diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-04-02 14:32:45 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-04-02 14:32:51 -0700 |
commit | 140754702464fd7297dbc828411f9212942d95a6 (patch) | |
tree | 38acf71d6cfbf67ad1056438caf8428179971247 | |
parent | de3b2f2916e8960f220f36fdb1ac5f04b0fc5499 (diff) |
Adding alternative method to set backend URL
SMS gets the backend address from ENV variable
if nothing is provided in the config.json file
Issue-ID: AAF-209
Change-Id: I7791ec6db3627092f9161088ed6242ed71368293
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
-rw-r--r-- | sms-service/src/sms/backend/backend.go | 2 | ||||
-rw-r--r-- | sms-service/src/sms/backend/backend_test.go | 2 | ||||
-rw-r--r-- | sms-service/src/sms/backend/vault_test.go | 2 | ||||
-rw-r--r-- | sms-service/src/sms/config/config.go | 14 | ||||
-rw-r--r-- | sms-service/src/sms/smsconfig.json.template | 5 | ||||
-rw-r--r-- | sms-service/src/sms/test/smsconfig_test.json | 4 |
6 files changed, 20 insertions, 9 deletions
diff --git a/sms-service/src/sms/backend/backend.go b/sms-service/src/sms/backend/backend.go index 756f609..062c0bd 100644 --- a/sms-service/src/sms/backend/backend.go +++ b/sms-service/src/sms/backend/backend.go @@ -54,7 +54,7 @@ type SecretBackend interface { // InitSecretBackend returns an interface implementation func InitSecretBackend() (SecretBackend, error) { backendImpl := &Vault{ - vaultAddress: smsconfig.SMSConfig.VaultAddress, + vaultAddress: smsconfig.SMSConfig.BackendAddress, vaultToken: smsconfig.SMSConfig.VaultToken, } diff --git a/sms-service/src/sms/backend/backend_test.go b/sms-service/src/sms/backend/backend_test.go index 674c03f..2d2e2a9 100644 --- a/sms-service/src/sms/backend/backend_test.go +++ b/sms-service/src/sms/backend/backend_test.go @@ -23,7 +23,7 @@ import ( func TestInitSecretBackend(t *testing.T) { smsconfig.SMSConfig = &smsconfig.SMSConfiguration{ - VaultAddress: "http://localhost:8200", + BackendAddress: "http://localhost:8200", } sec, err := InitSecretBackend() // We expect an error to be returned as Init expects diff --git a/sms-service/src/sms/backend/vault_test.go b/sms-service/src/sms/backend/vault_test.go index cd7b5a5..db8a13e 100644 --- a/sms-service/src/sms/backend/vault_test.go +++ b/sms-service/src/sms/backend/vault_test.go @@ -28,7 +28,7 @@ func init() { } func TestInit(t *testing.T) { - smsconfig.SMSConfig = &smsconfig.SMSConfiguration{VaultAddress: "http://localhost:8200"} + smsconfig.SMSConfig = &smsconfig.SMSConfiguration{BackendAddress: "http://localhost:8200"} v.Init() if v.vaultClient == nil { t.Fatal("Init: Init() failed to create vaultClient") diff --git a/sms-service/src/sms/config/config.go b/sms-service/src/sms/config/config.go index 58597f6..3901817 100644 --- a/sms-service/src/sms/config/config.go +++ b/sms-service/src/sms/config/config.go @@ -19,6 +19,7 @@ package config import ( "encoding/json" "os" + smslogger "sms/log" ) // SMSConfiguration loads up all the values that are used to configure @@ -29,9 +30,10 @@ type SMSConfiguration struct { ServerCert string `json:"servercert"` ServerKey string `json:"serverkey"` - VaultAddress string `json:"vaultaddress"` - VaultToken string `json:"vaulttoken"` - DisableTLS bool `json:"disable_tls"` + BackendAddress string `json:"smsdbaddress"` + VaultToken string `json:"vaulttoken"` + DisableTLS bool `json:"disable_tls"` + BackendAddressEnvVariable string `json:"smsdburlenv"` } // SMSConfig is the structure that stores the configuration @@ -53,6 +55,12 @@ func ReadConfigFile(file string) (*SMSConfiguration, error) { if err != nil { return nil, err } + + if SMSConfig.BackendAddress == "" && SMSConfig.BackendAddressEnvVariable != "" { + // Get the value from ENV variable + smslogger.WriteInfo("Using Environment Variable: " + SMSConfig.BackendAddressEnvVariable) + SMSConfig.BackendAddress = os.Getenv(SMSConfig.BackendAddressEnvVariable) + } } return SMSConfig, nil diff --git a/sms-service/src/sms/smsconfig.json.template b/sms-service/src/sms/smsconfig.json.template index 63a12a7..7eb4916 100644 --- a/sms-service/src/sms/smsconfig.json.template +++ b/sms-service/src/sms/smsconfig.json.template @@ -3,6 +3,7 @@ "servercert": "auth/server.cert", "serverkey": "auth/server.key", - "vaultaddress": "http://localhost:8200", - "vaulttoken": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + "smsdbaddress": "http://localhost:8200", + "vaulttoken": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", + "smsdburlenv" : "SMSDB_URL" } diff --git a/sms-service/src/sms/test/smsconfig_test.json b/sms-service/src/sms/test/smsconfig_test.json index b34bf78..ec03398 100644 --- a/sms-service/src/sms/test/smsconfig_test.json +++ b/sms-service/src/sms/test/smsconfig_test.json @@ -3,5 +3,7 @@ "servercert": "testserver.cert", "serverkey": "testserver.key", - "vaultaddress": "http://localhost:8200" + "smsdbaddress": "http://localhost:8200", + "vaulttoken": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", + "smsdburlenv" : "SMSDB_URL" } |