Skip to content

Commit

Permalink
Merge pull request #4519 from RanVaknin/fix-home-dir
Browse files Browse the repository at this point in the history
fix-resolve-home-v1
  • Loading branch information
RanVaknin authored Oct 18, 2022
2 parents 05a7de0 + 0ddcab4 commit d5e20b8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### SDK Features

### SDK Enhancements
* `aws/session`: Modified config resolution strategy when `$HOME` or `%USERPROFILE%` environment variables are not set.
* When the environment variables are not set, the SDK will attempt to determine the home directory using `user.Current()`.

### SDK Bugs
18 changes: 12 additions & 6 deletions internal/shareddefaults/shared_config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package shareddefaults

import (
"os"
"os/user"
"path/filepath"
"runtime"
)

// SharedCredentialsFilename returns the SDK's default file path
Expand Down Expand Up @@ -31,10 +30,17 @@ func SharedConfigFilename() string {
// UserHomeDir returns the home directory for the user the process is
// running under.
func UserHomeDir() string {
if runtime.GOOS == "windows" { // Windows
return os.Getenv("USERPROFILE")
var home string

home = userHomeDir()
if len(home) > 0 {
return home
}

currUser, _ := user.Current()
if currUser != nil {
home = currUser.HomeDir
}

// *nix
return os.Getenv("HOME")
return home
}
18 changes: 18 additions & 0 deletions internal/shareddefaults/shared_config_resolve_home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !go1.12
// +build !go1.12

package shareddefaults

import (
"os"
"runtime"
)

func userHomeDir() string {
if runtime.GOOS == "windows" { // Windows
return os.Getenv("USERPROFILE")
}

// *nix
return os.Getenv("HOME")
}
13 changes: 13 additions & 0 deletions internal/shareddefaults/shared_config_resolve_home_go1.12.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build go1.12
// +build go1.12

package shareddefaults

import (
"os"
)

func userHomeDir() string {
home, _ := os.UserHomeDir()
return home
}

0 comments on commit d5e20b8

Please sign in to comment.