Skip to content

Commit

Permalink
refactor load default config to take in context and load options
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Dec 10, 2020
1 parent 8baa5f4 commit d1a77c7
Show file tree
Hide file tree
Showing 33 changed files with 1,087 additions and 759 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
// Using the SDK's default configuration, loading additional config
// and credentials values from the environment variables, shared
// credentials, and shared configuration files
cfg, err := config.LoadDefaultConfig(config.WithRegion("us-west-2"))
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-west-2"))
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions aws/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
// The following example demonstrates using the AnonymousCredentials to prevent
// SDK's external config loading attempt to resolve credentials.
//
// cfg, err := config.LoadDefaultConfig(
// config.WithCredentialsProvider(aws.AnonymousCredentials{}))
// cfg, err := config.LoadDefaultConfig(context.TODO(),
// config.WithCredentialsProvider(aws.AnonymousCredentials{}),
// )
// if err != nil {
// log.Fatalf("failed to load config, %v", err)
// }
Expand All @@ -42,7 +43,7 @@ import (
//
// This can also be configured for specific operations calls too.
//
// cfg, err := config.LoadDefaultConfig()
// cfg, err := config.LoadDefaultConfig(context.TODO())
// if err != nil {
// log.Fatalf("failed to load config, %v", err)
// }
Expand Down
38 changes: 22 additions & 16 deletions config/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@ import (
)

const (
sharedConfigType = "&SharedConfig{}"
envConfigType = "&EnvConfig{}"
sharedConfigType = "&SharedConfig{}"
envConfigType = "&EnvConfig{}"
awsConfigType = "&awsConfig{}"
ec2IMDSRegionType = "&UseEC2IMDSRegion{}"
loadOptionsType = "&LoadOptions{}"
)

var implAsserts = map[string][]string{
"SharedConfigProfileProvider": {envConfigType, `WithSharedConfigProfile("")`},
"SharedConfigFilesProvider": {envConfigType, `WithSharedConfigFiles(nil)`},
"CustomCABundleProvider": {envConfigType, `WithCustomCABundle(nil)`},
"RegionProvider": {envConfigType, sharedConfigType, `WithRegion("")`, `WithEC2IMDSRegion{}`},
"CredentialsProviderProvider": {`WithCredentialsProvider(nil)`},
"DefaultRegionProvider": {`WithDefaultRegion("")`},
"EC2RoleCredentialOptionsProvider": {`WithEC2RoleCredentialOptions(nil)`},
"EndpointCredentialOptionsProvider": {`WithEndpointCredentialOptions(nil)`},
"EndpointResolverProvider": {`WithEndpointResolver(nil)`},
"APIOptionsProvider": {`WithAPIOptions(nil)`},
"HTTPClientProvider": {`WithHTTPClient(nil)`},
"AssumeRoleCredentialOptionsProvider": {`WithAssumeRoleCredentialOptions(nil)`},
"WebIdentityRoleCredentialOptionsProvider": {`WithWebIdentityRoleCredentialOptions(nil)`},
"RetryProvider": {`WithRetryer(nil)`},
"sharedConfigProfileProvider": {envConfigType, loadOptionsType},
"sharedConfigFilesProvider": {envConfigType, loadOptionsType},
"customCABundleProvider": {envConfigType, loadOptionsType},
"regionProvider": {envConfigType, sharedConfigType, loadOptionsType, ec2IMDSRegionType},
"credentialsProviderProvider": {loadOptionsType},
"defaultRegionProvider": {loadOptionsType},
"ec2RoleCredentialOptionsProvider": {loadOptionsType},
"endpointCredentialOptionsProvider": {loadOptionsType},
"assumeRoleCredentialOptionsProvider": {loadOptionsType},
"webIdentityRoleCredentialOptionsProvider": {loadOptionsType},
"httpClientProvider": {loadOptionsType},
"apiOptionsProvider": {loadOptionsType},
"retryProvider": {loadOptionsType},
"endpointResolverProvider": {loadOptionsType},
"loggerProvider": {loadOptionsType},
"clientLogModeProvider": {loadOptionsType},
"logConfigurationWarningsProvider": {loadOptionsType},
}

var tplProviderTests = template.Must(template.New("tplProviderTests").Funcs(map[string]interface{}{
Expand Down
Loading

0 comments on commit d1a77c7

Please sign in to comment.