Adding alternative method to set backend URL 73/40573/1
authorKiran Kamineni <kiran.k.kamineni@intel.com>
Mon, 2 Apr 2018 21:32:45 +0000 (14:32 -0700)
committerKiran Kamineni <kiran.k.kamineni@intel.com>
Mon, 2 Apr 2018 21:32:51 +0000 (14:32 -0700)
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>
sms-service/src/sms/backend/backend.go
sms-service/src/sms/backend/backend_test.go
sms-service/src/sms/backend/vault_test.go
sms-service/src/sms/config/config.go
sms-service/src/sms/smsconfig.json.template
sms-service/src/sms/test/smsconfig_test.json

index 756f609..062c0bd 100644 (file)
@@ -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,
        }
 
index 674c03f..2d2e2a9 100644 (file)
@@ -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
index cd7b5a5..db8a13e 100644 (file)
@@ -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")
index 58597f6..3901817 100644 (file)
@@ -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
index 63a12a7..7eb4916 100644 (file)
@@ -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"
 }
index b34bf78..ec03398 100644 (file)
@@ -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"
 }