Skip to content

Commit

Permalink
Use config.LoadOptionsFunc type alias
Browse files Browse the repository at this point in the history
This fixes aws#2193.
  • Loading branch information
davidjb committed Jul 20, 2023
1 parent 4051ca8 commit d9e8ace
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (cs configs) ResolveConfig(f func(configs []interface{}) error) error {
// The default configuration sources are:
// * Environment Variables
// * Shared Configuration and Shared Credentials files.
func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) (cfg aws.Config, err error) {
func LoadDefaultConfig(ctx context.Context, optFns ...LoadOptionsFunc) (cfg aws.Config, err error) {
var options LoadOptions
for _, optFn := range optFns {
if err := optFn(&options); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestConfigs_SharedConfigOptions(t *testing.T) {
var options LoadOptions
optFns := []func(*LoadOptions) error{
optFns := []LoadOptionsFunc{
WithSharedConfigProfile("profile-name"),
WithSharedConfigFiles([]string{"creds-file"}),
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestConfigs_AppendFromLoaders(t *testing.T) {

func TestConfigs_ResolveAWSConfig(t *testing.T) {
var options LoadOptions
optFns := []func(*LoadOptions) error{
optFns := []LoadOptionsFunc{
WithRegion("mock-region"),
WithCredentialsProvider(credentials.StaticCredentialsProvider{
Value: aws.Credentials{
Expand Down
4 changes: 2 additions & 2 deletions config/resolve_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestSharedConfigCredentialSource(t *testing.T) {

var credChain []string

loadOptions := []func(*LoadOptions) error{
loadOptions := []LoadOptionsFunc{
WithEndpointResolverWithOptions(endpointResolver),
WithAPIOptions([]func(*middleware.Stack) error{
func(stack *middleware.Stack) error {
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestResolveCredentialsIMDSClient(t *testing.T) {
httpClient = stubErrorClient{err: fmt.Errorf("expected HTTP client error")}
}

opts := []func(*LoadOptions) error{
opts := []LoadOptionsFunc{
WithRetryer(func() aws.Retryer { return aws.NopRetryer{} }),
WithHTTPClient(httpClient),
}
Expand Down
6 changes: 3 additions & 3 deletions config/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestResolveCustomCABundle_ErrorCustomClient(t *testing.T) {

func TestResolveRegion(t *testing.T) {
var options LoadOptions
optFns := []func(options *LoadOptions) error{
optFns := []LoadOptionsFunc{
WithRegion("ignored-region"),

WithRegion("mock-region"),
Expand All @@ -127,7 +127,7 @@ func TestResolveRegion(t *testing.T) {

func TestResolveAppID(t *testing.T) {
var options LoadOptions
optFns := []func(options *LoadOptions) error{
optFns := []LoadOptionsFunc{
WithAppID("1234"),

WithAppID("5678"),
Expand All @@ -152,7 +152,7 @@ func TestResolveAppID(t *testing.T) {

func TestResolveCredentialsProvider(t *testing.T) {
var options LoadOptions
optFns := []func(options *LoadOptions) error{
optFns := []LoadOptionsFunc{
WithCredentialsProvider(credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: "AKID",
Expand Down
56 changes: 28 additions & 28 deletions config/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func TestLoadSharedConfig(t *testing.T) {
}()

cases := []struct {
LoadOptionFn func(*LoadOptions) error
LoadOptionFn LoadOptionsFunc
Files []string
Profile string
LoadFn func(context.Context, configs) (Config, error)
Expand Down Expand Up @@ -949,14 +949,14 @@ func TestSharedConfigLoading(t *testing.T) {
logger := logging.NewStandardLogger(&loggerBuf)

cases := map[string]struct {
LoadOptionFns []func(*LoadOptions) error
LoadOptionFns []LoadOptionsFunc
LoadFn func(context.Context, configs) (Config, error)
Expect SharedConfig
ExpectLog string
Err string
}{
"duplicate profiles in the configuration files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("duplicate-profile"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "load_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
Expand All @@ -973,7 +973,7 @@ func TestSharedConfigLoading(t *testing.T) {
},

"profile prefix not used in the configuration files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("no-such-profile"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "load_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
Expand All @@ -986,7 +986,7 @@ func TestSharedConfigLoading(t *testing.T) {
},

"profile prefix overrides default": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigFiles([]string{filepath.Join("testdata", "load_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithLogConfigurationWarnings(true),
Expand All @@ -1001,7 +1001,7 @@ func TestSharedConfigLoading(t *testing.T) {
},

"duplicate profiles in credentials file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("duplicate-profile"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "load_credentials")}),
Expand All @@ -1018,7 +1018,7 @@ func TestSharedConfigLoading(t *testing.T) {
},

"profile prefix used in credentials files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("unused-profile"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "load_credentials")}),
Expand All @@ -1030,7 +1030,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "failed to get shared config profile, unused-profile",
},
"partial credentials in configuration files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("partial-creds-1"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "load_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
Expand All @@ -1044,7 +1044,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "partial credentials",
},
"parital credentials in the credentials files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("partial-creds-1"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "load_credentials")}),
Expand All @@ -1058,7 +1058,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "partial credentials found for profile partial-creds-1",
},
"credentials override configuration profile": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("complete"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "load_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "load_credentials")}),
Expand All @@ -1078,7 +1078,7 @@ func TestSharedConfigLoading(t *testing.T) {
},
},
"credentials profile has complete credentials": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("complete"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "load_credentials")}),
Expand All @@ -1096,7 +1096,7 @@ func TestSharedConfigLoading(t *testing.T) {
},
},
"credentials split between multiple credentials files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("partial-creds-1"),
WithSharedConfigFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedCredentialsFiles([]string{
Expand All @@ -1113,7 +1113,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "partial credentials",
},
"credentials split between multiple configuration files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("partial-creds-1"),
WithSharedCredentialsFiles([]string{filepath.Join("testdata", "empty_creds_config")}),
WithSharedConfigFiles([]string{
Expand All @@ -1132,7 +1132,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "partial credentials",
},
"credentials split between credentials and config files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("partial-creds-1"),
WithSharedConfigFiles([]string{
filepath.Join("testdata", "load_config"),
Expand All @@ -1151,7 +1151,7 @@ func TestSharedConfigLoading(t *testing.T) {
Err: "partial credentials",
},
"replaced profile with prefixed profile in config files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("replaced-profile"),
WithSharedConfigFiles([]string{
filepath.Join("testdata", "load_config"),
Expand All @@ -1170,7 +1170,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "non-default profile not prefixed with `profile `",
},
"replaced profile with prefixed profile in credentials files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("replaced-profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1189,7 +1189,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile replaced-profile` is ignored.",
},
"ignored profiles w/o prefixed profile across credentials and config files": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("replaced-profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1208,7 +1208,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile replaced-profile` is ignored.",
},
"1. profile with name as `profile` in config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "empty_creds_config"),
Expand All @@ -1224,7 +1224,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile` is ignored",
},
"2. profile with name as `profile ` in config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile "),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "empty_creds_config"),
Expand All @@ -1240,7 +1240,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile` is ignored",
},
"3. profile with name as `profile\t` in config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "empty_creds_config"),
Expand All @@ -1256,7 +1256,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile` is ignored",
},
"profile with tabs as delimiter for profile prefix in config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("with-tab"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "empty_creds_config"),
Expand All @@ -1274,7 +1274,7 @@ func TestSharedConfigLoading(t *testing.T) {
},
},
"profile with tabs as delimiter for profile prefix in credentials file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("with-tab"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1290,7 +1290,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile with-tab` is ignored",
},
"profile with name as `profile profile` in credentials file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1306,7 +1306,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile profile` is ignored",
},
"profile with name profile-bar in credentials file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile-bar"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1324,7 +1324,7 @@ func TestSharedConfigLoading(t *testing.T) {
},
},
"profile with name profile-bar in config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("profile-bar"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "empty_creds_config"),
Expand All @@ -1340,7 +1340,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `profile-bar` is ignored",
},
"profile ignored in credentials and config file": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("ignored-profile"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1356,7 +1356,7 @@ func TestSharedConfigLoading(t *testing.T) {
ExpectLog: "profile defined with name `ignored-profile` is ignored.",
},
"profile with sso_session": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedConfigProfile("sso-session-test"),
WithSharedCredentialsFiles([]string{
filepath.Join("testdata", "load_credentials"),
Expand All @@ -1379,7 +1379,7 @@ func TestSharedConfigLoading(t *testing.T) {
},
},
"config and creds files explicitly set to empty slice": {
LoadOptionFns: []func(*LoadOptions) error{
LoadOptionFns: []LoadOptionsFunc{
WithSharedCredentialsFiles([]string{}),
WithSharedConfigFiles([]string{}),
WithLogConfigurationWarnings(true),
Expand Down

0 comments on commit d9e8ace

Please sign in to comment.