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

config: refactor LoadDefaultConfig to take in context and concrete options #951

Merged
merged 4 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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