1package shareddefaults
 2
 3import (
 4	"os"
 5	"os/user"
 6	"path/filepath"
 7)
 8
 9// SharedCredentialsFilename returns the SDK's default file path
10// for the shared credentials file.
11//
12// Builds the shared config file path based on the OS's platform.
13//
14//   - Linux/Unix: $HOME/.aws/credentials
15//   - Windows: %USERPROFILE%\.aws\credentials
16func SharedCredentialsFilename() string {
17	return filepath.Join(UserHomeDir(), ".aws", "credentials")
18}
19
20// SharedConfigFilename returns the SDK's default file path for
21// the shared config file.
22//
23// Builds the shared config file path based on the OS's platform.
24//
25//   - Linux/Unix: $HOME/.aws/config
26//   - Windows: %USERPROFILE%\.aws\config
27func SharedConfigFilename() string {
28	return filepath.Join(UserHomeDir(), ".aws", "config")
29}
30
31// UserHomeDir returns the home directory for the user the process is
32// running under.
33func UserHomeDir() string {
34	// Ignore errors since we only care about Windows and *nix.
35	home, _ := os.UserHomeDir()
36
37	if len(home) > 0 {
38		return home
39	}
40
41	currUser, _ := user.Current()
42	if currUser != nil {
43		home = currUser.HomeDir
44	}
45
46	return home
47}