Skip to content
Snippets Groups Projects
Commit fd23e1c6 authored by Gospodin Bodurov's avatar Gospodin Bodurov
Browse files

Merge branch '6-Implement_Viper_configuration' into 'master'

Resolve "Implement Viper configuration"

Closes #6

See merge request !11
parents 3c763383 3182e91a
No related branches found
No related tags found
1 merge request!11Resolve "Implement Viper configuration"
...@@ -3,3 +3,4 @@ vendor/ ...@@ -3,3 +3,4 @@ vendor/
Gopkg.lock Gopkg.lock
.idea/ .idea/
.project .project
config.yaml
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
...@@ -18,31 +18,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -18,31 +18,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package main package main
import ( import (
"fmt"
"log" "log"
"code.vereign.com/code/key-storage-agent/server" "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 // main start a gRPC server and waits for connection
func main() { func main() {
server.SetConfigValues()
// TODO this should be done via configuration or even a certificate repository // TODO this should be done via configuration or even a certificate repository
certDir := utils.GetCertDirFromFlags() certDir := viper.GetString("certDir")
if certDir == "" { if certDir == "" {
log.Printf("cert-dir cannot be empty") log.Printf("cert-dir cannot be empty")
return return
} }
grpcAddress := fmt.Sprintf("%s:%d", "localhost", 7877) grpcAddress := viper.GetString("grpcClientUrl")
restAddress := fmt.Sprintf("%s:%d", "localhost", 7878) restAddress := viper.GetString("restClientUrl")
dataStorageAddress := fmt.Sprintf("%s:%d", "localhost", 7777) dataStorageAddress := viper.GetString("dataStorageClientUrl")
certFilePath := certDir + "/server.crt" certFilePath := certDir + "/" + viper.GetString("certFile")
privateKeyFilePath := certDir + "/server.key" privateKeyFilePath := certDir + "/" + viper.GetString("certKey")
vereignCertFilePath := certDir + "/vereign_ca.cer" vereignCertFilePath := certDir + "/" + viper.GetString("vereignCertFile")
vereignPrivateKeyFilePath := certDir + "/vereign_ca.key" vereignPrivateKeyFilePath := certDir + "/" + viper.GetString("vereignCertKey")
// fire the gRPC server in a goroutine // fire the gRPC server in a goroutine
go func() { go func() {
......
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
...@@ -36,6 +36,7 @@ import ( ...@@ -36,6 +36,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"github.com/spf13/viper"
) )
// private type for Context keys // private type for Context keys
...@@ -69,7 +70,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in ...@@ -69,7 +70,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in
} }
sessionClient := &client.DataStorageClientImpl{} sessionClient := &client.DataStorageClientImpl{}
sessionClient.SetUpClient(viamAuth, "localhost:7777", pkgCertFile) sessionClient.SetUpClient(viamAuth, viper.GetString("dataStorageClientUrl"), pkgCertFile)
defer sessionClient.CloseClient() defer sessionClient.CloseClient()
if clientAuth.Uuid == viamAuth.Uuid { if clientAuth.Uuid == viamAuth.Uuid {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment