Skip to content

Commit

Permalink
config: Update shared config loading to use os.UserHomeDir() (#1563)
Browse files Browse the repository at this point in the history
Instead of hard-coding Windows and *nix environment variables, rely on
os.UserHomeDir() to do the right thing. Ignore errors since those only
happen in situations we don't care about (and didn't handle
previously).

Signed-off-by: Stephen Kitt <skitt@redhat.com>
Co-authored-by: Jason Del Ponte <961963+jasdel@users.noreply.github.com>
  • Loading branch information
skitt and jasdel authored Jan 24, 2022
1 parent 484478f commit 452ee5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .changelog/4f325261c632499cb3f4464799763f58.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "4f325261-c632-499c-b3f4-464799763f58",
"type": "bugfix",
"description": "Updates `config` module to use os.UserHomeDir instead of hard coded environment variable for OS. [#1563](https://github.com/aws/aws-sdk-go-v2/pull/1563)",
"modules": [
"config"
]
}
10 changes: 3 additions & 7 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -1051,12 +1050,9 @@ func (e CredentialRequiresARNError) Error() string {
}

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

// *nix
return os.Getenv("HOME")
// Ignore errors since we only care about Windows and *nix.
homedir, _ := os.UserHomeDir()
return homedir
}

func oneOrNone(bs ...bool) bool {
Expand Down

0 comments on commit 452ee5e

Please sign in to comment.