Skip to content

Commit

Permalink
Merge pull request gophercloud#71 from flaper87/survive-userless
Browse files Browse the repository at this point in the history
Don't fail if USER is not defined
  • Loading branch information
jtopjian authored Oct 29, 2018
2 parents a45c12c + 9427fef commit 34f5991
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions openstack/clientconfig/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,13 @@ func findAndReadYAML(yamlFile string) ([]byte, error) {
}

// unix user config directory: ~/.config/openstack.
currentUser, err := user.Current()
if err != nil {
return nil, fmt.Errorf("unable to get current user: %s", err)
}

homeDir := currentUser.HomeDir
if homeDir != "" {
filename := filepath.Join(homeDir, ".config/openstack/"+yamlFile)
if ok := fileExists(filename); ok {
return ioutil.ReadFile(filename)
if currentUser, err := user.Current(); err == nil {
homeDir := currentUser.HomeDir
if homeDir != "" {
filename := filepath.Join(homeDir, ".config/openstack/"+yamlFile)
if ok := fileExists(filename); ok {
return ioutil.ReadFile(filename)
}
}
}

Expand Down

0 comments on commit 34f5991

Please sign in to comment.