Skip to content

Commit

Permalink
feat(creds): Search creds in working dir before home
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Sep 17, 2019
1 parent fbb900b commit bf4a377
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) <user-home-dir>/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) <current-working-directory>/ibm-credentials.env
// 2) <current-working-directory>/ibm-credentials.env
if credentialFilePath == "" {
dir, _ := os.Getwd()
var filePath = path.Join(dir, DEFAULT_CREDENTIAL_FILE_NAME)
Expand All @@ -90,6 +82,14 @@ func getServicePropertiesFromCredentialFile(credentialKey string) map[string]str
}
}

// 3) <user-home-dir>/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)
Expand Down

0 comments on commit bf4a377

Please sign in to comment.