Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
key-storage-agent
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
key-storage-agent
Commits
3182e91a
Commit
3182e91a
authored
6 years ago
by
Olgun Cengiz
Browse files
Options
Downloads
Patches
Plain Diff
Viper configuration added
parent
3c763383
No related branches found
No related tags found
2 merge requests
!11
Resolve "Implement Viper configuration"
,
!10
Resolve "Implement Viper configuration"
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
config.yaml.sample
+10
-0
10 additions, 0 deletions
config.yaml.sample
main.go
+10
-10
10 additions, 10 deletions
main.go
server/configs.go
+29
-0
29 additions, 0 deletions
server/configs.go
server/server.go
+2
-1
2 additions, 1 deletion
server/server.go
with
52 additions
and
11 deletions
.gitignore
+
1
−
0
View file @
3182e91a
...
...
@@ -3,3 +3,4 @@ vendor/
Gopkg.lock
.idea/
.project
config.yaml
This diff is collapsed.
Click to expand it.
config.yaml.sample
0 → 100644
+
10
−
0
View file @
3182e91a
dataStorageClientUrl: localhost:7777
grpcClientUrl: localhost:7877
restClientUrl: localhost:7878
# Certificate Related Config
certDir: cert
certFile: server.crt
certKey: server.key
vereignCertFile: vereign_ca.cer
vereignCertKey: vereign_ca.key
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.go
+
10
−
10
View file @
3182e91a
...
...
@@ -18,31 +18,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package
main
import
(
"fmt"
"log"
"code.vereign.com/code/key-storage-agent/server"
"
code.vereign.com/code/viam-apis/utils
"
"
github.com/spf13/viper
"
)
// main start a gRPC server and waits for connection
func
main
()
{
server
.
SetConfigValues
()
// TODO this should be done via configuration or even a certificate repository
certDir
:=
utils
.
GetCertDirFromFlags
(
)
certDir
:=
viper
.
GetString
(
"certDir"
)
if
certDir
==
""
{
log
.
Printf
(
"cert-dir cannot be empty"
)
return
}
grpcAddress
:=
fmt
.
Sprintf
(
"%s:%d"
,
"localhost"
,
7877
)
restAddress
:=
fmt
.
Sprintf
(
"%s:%d"
,
"localhost"
,
7878
)
dataStorageAddress
:=
fmt
.
Sprintf
(
"%s:%d"
,
"localhost"
,
7777
)
grpcAddress
:=
viper
.
GetString
(
"grpcClientUrl"
)
restAddress
:=
viper
.
GetString
(
"restClientUrl"
)
dataStorageAddress
:=
viper
.
GetString
(
"dataStorageClientUrl"
)
certFilePath
:=
certDir
+
"/
server.crt"
privateKeyFilePath
:=
certDir
+
"/
server.k
ey"
vereignCertFilePath
:=
certDir
+
"/
vereign_ca.cer"
vereignPrivateKeyFilePath
:=
certDir
+
"/vereign
_ca.k
ey"
certFilePath
:=
certDir
+
"/
"
+
viper
.
GetString
(
"certFile"
)
privateKeyFilePath
:=
certDir
+
"/
"
+
viper
.
GetString
(
"certK
ey"
)
vereignCertFilePath
:=
certDir
+
"/
"
+
viper
.
GetString
(
"vereignCertFile"
)
vereignPrivateKeyFilePath
:=
certDir
+
"/
"
+
viper
.
GetString
(
"
vereign
CertK
ey"
)
// fire the gRPC server in a goroutine
go
func
()
{
...
...
This diff is collapsed.
Click to expand it.
server/configs.go
0 → 100644
+
29
−
0
View file @
3182e91a
package
server
import
(
"log"
"github.com/spf13/viper"
)
func
SetConfigValues
()
{
// Set Default Values For Config Variables
// Vereign API Related
viper
.
SetDefault
(
"grpcClientUrl"
,
"localhost:7877"
)
viper
.
SetDefault
(
"restClientUrl"
,
"localhost:7878"
)
viper
.
SetDefault
(
"dataStorageClientUrl"
,
"localhost:7777"
)
// Certificates Related
viper
.
SetDefault
(
"certDir"
,
"cert"
)
viper
.
SetDefault
(
"certFile"
,
"server.crt"
)
viper
.
SetDefault
(
"certKey"
,
"server.key"
)
viper
.
SetDefault
(
"vereignCertFile"
,
"vereign_ca.cer"
)
viper
.
SetDefault
(
"vereignCertKey"
,
"vereign_ca.key"
)
// Read Config File
viper
.
SetConfigName
(
"config"
)
viper
.
AddConfigPath
(
"."
)
if
err
:=
viper
.
ReadInConfig
();
err
!=
nil
{
log
.
Printf
(
"can't read config: %s, will use default values"
,
err
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/server.go
+
2
−
1
View file @
3182e91a
...
...
@@ -36,6 +36,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"github.com/spf13/viper"
)
// private type for Context keys
...
...
@@ -69,7 +70,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in
}
sessionClient
:=
&
client
.
DataStorageClientImpl
{}
sessionClient
.
SetUpClient
(
viamAuth
,
"localhost:7777"
,
pkgCertFile
)
sessionClient
.
SetUpClient
(
viamAuth
,
viper
.
GetString
(
"dataStorageClientUrl"
)
,
pkgCertFile
)
defer
sessionClient
.
CloseClient
()
if
clientAuth
.
Uuid
==
viamAuth
.
Uuid
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment