From d9e8ace95df688217f48eddba7f0ab4196c65626 Mon Sep 17 00:00:00 2001 From: David Beitey Date: Thu, 20 Jul 2023 12:45:39 +1000 Subject: [PATCH] Use config.LoadOptionsFunc type alias This fixes #2193. --- config/config.go | 2 +- config/config_test.go | 4 +-- config/resolve_credentials_test.go | 4 +-- config/resolve_test.go | 6 ++-- config/shared_config_test.go | 56 +++++++++++++++--------------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/config/config.go b/config/config.go index 138f8e76da7..807c41fe48c 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/config_test.go b/config/config_test.go index 0638fb96779..4887d1066b5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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"}), } @@ -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{ diff --git a/config/resolve_credentials_test.go b/config/resolve_credentials_test.go index f099594c77d..c077fc4f76d 100644 --- a/config/resolve_credentials_test.go +++ b/config/resolve_credentials_test.go @@ -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 { @@ -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), } diff --git a/config/resolve_test.go b/config/resolve_test.go index 773e8285c94..842c1b6c6e8 100644 --- a/config/resolve_test.go +++ b/config/resolve_test.go @@ -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"), @@ -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"), @@ -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", diff --git a/config/shared_config_test.go b/config/shared_config_test.go index c2701269cbf..8e124dc4448 100644 --- a/config/shared_config_test.go +++ b/config/shared_config_test.go @@ -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) @@ -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")}), @@ -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")}), @@ -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), @@ -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")}), @@ -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")}), @@ -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")}), @@ -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")}), @@ -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")}), @@ -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")}), @@ -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{ @@ -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{ @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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),