Skip to content

Commit

Permalink
Merge pull request #40 from cyberark/fix-loadconfig-user-error
Browse files Browse the repository at this point in the history
Update LoadConfig to call getHomeDir method
  • Loading branch information
sgnn7 authored Jan 3, 2019
2 parents a417f53 + 10de0cf commit bb43c2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

* Modify configuration loading to skip options that check home dirs if there is
an error retrieving the home dir

# [0.5.0]

* Add support for passing fully qualified variable id to `RetrieveSecret` API method in v4 mode
Expand Down
30 changes: 21 additions & 9 deletions conjurapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,40 @@ func (c *Config) mergeEnv() {
}

func LoadConfig() (config Config, err error) {
usr, err := user.Current()
if err != nil {
return
}
home := getHomeDir()

// Default to using ~/.netrc, subsequent configuration can
// override it.
config = Config{NetRCPath: path.Join(usr.HomeDir, ".netrc")}
// override it if the home dir is set.
if home != "" {
config = Config{NetRCPath: path.Join(home, ".netrc")}
}

config.mergeYAML(path.Join(getSystemPath(), "conjur.conf"))

conjurrc := os.Getenv("CONJURRC")
if conjurrc == "" {
conjurrc = path.Join(usr.HomeDir, ".conjurrc")
if conjurrc == "" && home != "" {
conjurrc = path.Join(home, ".conjurrc")
}
if conjurrc != "" {
config.mergeYAML(conjurrc)
}
config.mergeYAML(conjurrc)

config.mergeEnv()

logging.ApiLog.Debugf("Final config: %+v\n", config)
return
}

func getHomeDir() string {
usr, err := user.Current()
if err != nil {
// Return an empty value
return ""
}

return usr.HomeDir
}

func getSystemPath() string {
if runtime.GOOS == "windows" {
//No way to use SHGetKnownFolderPath()
Expand Down

0 comments on commit bb43c2b

Please sign in to comment.