Skip to content
Snippets Groups Projects
Commit 3182e91a authored by Olgun Cengiz's avatar Olgun Cengiz :drum:
Browse files

Viper configuration added

parent 3c763383
No related branches found
No related tags found
2 merge requests!11Resolve "Implement Viper configuration",!10Resolve "Implement Viper configuration"
......@@ -3,3 +3,4 @@ vendor/
Gopkg.lock
.idea/
.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/>.
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.key"
vereignCertFilePath := certDir + "/vereign_ca.cer"
vereignPrivateKeyFilePath := certDir + "/vereign_ca.key"
certFilePath := certDir + "/" + viper.GetString("certFile")
privateKeyFilePath := certDir + "/" + viper.GetString("certKey")
vereignCertFilePath := certDir + "/" + viper.GetString("vereignCertFile")
vereignPrivateKeyFilePath := certDir + "/" + viper.GetString("vereignCertKey")
// fire the gRPC server in a goroutine
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 (
"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 {
......
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