shared_config.go 1.0 KB

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