From bf4a377b13850c10b49d77fa0b153840ca8d63a3 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 17 Sep 2019 09:14:22 -0700 Subject: [PATCH] feat(creds): Search creds in working dir before home --- core/config_utils.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/config_utils.go b/core/config_utils.go index 26e9962..e063e20 100644 --- a/core/config_utils.go +++ b/core/config_utils.go @@ -67,21 +67,13 @@ func getServicePropertiesFromCredentialFile(credentialKey string) map[string]str // Check the search order for the credential file that we'll attempt to load: var credentialFilePath string - // 1) /ibm-credentials.env - if credentialFilePath == "" { - var filePath = path.Join(UserHomeDir(), DEFAULT_CREDENTIAL_FILE_NAME) - if _, err := os.Stat(filePath); err == nil { - credentialFilePath = filePath - } - } - - // 2) ${IBM_CREDENTIALS_FILE} + // 1) ${IBM_CREDENTIALS_FILE} envPath := os.Getenv(IBM_CREDENTIAL_FILE_ENVVAR) if _, err := os.Stat(envPath); err == nil { credentialFilePath = envPath } - // 3) /ibm-credentials.env + // 2) /ibm-credentials.env if credentialFilePath == "" { dir, _ := os.Getwd() var filePath = path.Join(dir, DEFAULT_CREDENTIAL_FILE_NAME) @@ -90,6 +82,14 @@ func getServicePropertiesFromCredentialFile(credentialKey string) map[string]str } } + // 3) /ibm-credentials.env + if credentialFilePath == "" { + var filePath = path.Join(UserHomeDir(), DEFAULT_CREDENTIAL_FILE_NAME) + if _, err := os.Stat(filePath); err == nil { + credentialFilePath = filePath + } + } + // If we found a file to load, then load it. if credentialFilePath != "" { file, err := os.Open(credentialFilePath)