Skip to content
Snippets Groups Projects

130-implement-etcd-configuration-use

Merged Viktor Popov requested to merge 130-implement-etcd-configuration-use into master
4 files
+ 38
6
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 22
5
@@ -2,11 +2,16 @@ package config
import (
"log"
"os"
"path/filepath"
"strings"
"code.vereign.com/code/viam-apis/authentication"
"github.com/spf13/viper"
)
import _ "github.com/spf13/viper/remote"
var SystemAuth = &authentication.Authentication{
Uuid: "undefined",
Session: "undefined",
@@ -27,7 +32,7 @@ var RestListenAddress string
var DataStorageUrl string
var CertDir string
func SetConfigValues() {
func SetConfigValues(configFile, etcdURL string) {
// Set Default Values For Config Variables
// Vereign API Related
@@ -66,10 +71,22 @@ func SetConfigValues() {
*/
// 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)
if configFile != "" {
configName := strings.Split(filepath.Base(configFile), ".")[0]
configDir := filepath.Dir(configFile)
viper.SetConfigName(configName)
viper.AddConfigPath(configDir)
if err := viper.ReadInConfig(); err != nil {
log.Printf("can't read config: %v, will use default values", err)
}
} else {
log.Printf("requesting config at "+etcdURL, "/"+os.Getenv("ENV_NAME")+"/"+os.Getenv("CI_PROJECT_NAME")+".json")
viper.AddRemoteProvider("etcd", etcdURL, "/"+os.Getenv("ENV_NAME")+"/"+os.Getenv("CI_PROJECT_NAME")+".json")
viper.SetConfigType("json")
if err := viper.ReadRemoteConfig(); err != nil {
log.Printf("can't read config: %v, will use default values", err)
}
}
CertificationMethod = viper.GetString("certificationMethod")
Loading