From 9710d97518bfe343288ad53b90a0da21e0e37b7a Mon Sep 17 00:00:00 2001 From: Ran Vaknin Date: Fri, 12 Aug 2022 19:15:32 -0700 Subject: [PATCH 1/4] fix-resolve-home-v1 --- internal/shareddefaults/shared_config.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/shareddefaults/shared_config.go b/internal/shareddefaults/shared_config.go index ebcbc2b40a3..aba8723bce3 100644 --- a/internal/shareddefaults/shared_config.go +++ b/internal/shareddefaults/shared_config.go @@ -2,8 +2,8 @@ package shareddefaults import ( "os" + "os/user" "path/filepath" - "runtime" ) // SharedCredentialsFilename returns the SDK's default file path @@ -31,10 +31,16 @@ 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") + home, _ := os.UserHomeDir() + + if len(home) > 0 { + return home + } + + currUser, _ := user.Current() + if currUser != nil { + home = currUser.HomeDir } - // *nix - return os.Getenv("HOME") + return home } From 79ab6a7db89d48d150ad6ff1336c482f305134c8 Mon Sep 17 00:00:00 2001 From: Ran Vaknin Date: Mon, 15 Aug 2022 16:16:37 -0700 Subject: [PATCH 2/4] added support for oldergo version 1.12 --- internal/shareddefaults/shared_config.go | 15 +----------- .../shared_config_resolve_home.go | 18 ++++++++++++++ .../shared_config_resolve_home_go1.12.go | 24 +++++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 internal/shareddefaults/shared_config_resolve_home.go create mode 100644 internal/shareddefaults/shared_config_resolve_home_go1.12.go diff --git a/internal/shareddefaults/shared_config.go b/internal/shareddefaults/shared_config.go index aba8723bce3..8b3141bc1a4 100644 --- a/internal/shareddefaults/shared_config.go +++ b/internal/shareddefaults/shared_config.go @@ -1,8 +1,6 @@ package shareddefaults import ( - "os" - "os/user" "path/filepath" ) @@ -31,16 +29,5 @@ func SharedConfigFilename() string { // UserHomeDir returns the home directory for the user the process is // running under. func UserHomeDir() string { - home, _ := os.UserHomeDir() - - if len(home) > 0 { - return home - } - - currUser, _ := user.Current() - if currUser != nil { - home = currUser.HomeDir - } - - return home + return userHomeDir() } diff --git a/internal/shareddefaults/shared_config_resolve_home.go b/internal/shareddefaults/shared_config_resolve_home.go new file mode 100644 index 00000000000..eb298ae0fc1 --- /dev/null +++ b/internal/shareddefaults/shared_config_resolve_home.go @@ -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") +} diff --git a/internal/shareddefaults/shared_config_resolve_home_go1.12.go b/internal/shareddefaults/shared_config_resolve_home_go1.12.go new file mode 100644 index 00000000000..1b214d2fefb --- /dev/null +++ b/internal/shareddefaults/shared_config_resolve_home_go1.12.go @@ -0,0 +1,24 @@ +//go:build go1.12 +// +build go1.12 + +package shareddefaults + +import ( + "os" + "os/user" +) + +func userHomeDir() string { + home, _ := os.UserHomeDir() + + if len(home) > 0 { + return home + } + + currUser, _ := user.Current() + if currUser != nil { + home = currUser.HomeDir + } + + return home +} From dd068e53a92e67ba8c09e913adf05fae5ee609a1 Mon Sep 17 00:00:00 2001 From: Ran Vaknin Date: Tue, 18 Oct 2022 11:06:27 -0700 Subject: [PATCH 3/4] fixed code based on mcgrails suggestions --- internal/shareddefaults/shared_config.go | 15 ++++++++++++++- .../shared_config_resolve_home_go1.12.go | 11 ----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/internal/shareddefaults/shared_config.go b/internal/shareddefaults/shared_config.go index 8b3141bc1a4..34fea49ca81 100644 --- a/internal/shareddefaults/shared_config.go +++ b/internal/shareddefaults/shared_config.go @@ -1,6 +1,7 @@ package shareddefaults import ( + "os/user" "path/filepath" ) @@ -29,5 +30,17 @@ func SharedConfigFilename() string { // UserHomeDir returns the home directory for the user the process is // running under. func UserHomeDir() string { - return userHomeDir() + var home string + + home = userHomeDir() + if len(home) > 0 { + return home + } + + currUser, _ := user.Current() + if currUser != nil { + home = currUser.HomeDir + } + + return home } diff --git a/internal/shareddefaults/shared_config_resolve_home_go1.12.go b/internal/shareddefaults/shared_config_resolve_home_go1.12.go index 1b214d2fefb..51541b50876 100644 --- a/internal/shareddefaults/shared_config_resolve_home_go1.12.go +++ b/internal/shareddefaults/shared_config_resolve_home_go1.12.go @@ -5,20 +5,9 @@ package shareddefaults import ( "os" - "os/user" ) func userHomeDir() string { home, _ := os.UserHomeDir() - - if len(home) > 0 { - return home - } - - currUser, _ := user.Current() - if currUser != nil { - home = currUser.HomeDir - } - return home } From 0ddcab474fe02cc558da2a7b3349da5b363e948d Mon Sep 17 00:00:00 2001 From: Ran Vaknin Date: Tue, 18 Oct 2022 11:52:15 -0700 Subject: [PATCH 4/4] added release notes --- CHANGELOG_PENDING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8a1927a39ca..6773dacfffc 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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