Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/external: Cleanup Exported Types #508

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Breaking Change
---
* `aws/endpoints`: Removes `DecodeModel` and `DecodeModelOptions` from the package ([#509](https://github.com/aws/aws-sdk-go-v2/pull/509))
* `aws/external`: Removes several export constants and types ([#508](https://github.com/aws/aws-sdk-go-v2/pull/508))
* No longer exports AWS environment constants used by the external environment configuration loader
* `DefaultSharedConfigProfile` is now defined an exported constant

Services
---
Expand Down
80 changes: 40 additions & 40 deletions aws/external/env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,56 @@ const CredentialsSourceName = "EnvConfigCredentials"

// Environment variables that will be read for configuration values.
const (
AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
AWSAccessKeyEnvVar = "AWS_ACCESS_KEY"
awsAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
awsAccessKeyEnvVar = "AWS_ACCESS_KEY"

AWSSecreteAccessKeyEnvVar = "AWS_SECRET_ACCESS_KEY"
AWSSecreteKeyEnvVar = "AWS_SECRET_KEY"
awsSecreteAccessKeyEnvVar = "AWS_SECRET_ACCESS_KEY"
awsSecreteKeyEnvVar = "AWS_SECRET_KEY"

AWSSessionTokenEnvVar = "AWS_SESSION_TOKEN"
awsSessionTokenEnvVar = "AWS_SESSION_TOKEN"

AWSContainerCredentialsEndpointEnvVar = "AWS_CONTAINER_CREDENTIALS_FULL_URI"
AWSContainerCredentialsRelativePathEnvVar = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
AWSContainerPProviderAuthorizationEnvVar = "AWS_CONTAINER_AUTHORIZATION_TOKEN"
awsContainerCredentialsEndpointEnvVar = "AWS_CONTAINER_CREDENTIALS_FULL_URI"
awsContainerCredentialsRelativePathEnvVar = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
awsContainerPProviderAuthorizationEnvVar = "AWS_CONTAINER_AUTHORIZATION_TOKEN"

AWSRegionEnvVar = "AWS_REGION"
AWSDefaultRegionEnvVar = "AWS_DEFAULT_REGION"
awsRegionEnvVar = "AWS_REGION"
awsDefaultRegionEnvVar = "AWS_DEFAULT_REGION"

AWSProfileEnvVar = "AWS_PROFILE"
AWSDefaultProfileEnvVar = "AWS_DEFAULT_PROFILE"
awsProfileEnvVar = "AWS_PROFILE"
awsDefaultProfileEnvVar = "AWS_DEFAULT_PROFILE"

AWSSharedCredentialsFileEnvVar = "AWS_SHARED_CREDENTIALS_FILE"
awsSharedCredentialsFileEnvVar = "AWS_SHARED_CREDENTIALS_FILE"

AWSConfigFileEnvVar = "AWS_CONFIG_FILE"
awsConfigFileEnvVar = "AWS_CONFIG_FILE"

AWSCustomCABundleEnvVar = "AWS_CA_BUNDLE"
awsCustomCABundleEnvVar = "AWS_CA_BUNDLE"

AWSWebIdentityTokenFilePathEnvKey = "AWS_WEB_IDENTITY_TOKEN_FILE"
awsWebIdentityTokenFilePathEnvKey = "AWS_WEB_IDENTITY_TOKEN_FILE"

AWSRoleARNEnvKey = "AWS_ROLE_ARN"
AWSRoleSessionNameEnvKey = "AWS_ROLE_SESSION_NAME"
awsRoleARNEnvKey = "AWS_ROLE_ARN"
awsRoleSessionNameEnvKey = "AWS_ROLE_SESSION_NAME"

AWSEnableEndpointDiscoveryEnvKey = "AWS_ENABLE_ENDPOINT_DISCOVERY"
awsEnableEndpointDiscoveryEnvKey = "AWS_ENABLE_ENDPOINT_DISCOVERY"

AWSS3UseARNRegionEnvVar = "AWS_S3_USE_ARN_REGION"
awsS3UseARNRegionEnvVar = "AWS_S3_USE_ARN_REGION"
)

var (
credAccessEnvKeys = []string{
AWSAccessKeyIDEnvVar,
AWSAccessKeyEnvVar,
awsAccessKeyIDEnvVar,
awsAccessKeyEnvVar,
}
credSecretEnvKeys = []string{
AWSSecreteAccessKeyEnvVar,
AWSSecreteKeyEnvVar,
awsSecreteAccessKeyEnvVar,
awsSecreteKeyEnvVar,
}
regionEnvKeys = []string{
AWSRegionEnvVar,
AWSDefaultRegionEnvVar,
awsRegionEnvVar,
awsDefaultRegionEnvVar,
}
profileEnvKeys = []string{
AWSProfileEnvVar,
AWSDefaultProfileEnvVar,
awsProfileEnvVar,
awsDefaultProfileEnvVar,
}
)

Expand Down Expand Up @@ -196,32 +196,32 @@ func NewEnvConfig() (EnvConfig, error) {
setStringFromEnvVal(&creds.AccessKeyID, credAccessEnvKeys)
setStringFromEnvVal(&creds.SecretAccessKey, credSecretEnvKeys)
if creds.HasKeys() {
creds.SessionToken = os.Getenv(AWSSessionTokenEnvVar)
creds.SessionToken = os.Getenv(awsSessionTokenEnvVar)
cfg.Credentials = creds
}

cfg.ContainerCredentialsEndpoint = os.Getenv(AWSContainerCredentialsEndpointEnvVar)
cfg.ContainerCredentialsRelativePath = os.Getenv(AWSContainerCredentialsRelativePathEnvVar)
cfg.ContainerAuthorizationToken = os.Getenv(AWSContainerPProviderAuthorizationEnvVar)
cfg.ContainerCredentialsEndpoint = os.Getenv(awsContainerCredentialsEndpointEnvVar)
cfg.ContainerCredentialsRelativePath = os.Getenv(awsContainerCredentialsRelativePathEnvVar)
cfg.ContainerAuthorizationToken = os.Getenv(awsContainerPProviderAuthorizationEnvVar)

setStringFromEnvVal(&cfg.Region, regionEnvKeys)
setStringFromEnvVal(&cfg.SharedConfigProfile, profileEnvKeys)

cfg.SharedCredentialsFile = os.Getenv(AWSSharedCredentialsFileEnvVar)
cfg.SharedConfigFile = os.Getenv(AWSConfigFileEnvVar)
cfg.SharedCredentialsFile = os.Getenv(awsSharedCredentialsFileEnvVar)
cfg.SharedConfigFile = os.Getenv(awsConfigFileEnvVar)

cfg.CustomCABundle = os.Getenv(AWSCustomCABundleEnvVar)
cfg.CustomCABundle = os.Getenv(awsCustomCABundleEnvVar)

cfg.WebIdentityTokenFilePath = os.Getenv(AWSWebIdentityTokenFilePathEnvKey)
cfg.WebIdentityTokenFilePath = os.Getenv(awsWebIdentityTokenFilePathEnvKey)

cfg.RoleARN = os.Getenv(AWSRoleARNEnvKey)
cfg.RoleSessionName = os.Getenv(AWSRoleSessionNameEnvKey)
cfg.RoleARN = os.Getenv(awsRoleARNEnvKey)
cfg.RoleSessionName = os.Getenv(awsRoleSessionNameEnvKey)

if err := setBoolPtrFromEnvVal(&cfg.EnableEndpointDiscovery, []string{AWSEnableEndpointDiscoveryEnvKey}); err != nil {
if err := setBoolPtrFromEnvVal(&cfg.EnableEndpointDiscovery, []string{awsEnableEndpointDiscoveryEnvKey}); err != nil {
return cfg, err
}

if err := setBoolPtrFromEnvVal(&cfg.S3UseARNRegion, []string{AWSS3UseARNRegionEnvVar}); err != nil {
if err := setBoolPtrFromEnvVal(&cfg.S3UseARNRegion, []string{awsS3UseARNRegionEnvVar}); err != nil {
return cfg, err
}

Expand Down
16 changes: 9 additions & 7 deletions aws/external/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ const (

// ErrCodeSharedConfig AWS SDK Error Code for Shared Configuration Errors
ErrCodeSharedConfig = "SharedConfigErr"

// DefaultSharedConfigProfile is the default profile to be used when
// loading configuration from the config files if another profile name
// is not provided.
DefaultSharedConfigProfile = `default`
)

// DefaultSharedConfigProfile is the default profile to be used when
// loading configuration from the config files if another profile name
// is not provided.
var DefaultSharedConfigProfile = `default`
// defaultSharedConfigProfile allows for swapping the default profile for testing
var defaultSharedConfigProfile = DefaultSharedConfigProfile

// DefaultSharedCredentialsFilename returns the SDK's default file path
// for the shared credentials file.
Expand Down Expand Up @@ -82,8 +85,7 @@ var DefaultSharedConfigFiles = []string{

// AssumeRoleConfig provides the values defining the configuration for an IAM
// assume role.
type AssumeRoleConfig struct {
}
type AssumeRoleConfig struct{}

// SharedConfig represents the configuration fields of the SDK config files.
type SharedConfig struct {
Expand Down Expand Up @@ -199,7 +201,7 @@ func LoadSharedConfig(configs Configs) (Config, error) {
return nil, err
}
if !ok {
profile = DefaultSharedConfigProfile
profile = defaultSharedConfigProfile
}

files, ok, err = GetSharedConfigFiles(configs)
Expand Down
8 changes: 4 additions & 4 deletions aws/external/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ func cmpFiles(expects, actuals []sharedConfigFile) bool {
}

func TestLoadSharedConfig(t *testing.T) {
origProf := DefaultSharedConfigProfile
origProf := defaultSharedConfigProfile
origFiles := DefaultSharedConfigFiles
defer func() {
DefaultSharedConfigProfile = origProf
defaultSharedConfigProfile = origProf
DefaultSharedConfigFiles = origFiles
}()

Expand Down Expand Up @@ -500,11 +500,11 @@ func TestLoadSharedConfig(t *testing.T) {

for i, c := range cases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
DefaultSharedConfigProfile = origProf
defaultSharedConfigProfile = origProf
DefaultSharedConfigFiles = origFiles

if len(c.Profile) > 0 {
DefaultSharedConfigProfile = c.Profile
defaultSharedConfigProfile = c.Profile
}
if len(c.Files) > 0 {
DefaultSharedConfigFiles = c.Files
Expand Down