Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch user.current -> homedir.dir #32

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,37 @@ func New(args ...interface{}) *Session {
envFallback("SOFTLAYER_TIMEOUT", &values[keys["timeout"]])

// Read ~/.softlayer for configuration
var homeDir string
u, err := user.Current()
if err != nil {
panic("session: Could not determine current user.")
for _, name := range []string{"HOME", "USERPROFILE"} { // *nix, windows
if dir := os.Getenv(name); dir != "" {
homeDir = dir
break
}
}
} else {
homeDir = u.HomeDir
}

configPath := fmt.Sprintf("%s/.softlayer", u.HomeDir)
if _, err = os.Stat(configPath); !os.IsNotExist(err) {
// config file exists
file, err := config.LoadFile(configPath)
if err != nil {
log.Println(fmt.Sprintf("[WARN] session: Could not parse %s : %s", configPath, err))
} else {
for k, v := range keys {
value, ok := file.Get("softlayer", k)
if ok && values[v] == "" {
values[v] = value
if homeDir != "" {
configPath := fmt.Sprintf("%s/.softlayer", homeDir)
if _, err = os.Stat(configPath); !os.IsNotExist(err) {
// config file exists
file, err := config.LoadFile(configPath)
if err != nil {
log.Println(fmt.Sprintf("[WARN] session: Could not parse %s : %s", configPath, err))
} else {
for k, v := range keys {
value, ok := file.Get("softlayer", k)
if ok && values[v] == "" {
values[v] = value
}
}
}
}
} else {
log.Println("[WARN] session: home dir could not be determined. Skipping read of ~/.softlayer.")
}

endpointURL := values[keys["endpoint_url"]]
Expand Down