From 96c74759abe5968773d552967f5bc26c5106ac77 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:04:11 -0700 Subject: [PATCH 01/26] all changes, removed gen lambda --- aws/config.go | 4 + .../AwsEndpointConfigTestGenerator.java | 222 ++++++++++++++++++ ...sEndpointResolverInitializerGenerator.java | 45 +++- .../aws/go/codegen/AwsGoDependency.java | 2 + .../ResolveClientConfigFromSources.java | 8 + ...mithy.go.codegen.integration.GoIntegration | 1 + config/config.go | 2 + config/env_config.go | 46 +++- config/env_config_test.go | 16 ++ config/provider.go | 32 +++ config/resolve.go | 18 ++ config/shared_config.go | 87 +++++++ config/shared_config_test.go | 10 +- config/testdata/shared_config | 4 + internal/ini/ini_lexer.go | 4 + internal/ini/ini_parser_test.go | 31 ++- internal/ini/literal_tokens.go | 73 +++++- .../ini/testdata/valid/nested_fields_expected | 1 + .../testdata/valid/op_sep_in_values_expected | 2 +- internal/ini/visitor.go | 19 ++ internal/ini/walker_test.go | 7 +- service/elasticbeanstalk/api_client.go | 1 + service/elasticbeanstalk/endpoints.go | 18 ++ .../elasticbeanstalk/endpoints_config_test.go | 146 ++++++++++++ service/elasticbeanstalk/generated.json | 1 + service/eventbridge/api_client.go | 1 + service/eventbridge/endpoints.go | 18 ++ service/eventbridge/endpoints_config_test.go | 146 ++++++++++++ service/eventbridge/generated.json | 1 + service/s3/api_client.go | 1 + service/s3/endpoints.go | 18 ++ service/s3/endpoints_config_test.go | 146 ++++++++++++ service/s3/generated.json | 1 + service/s3/go.mod | 2 + service/s3/go.sum | 16 ++ service/s3control/api_client.go | 1 + service/s3control/endpoints.go | 18 ++ service/s3control/endpoints_config_test.go | 146 ++++++++++++ service/s3control/generated.json | 1 + service/s3outposts/api_client.go | 1 + service/s3outposts/endpoints.go | 18 ++ service/s3outposts/endpoints_config_test.go | 146 ++++++++++++ service/s3outposts/generated.json | 1 + 43 files changed, 1462 insertions(+), 20 deletions(-) create mode 100644 codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java create mode 100644 service/elasticbeanstalk/endpoints_config_test.go create mode 100644 service/eventbridge/endpoints_config_test.go create mode 100644 service/s3/endpoints_config_test.go create mode 100644 service/s3control/endpoints_config_test.go create mode 100644 service/s3outposts/endpoints_config_test.go diff --git a/aws/config.go b/aws/config.go index fe7aacbfa63..b361c13867c 100644 --- a/aws/config.go +++ b/aws/config.go @@ -146,6 +146,10 @@ type Config struct { // See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for // more information on environment variables and shared config settings. AppID string + + // BaseEndpoint is an intermediary transfer location to a service specific + // BaseEndpoint on a service's Options. + BaseEndpoint *string } // NewConfig returns a new Config pointer that can be chained with builder diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java new file mode 100644 index 00000000000..f54516a9cf9 --- /dev/null +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -0,0 +1,222 @@ +package software.amazon.smithy.aws.go.codegen; + +import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; + +import software.amazon.smithy.aws.traits.ServiceTrait; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.go.codegen.GoSettings; +import software.amazon.smithy.go.codegen.TriConsumer; +import software.amazon.smithy.go.codegen.integration.GoIntegration; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.utils.MapUtils; +import software.amazon.smithy.go.codegen.GoWriter; +import software.amazon.smithy.go.codegen.SmithyGoDependency; +import software.amazon.smithy.go.codegen.SymbolUtils; + +import java.util.Map; +import java.util.function.Consumer; + + +/* + * This class generates service specific tests for resolving configured endpoints. + */ +public class AwsEndpointConfigTestGenerator implements GoIntegration { + + private Map commonCodegenArgs; + + + @Override + public void writeAdditionalFiles( + GoSettings settings, + Model model, + SymbolProvider symbolProvider, + TriConsumer> writerFactory + ) { + String sdkId = settings.getService(model).expectTrait(ServiceTrait.class).getSdkId(); + this.commonCodegenArgs = MapUtils.of( + "envSdkId", sdkId.toUpperCase().replaceAll(" ", "_"), + "configSdkId", sdkId.toLowerCase().replaceAll(" ", "_"), + "urlSdkId", sdkId.toLowerCase().replaceAll(" ", "-"), + "testing", SymbolUtils.createPointableSymbolBuilder("T", SmithyGoDependency.TESTING).build(), + "awsString", SymbolUtils.createValueSymbolBuilder("String", AwsGoDependency.AWS_CORE).build() + ); + + writerFactory.accept("endpoints_config_test.go", settings.getModuleName(), writer -> { + writer.write("$W", generate()); + }); + + } + + + private GoWriter.Writable generate() { + return (GoWriter w) -> { + w.write( + """ + func TestConfiguredEndpoints(t $P) { + $W + + $W + } + """, + SymbolUtils.createPointableSymbolBuilder("T", SmithyGoDependency.TESTING).build(), + generateCases(), + generateTests() + ); + }; + } + + private GoWriter.Writable generateCases() { + return goTemplate( + """ + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-$urlSdkId:L + +[services testing-$urlSdkId:L] +$configSdkId:L = + endpoint_url = http://config-$urlSdkId:L.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: $awsString:T("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-$urlSdkId:L + +[services testing-$urlSdkId:L] +$configSdkId:L = + endpoint_url = http://config-$urlSdkId:L.dev +`, + ExpectURL: $awsString:T("https://env-$urlSdkId:L.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-$urlSdkId:L +ignore_configured_endpoint_urls = true + +[services testing-$urlSdkId:L] +$configSdkId:L = + endpoint_url = http://config-$urlSdkId:L.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: $awsString:T("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-$urlSdkId:L + +[services testing-$urlSdkId:L] +$configSdkId:L = + endpoint_url = http://config-$urlSdkId:L.dev +`, + ExpectURL: $awsString:T("http://config-$urlSdkId:L.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-$urlSdkId:L + +[services testing-$urlSdkId:L] +$configSdkId:L = + endpoint_url = http://config-$urlSdkId:L.dev +`, + ClientEndpoint: $awsString:T("https://client-$urlSdkId:L.dev"), + ExpectURL: $awsString:T("https://client-$urlSdkId:L.dev"), + }, + } + """, + this.commonCodegenArgs + ); + } + + private GoWriter.Writable generateTests() { + return goTemplate( + """ + for name, c := range cases { + t.Run(name, func(t $testing:P) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + $writeFile:T($joinFile:T(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), $fileMode:T(int(0777))) + + awsConfig, err := $loadDefaultConfig:T( + $contextTodo:T(), + $withSharedConfig:T([]string{$joinFile:T(tmpDir, "test_shared_config")}), + $withSharedConfigProfile:T("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func (o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !$deepEqual:T(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } + """, + this.commonCodegenArgs, + MapUtils.of( + "writeFile", SymbolUtils.createValueSymbolBuilder("WriteFile", SmithyGoDependency.OS).build(), + "joinFile", SymbolUtils.createValueSymbolBuilder("Join", SmithyGoDependency.PATH_FILEPATH).build(), + "fileMode", SymbolUtils.createValueSymbolBuilder("FileMode", SmithyGoDependency.OS).build(), + "loadDefaultConfig", SymbolUtils.createValueSymbolBuilder("LoadDefaultConfig", AwsGoDependency.CONFIG).build(), + "contextTodo", SymbolUtils.createValueSymbolBuilder("TODO", SmithyGoDependency.CONTEXT).build(), + "withSharedConfig", SymbolUtils.createValueSymbolBuilder("WithSharedConfigFiles", AwsGoDependency.CONFIG).build(), + "withSharedConfigProfile", SymbolUtils.createValueSymbolBuilder("WithSharedConfigProfile", AwsGoDependency.CONFIG).build(), + "deepEqual", SymbolUtils.createValueSymbolBuilder("DeepEqual", SmithyGoDependency.REFLECT).build() + ) + ); + } +} diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java index 6d27efa3b24..09b9b932a5e 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java @@ -3,6 +3,7 @@ import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; +import software.amazon.smithy.aws.traits.ServiceTrait; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.go.codegen.GoSettings; import software.amazon.smithy.go.codegen.GoWriter; @@ -24,6 +25,7 @@ public class AwsEndpointResolverInitializerGenerator implements GoIntegration { public static final String RESOLVE_ENDPOINT_RESOLVER_V2 = "resolve" + EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME; + public static final String RESOLVE_BASE_ENDPOINT = "resolveBaseEndpoint"; @Override public void writeAdditionalFiles( @@ -34,10 +36,51 @@ public void writeAdditionalFiles( ) { writerFactory.accept("endpoints.go", settings.getModuleName(), writer -> { - writer.write("$W", generateResolveMethod()); + writer.write( + """ + $W + + $W + + """ + , + generateResolveMethod(), + generateConfigResolverMethod( + settings.getService(model).expectTrait(ServiceTrait.class).getSdkId()) + ); }); } + private GoWriter.Writable generateConfigResolverMethod(String sdkId) { + return goTemplate( + """ + func $resolveMethodName:L(cfg $awsConfig:T, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []$config:T + for _, c := range cfg.ConfigSources { + if cs, ok := c.($config:T); ok { + configSources = append(configSources, cs) + } + } + value, found, err := $resolveServiceEndpoint:T(context.Background(), "$sdkId:L", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } + } + """, + MapUtils.of( + "resolveMethodName", RESOLVE_BASE_ENDPOINT, + "awsConfig", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.AWS_CORE).build(), + "config", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.CONFIG).build(), + "resolveServiceEndpoint", SymbolUtils.createValueSymbolBuilder( + "ResolveServiceBaseEndpoint", AwsGoDependency.INTERNAL_ENDPOINTS_CONFIG).build(), + "sdkId", sdkId + ) + ); + } + private GoWriter.Writable generateResolveMethod() { return goTemplate( diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java index b21e135dcce..8733fbbc8c9 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java @@ -38,9 +38,11 @@ public class AwsGoDependency { null, Versions.AWS_PROTOCOL_EVENTSTREAM, "eventstream"); public static final GoDependency SERVICE_INTERNAL_EVENTSTREAMAPI = awsModuleDep("aws/protocol/eventstream", "eventstreamapi", Versions.AWS_PROTOCOL_EVENTSTREAM, "eventstreamapi"); + public static final GoDependency CONFIG = aws("config"); public static final GoDependency AWS_ENDPOINT_RULESFN = aws("internal/endpoints/awsrulesfn"); public static final GoDependency INTERNAL_ENDPOINTS = aws("internal/endpoints"); + public static final GoDependency INTERNAL_ENDPOINTS_CONFIG = aws("internal/endpoints/config", "internalepconfig"); public static final GoDependency INTERNAL_AUTH = aws("internal/auth", "internalauth"); public static final GoDependency INTERNAL_ENDPOINTS_V2 = awsModuleDep("internal/endpoints/v2", null, diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/ResolveClientConfigFromSources.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/ResolveClientConfigFromSources.java index 5af199db31c..e217cb469f5 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/ResolveClientConfigFromSources.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/ResolveClientConfigFromSources.java @@ -87,6 +87,14 @@ public class ResolveClientConfigFromSources implements GoIntegration { .generatedOnClient(false) .awsResolveFunction(SymbolUtils.createValueSymbolBuilder(USE_FIPS_ENDPOINT_CONFIG_RESOLVER) .build()) + .build(), + AddAwsConfigFields.AwsConfigField.builder() + .name("BaseEndpoint") + .type(SymbolUtils.createPointableSymbolBuilder("string").build()) + .generatedOnClient(false) + .awsResolveFunction(SymbolUtils.createValueSymbolBuilder( + AwsEndpointResolverInitializerGenerator.RESOLVE_BASE_ENDPOINT) + .build()) .build() ); diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration index 7633740e9b2..20ecc427b6d 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration +++ b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration @@ -60,4 +60,5 @@ software.amazon.smithy.aws.go.codegen.customization.S3SerializeImmutableHostname software.amazon.smithy.aws.go.codegen.customization.S3UpdateOutpostArn software.amazon.smithy.aws.go.codegen.LegacyEndpointContextSetter software.amazon.smithy.aws.go.codegen.customization.DisableEndpointHostPrefix +software.amazon.smithy.aws.go.codegen.AwsEndpointConfigTestGenerator diff --git a/config/config.go b/config/config.go index bf26eab9a9a..ef9f753d408 100644 --- a/config/config.go +++ b/config/config.go @@ -72,6 +72,8 @@ var defaultAWSConfigResolvers = []awsConfigResolver{ // Sets the sdk app ID if present in shared config profile resolveAppID, + + resolveBaseEndpoint, } // A Config represents a generic configuration value or set of values. This type diff --git a/config/env_config.go b/config/env_config.go index a142a45c544..4a3e00be6fe 100644 --- a/config/env_config.go +++ b/config/env_config.go @@ -70,6 +70,9 @@ const ( awsRetryMaxAttempts = "AWS_MAX_ATTEMPTS" awsRetryMode = "AWS_RETRY_MODE" awsSdkAppID = "AWS_SDK_UA_APP_ID" + + awsIgnoreConfiguredEndpoints = "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS" + awsEndpointURL = "AWS_ENDPOINT_URL" ) var ( @@ -251,7 +254,14 @@ type EnvConfig struct { RetryMode aws.RetryMode // aws sdk app ID that can be added to user agent header string - AppID string + AppID string + + // Flag used to disable configured endpoints. + IgnoreConfiguredEndpoints *bool + + // Value to contain configured endpoints to be propagated to + // corresponding endpoint resolution field. + BaseEndpoint string } // loadEnvConfig reads configuration values from the OS's environment variables. @@ -331,6 +341,12 @@ func NewEnvConfig() (EnvConfig, error) { return cfg, err } + setStringFromEnvVal(&cfg.BaseEndpoint, []string{awsEndpointURL}) + + if err := setBoolPtrFromEnvVal(&cfg.IgnoreConfiguredEndpoints, []string{awsIgnoreConfiguredEndpoints}); err != nil { + return cfg, err + } + return cfg, nil } @@ -482,6 +498,34 @@ func (c EnvConfig) getCustomCABundle(context.Context) (io.Reader, bool, error) { return bytes.NewReader(b), true, nil } +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (c EnvConfig) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + if c.IgnoreConfiguredEndpoints == nil { + return false, false, nil + } + + return *c.IgnoreConfiguredEndpoints, true, nil +} + +func (c EnvConfig) getBaseEndpoint(context.Context) (string, bool, error) { + return c.BaseEndpoint, len(c.BaseEndpoint) > 0, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (c EnvConfig) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if endpt := os.Getenv(fmt.Sprintf("%s_%s", awsEndpointURL, normalizeEnv(sdkID))); endpt != "" { + return endpt, true, nil + } + return "", false, nil +} + +func normalizeEnv(sdkID string) string { + upper := strings.ToUpper(sdkID) + return strings.ReplaceAll(upper, " ", "_") +} + // GetS3UseARNRegion returns whether to allow ARNs to direct the region // the S3 client's requests are sent to. func (c EnvConfig) GetS3UseARNRegion(ctx context.Context) (value, ok bool, err error) { diff --git a/config/env_config_test.go b/config/env_config_test.go index afc568e3263..efb85e91c64 100644 --- a/config/env_config_test.go +++ b/config/env_config_test.go @@ -423,6 +423,22 @@ func TestNewEnvConfig(t *testing.T) { Config: EnvConfig{}, WantErr: true, }, + 38: { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "http://localhost:5567", + }, + Config: EnvConfig{ + BaseEndpoint: "http://localhost:5567", + }, + }, + 39: { + Env: map[string]string{ + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + Config: EnvConfig{ + IgnoreConfiguredEndpoints: ptr.Bool(true), + }, + }, } for i, c := range cases { diff --git a/config/provider.go b/config/provider.go index b056235152e..c77bc784f6a 100644 --- a/config/provider.go +++ b/config/provider.go @@ -142,6 +142,38 @@ func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []Config) (value return } +type baseEndpointProvider interface { + getBaseEndpoint(ctx context.Context) (string, bool, error) +} + +func getBaseEndpoint(ctx context.Context, configs configs) (value string, found bool, err error) { + for _, cfg := range configs { + if p, ok := cfg.(baseEndpointProvider); ok { + value, found, err = p.getBaseEndpoint(ctx) + if err != nil || found { + break + } + } + } + return +} + +type servicesObjectProvider interface { + getServicesObject(ctx context.Context) (map[string]map[string]string, bool, error) +} + +func getServicesObject(ctx context.Context, configs configs) (value map[string]map[string]string, found bool, err error) { + for _, cfg := range configs { + if p, ok := cfg.(servicesObjectProvider); ok { + value, found, err = p.getServicesObject(ctx) + if err != nil || found { + break + } + } + } + return +} + // appIDProvider provides access to the sdk app ID value type appIDProvider interface { getAppID(ctx context.Context) (string, bool, error) diff --git a/config/resolve.go b/config/resolve.go index 1187e8c4803..3c087265ae8 100644 --- a/config/resolve.go +++ b/config/resolve.go @@ -106,6 +106,24 @@ func resolveRegion(ctx context.Context, cfg *aws.Config, configs configs) error return nil } +func resolveBaseEndpoint(ctx context.Context, cfg *aws.Config, configs configs) error { + if val, found, err := GetIgnoreConfiguredEndpoints(ctx, configs); found && val && err == nil { + cfg.BaseEndpoint = nil + return nil + } + + v, found, err := getBaseEndpoint(ctx, configs) + if err != nil { + return err + } + + if !found { + return nil + } + cfg.BaseEndpoint = aws.String(v) + return nil +} + // resolveAppID extracts the sdk app ID from the configs slice's SharedConfig or env var func resolveAppID(ctx context.Context, cfg *aws.Config, configs configs) error { ID, _, err := getAppID(ctx, configs) diff --git a/config/shared_config.go b/config/shared_config.go index ae5ba76584e..435051735b4 100644 --- a/config/shared_config.go +++ b/config/shared_config.go @@ -28,6 +28,10 @@ const ( // the shared config file, not the credentials file. ssoSectionPrefix = `sso-session ` + // Prefix for services section. It is referenced in profile via the services + // parameter to configure clients for service-specific parameters. + servicesPrefix = `services` + // string equivalent for boolean endpointDiscoveryDisabled = `false` endpointDiscoveryEnabled = `true` @@ -97,6 +101,10 @@ const ( caBundleKey = "ca_bundle" sdkAppID = "sdk_ua_app_id" + + ignoreConfiguredEndpoints = "ignore_configured_endpoint_urls" + + endpointURL = "endpoint_url" ) // defaultSharedConfigProfile allows for swapping the default profile for testing @@ -150,6 +158,24 @@ func (s *SSOSession) setFromIniSection(section ini.Section) { updateString(&s.SSOStartURL, section, ssoStartURLKey) } +// Services contains values configured in the services section +// of the AWS configuration file. +type Services struct { + // Services section values + // {"serviceId": {"key": "value"}} + // e.g. {"s3": {"endpoint_url": "example.com"}} + ServiceValues map[string]map[string]string +} + +func (s *Services) setFromIniSection(section ini.Section) { + if s.ServiceValues == nil { + s.ServiceValues = make(map[string]map[string]string) + } + for _, service := range section.List() { + s.ServiceValues[service] = section.Map(service) + } +} + // SharedConfig represents the configuration fields of the SDK config files. type SharedConfig struct { Profile string @@ -272,6 +298,16 @@ type SharedConfig struct { // aws sdk app ID that can be added to user agent header string AppID string + + // Flag used to disable configured endpoints. + IgnoreConfiguredEndpoints *bool + + // Value to contain configured endpoints to be propagated to + // corresponding endpoint resolution field. + BaseEndpoint string + + // Value to contain services section content. + Services Services } func (c SharedConfig) getDefaultsMode(ctx context.Context) (value aws.DefaultsMode, ok bool, err error) { @@ -399,6 +435,40 @@ func (c SharedConfig) getAppID(context.Context) (string, bool, error) { return c.AppID, len(c.AppID) > 0, nil } +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (c SharedConfig) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + if c.IgnoreConfiguredEndpoints == nil { + return false, false, nil + } + + return *c.IgnoreConfiguredEndpoints, true, nil +} + +func (c SharedConfig) getBaseEndpoint(context.Context) (string, bool, error) { + return c.BaseEndpoint, len(c.BaseEndpoint) > 0, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (c SharedConfig) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if service, ok := c.Services.ServiceValues[normalizeShared(sdkID)]; ok { + if endpt, ok := service[endpointURL]; ok { + return endpt, true, nil + } + } + return "", false, nil +} + +func normalizeShared(sdkID string) string { + lower := strings.ToLower(sdkID) + return strings.ReplaceAll(lower, " ", "_") +} + +func (c SharedConfig) getServicesObject(context.Context) (map[string]map[string]string, bool, error) { + return c.Services.ServiceValues, c.Services.ServiceValues != nil, nil +} + // loadSharedConfigIgnoreNotExist is an alias for loadSharedConfig with the // addition of ignoring when none of the files exist or when the profile // is not found in any of the files. @@ -548,6 +618,7 @@ func LoadSharedConfigProfile(ctx context.Context, profile string, optFns ...func cfg := SharedConfig{} profiles := map[string]struct{}{} + if err = cfg.setFromIniSections(profiles, profile, configSections, option.Logger); err != nil { return SharedConfig{}, err } @@ -576,6 +647,7 @@ func processConfigSections(ctx context.Context, sections *ini.Sections, logger l skipSections[newName] = struct{}{} case strings.HasPrefix(section, ssoSectionPrefix): + case strings.HasPrefix(section, servicesPrefix): case strings.EqualFold(section, "default"): default: // drop this section, as invalid profile name @@ -884,6 +956,17 @@ func (c *SharedConfig) setFromIniSections(profiles map[string]struct{}, profile c.SSOSession = &ssoSession } + for _, sectionName := range sections.List() { + if strings.HasPrefix(sectionName, servicesPrefix) { + section, ok := sections.GetSection(sectionName) + if ok { + var svcs Services + svcs.setFromIniSection(section) + c.Services = svcs + } + } + } + return nil } @@ -977,6 +1060,10 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er // user agent app ID added to request User-Agent header updateString(&c.AppID, section, sdkAppID) + updateBoolPtr(&c.IgnoreConfiguredEndpoints, section, ignoreConfiguredEndpoints) + + updateString(&c.BaseEndpoint, section, endpointURL) + // Shared Credentials creds := aws.Credentials{ AccessKeyID: section.String(accessKeyIDKey), diff --git a/config/shared_config_test.go b/config/shared_config_test.go index c2701269cbf..128bc6dac7b 100644 --- a/config/shared_config_test.go +++ b/config/shared_config_test.go @@ -652,7 +652,15 @@ func TestNewSharedConfig(t *testing.T) { AppID: "12345", }, }, - } + "endpoint config test": { + ConfigFilenames: []string{testConfigFilename}, + Profile: "endpoint_config", + Expected: SharedConfig{ + Profile: "endpoint_config", + BaseEndpoint: "http://localhost:5567", + IgnoreConfiguredEndpoints: ptr.Bool(true), + }, + }} for name, c := range cases { t.Run(name, func(t *testing.T) { diff --git a/config/testdata/shared_config b/config/testdata/shared_config index 5904acd0150..4c50293faaa 100644 --- a/config/testdata/shared_config +++ b/config/testdata/shared_config @@ -278,3 +278,7 @@ ca_bundle = custom_ca_bundle_file.pem [profile sdk_app_id] sdk_ua_app_id = 12345 + +[profile endpoint_config] +ignore_configured_endpoint_urls = true +endpoint_url = http://localhost:5567 diff --git a/internal/ini/ini_lexer.go b/internal/ini/ini_lexer.go index abf1fb03626..ab16760dd16 100644 --- a/internal/ini/ini_lexer.go +++ b/internal/ini/ini_lexer.go @@ -67,6 +67,8 @@ func (l *iniLexer) tokenize(b []byte) ([]Token, error) { for len(runes) > 0 && count < tokenAmount { switch { + case isSubProperty(runes): + tokens[count], n, err = newLitToken(runes) case isWhitespace(runes[0]): tokens[count], n, err = newWSToken(runes) case isComma(runes[0]): @@ -101,6 +103,8 @@ func countTokens(runes []rune) int { for len(runes) > 0 { switch { + case isSubProperty(runes): + _, n, err = newLitToken(runes) case isWhitespace(runes[0]): _, n, err = newWSToken(runes) case isComma(runes[0]): diff --git a/internal/ini/ini_parser_test.go b/internal/ini/ini_parser_test.go index b0bc1a136a3..a4e51088507 100644 --- a/internal/ini/ini_parser_test.go +++ b/internal/ini/ini_parser_test.go @@ -17,6 +17,9 @@ func TestParser(t *testing.T) { regionLit, _, _ := newLitToken([]rune(`"us-west-2"`)) regionNoQuotesLit, _, _ := newLitToken([]rune("us-west-2")) + s3ServiceID, _, _ := newLitToken([]rune("s3")) + nestedParamsLit, _, _ := newLitToken([]rune("\n\tfoo=bar\n\tbar=baz\n")) + credentialID, _, _ := newLitToken([]rune("credential_source")) ec2MetadataLit, _, _ := newLitToken([]rune("Ec2InstanceMetadata")) @@ -57,6 +60,9 @@ func TestParser(t *testing.T) { sepInValueExpr := newEqualExpr(newExpression(sepInValueID), equalOp) sepInValueExpr.AppendChild(newExpression(sepInValueLit)) + nestedEQExpr := newEqualExpr(newExpression(s3ServiceID), equalOp) + nestedEQExpr.AppendChild(newExpression(nestedParamsLit)) + cases := []struct { name string r io.Reader @@ -206,8 +212,9 @@ func TestParser(t *testing.T) { }, { name: "section statement", - r: bytes.NewBuffer([]byte(`[default] - region="us-west-2"`)), + r: bytes.NewBuffer([]byte( + `[default] +region="us-west-2"`)), expectedStack: []AST{ newCompletedSectionStatement( defaultProfileStmt, @@ -217,15 +224,15 @@ func TestParser(t *testing.T) { }, { name: "complex section statement", - r: bytes.NewBuffer([]byte(`[default] - region = us-west-2 - credential_source = Ec2InstanceMetadata - output = json + r: bytes.NewBuffer([]byte( + `[default] +region = us-west-2 +credential_source = Ec2InstanceMetadata +output = json - [assumerole] - output = json - region = us-west-2 - `)), +[assumerole] +output = json +region = us-west-2`)), expectedStack: []AST{ newCompletedSectionStatement( defaultProfileStmt, @@ -258,7 +265,7 @@ region = us-west-2 newCompletedSectionStatement( defaultProfileStmt, ), - newSkipStatement(newEqualExpr(newExpression(s3ID), equalOp)), + newExprStatement(nestedEQExpr), newExprStatement(noQuotesRegionEQRegion), newExprStatement(credEQExpr), newExprStatement(outputEQExpr), @@ -289,7 +296,7 @@ region = us-west-2 ), newExprStatement(noQuotesRegionEQRegion), newExprStatement(credEQExpr), - newSkipStatement(newEqualExpr(newExpression(s3ID), equalOp)), + newExprStatement(nestedEQExpr), newExprStatement(outputEQExpr), newCompletedSectionStatement( assumeProfileStmt, diff --git a/internal/ini/literal_tokens.go b/internal/ini/literal_tokens.go index efcd2e6c7da..a24903202ac 100644 --- a/internal/ini/literal_tokens.go +++ b/internal/ini/literal_tokens.go @@ -60,7 +60,6 @@ const ( NoneType = ValueType(iota) StringType QuotedStringType - // FUTURE(2226) MapType ) // Value is a union container @@ -69,7 +68,7 @@ type Value struct { raw []rune str string - // FUTURE(2226) mp map[string]string + mp map[string]string } func newValue(t ValueType, base int, raw []rune) (Value, error) { @@ -81,6 +80,9 @@ func newValue(t ValueType, base int, raw []rune) (Value, error) { switch t { case StringType: v.str = string(raw) + if isSubProperty(raw) { + v.mp = v.MapValue() + } case QuotedStringType: v.str = string(raw[1 : len(raw)-1]) } @@ -114,8 +116,15 @@ func newLitToken(b []rune) (Token, int, error) { if err != nil { return token, n, err } - token = newToken(TokenLit, b[:n], QuotedStringType) + } else if isSubProperty(b) { + offset := 0 + end, err := getSubProperty(b, offset) + if err != nil { + return token, n, err + } + token = newToken(TokenLit, b[offset:end], StringType) + n = end } else { n, err = getValue(b) token = newToken(TokenLit, b[:n], StringType) @@ -124,6 +133,63 @@ func newLitToken(b []rune) (Token, int, error) { return token, n, err } +func isSubProperty(runes []rune) bool { + // needs at least + // (1) newline (2) whitespace (3) literal + if len(runes) < 3 { + return false + } + + // must have an equal expression + split := strings.FieldsFunc(string(runes), func(r rune) bool { + return isOp([]rune{r}) + }) + if len(split) < 2 { + return false + } + + // must start with a new line + if !isNewline(runes) { + return false + } + _, n, err := newNewlineToken(runes) + if err != nil { + return false + } + + // whitespace must follow newline + return isWhitespace(runes[n]) +} + +// getSubProperty pulls all subproperties and terminates when +// it hits a newline that is not the start of another subproperty. +// offset allows for removal of leading newline and whitespace +// characters +func getSubProperty(runes []rune, offset int) (int, error) { + for idx, val := range runes[offset:] { + if val == '\n' && !isSubProperty(runes[offset+idx:]) { + return offset + idx, nil + } + } + return 0, fmt.Errorf("no sub property") +} + +// MapValue returns a map value for sub properties +func (v Value) MapValue() map[string]string { + newlineParts := strings.Split(string(v.raw), "\n") + mp := make(map[string]string) + for _, part := range newlineParts { + operandParts := strings.Split(part, "=") + if len(operandParts) < 2 { + continue + } + key := strings.TrimSpace(operandParts[0]) + val := strings.TrimSpace(operandParts[1]) + mp[key] = val + } + return mp +} + // IntValue returns an integer value func (v Value) IntValue() (int64, bool) { i, err := strconv.ParseInt(string(v.raw), 0, 64) @@ -165,6 +231,7 @@ func isTrimmable(r rune) bool { // StringValue returns the string value func (v Value) StringValue() string { switch v.Type { + case StringType: return strings.TrimFunc(string(v.raw), isTrimmable) case QuotedStringType: diff --git a/internal/ini/testdata/valid/nested_fields_expected b/internal/ini/testdata/valid/nested_fields_expected index 0f1ae73acfc..c51a24cbdea 100644 --- a/internal/ini/testdata/valid/nested_fields_expected +++ b/internal/ini/testdata/valid/nested_fields_expected @@ -1,5 +1,6 @@ { "foo": { + "aws_access_key_id": "map[aws_secret_access_key:valid]", "aws_session_token": "valid" }, "bar": { diff --git a/internal/ini/testdata/valid/op_sep_in_values_expected b/internal/ini/testdata/valid/op_sep_in_values_expected index a2609269eb4..7a85944b1ad 100644 --- a/internal/ini/testdata/valid/op_sep_in_values_expected +++ b/internal/ini/testdata/valid/op_sep_in_values_expected @@ -19,7 +19,7 @@ "key": "value5" }, "case6": { - "s3": "", + "s3": "map[key:valuen6]", "key": "=value6" }, "case7": { diff --git a/internal/ini/visitor.go b/internal/ini/visitor.go index 97fb3d7f3a2..c124ad61030 100644 --- a/internal/ini/visitor.go +++ b/internal/ini/visitor.go @@ -220,6 +220,20 @@ func NewSection(name string) Section { } } +// List will return a list of all +// services in values +func (t Section) List() []string { + keys := make([]string, len(t.values)) + i := 0 + for k := range t.values { + keys[i] = k + i++ + } + + sort.Strings(keys) + return keys +} + // UpdateSourceFile updates source file for a property to provided filepath. func (t Section) UpdateSourceFile(property string, filepath string) { t.SourceFile[property] = filepath @@ -254,6 +268,11 @@ func (t Section) Int(k string) (int64, bool) { return t.values[k].IntValue() } +// Map returns a map value at k +func (t Section) Map(k string) map[string]string { + return t.values[k].MapValue() +} + // Float64 returns a float value at k func (t Section) Float64(k string) (float64, bool) { return t.values[k].FloatValue() diff --git a/internal/ini/walker_test.go b/internal/ini/walker_test.go index 02946be782b..87cef0b5419 100644 --- a/internal/ini/walker_test.go +++ b/internal/ini/walker_test.go @@ -71,7 +71,12 @@ func TestValidDataFiles(t *testing.T) { for k, v := range table { switch e := v.(type) { case string: - a := p.String(k) + var a string + if p.values[k].mp != nil { + a = fmt.Sprintf("%v", p.values[k].mp) + } else { + a = p.String(k) + } if e != a { t.Errorf("%s: expected %v, but received %v for profile %v", path, e, a, profile) } diff --git a/service/elasticbeanstalk/api_client.go b/service/elasticbeanstalk/api_client.go index de475a41106..605c2e79f69 100644 --- a/service/elasticbeanstalk/api_client.go +++ b/service/elasticbeanstalk/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticbeanstalk/endpoints.go b/service/elasticbeanstalk/endpoints.go index a76c816d1b3..7ca9738595d 100644 --- a/service/elasticbeanstalk/endpoints.go +++ b/service/elasticbeanstalk/endpoints.go @@ -8,7 +8,9 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -194,6 +196,22 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []config.Config + for _, c := range cfg.ConfigSources { + if cs, ok := c.(config.Config); ok { + configSources = append(configSources, cs) + } + } + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Beanstalk", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticbeanstalk/endpoints_config_test.go b/service/elasticbeanstalk/endpoints_config_test.go new file mode 100644 index 00000000000..3a4c29251f4 --- /dev/null +++ b/service/elasticbeanstalk/endpoints_config_test.go @@ -0,0 +1,146 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticbeanstalk + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestConfiguredEndpoints(t *testing.T) { + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-elastic-beanstalk + +[services testing-elastic-beanstalk] +elastic_beanstalk = + endpoint_url = http://config-elastic-beanstalk.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-elastic-beanstalk + +[services testing-elastic-beanstalk] +elastic_beanstalk = + endpoint_url = http://config-elastic-beanstalk.dev +`, + ExpectURL: aws.String("https://env-elastic-beanstalk.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-elastic-beanstalk +ignore_configured_endpoint_urls = true + +[services testing-elastic-beanstalk] +elastic_beanstalk = + endpoint_url = http://config-elastic-beanstalk.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-elastic-beanstalk + +[services testing-elastic-beanstalk] +elastic_beanstalk = + endpoint_url = http://config-elastic-beanstalk.dev +`, + ExpectURL: aws.String("http://config-elastic-beanstalk.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-elastic-beanstalk + +[services testing-elastic-beanstalk] +elastic_beanstalk = + endpoint_url = http://config-elastic-beanstalk.dev +`, + ClientEndpoint: aws.String("https://client-elastic-beanstalk.dev"), + ExpectURL: aws.String("https://client-elastic-beanstalk.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + + awsConfig, err := config.LoadDefaultConfig( + context.TODO(), + config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), + config.WithSharedConfigProfile("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticbeanstalk/generated.json b/service/elasticbeanstalk/generated.json index 54a6819aa0b..31d19929d0d 100644 --- a/service/elasticbeanstalk/generated.json +++ b/service/elasticbeanstalk/generated.json @@ -60,6 +60,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/eventbridge/api_client.go b/service/eventbridge/api_client.go index 84e751410db..5c85e759354 100644 --- a/service/eventbridge/api_client.go +++ b/service/eventbridge/api_client.go @@ -306,6 +306,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/eventbridge/endpoints.go b/service/eventbridge/endpoints.go index 4c9f8c1818b..16d9480a7c4 100644 --- a/service/eventbridge/endpoints.go +++ b/service/eventbridge/endpoints.go @@ -8,7 +8,9 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/eventbridge/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -196,6 +198,22 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []config.Config + for _, c := range cfg.ConfigSources { + if cs, ok := c.(config.Config); ok { + configSources = append(configSources, cs) + } + } + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EventBridge", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/eventbridge/endpoints_config_test.go b/service/eventbridge/endpoints_config_test.go new file mode 100644 index 00000000000..e10887fa3f0 --- /dev/null +++ b/service/eventbridge/endpoints_config_test.go @@ -0,0 +1,146 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package eventbridge + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestConfiguredEndpoints(t *testing.T) { + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-eventbridge + +[services testing-eventbridge] +eventbridge = + endpoint_url = http://config-eventbridge.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-eventbridge + +[services testing-eventbridge] +eventbridge = + endpoint_url = http://config-eventbridge.dev +`, + ExpectURL: aws.String("https://env-eventbridge.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-eventbridge +ignore_configured_endpoint_urls = true + +[services testing-eventbridge] +eventbridge = + endpoint_url = http://config-eventbridge.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-eventbridge + +[services testing-eventbridge] +eventbridge = + endpoint_url = http://config-eventbridge.dev +`, + ExpectURL: aws.String("http://config-eventbridge.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-eventbridge + +[services testing-eventbridge] +eventbridge = + endpoint_url = http://config-eventbridge.dev +`, + ClientEndpoint: aws.String("https://client-eventbridge.dev"), + ExpectURL: aws.String("https://client-eventbridge.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + + awsConfig, err := config.LoadDefaultConfig( + context.TODO(), + config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), + config.WithSharedConfigProfile("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/eventbridge/generated.json b/service/eventbridge/generated.json index fd1b23441d5..34a0eda61ae 100644 --- a/service/eventbridge/generated.json +++ b/service/eventbridge/generated.json @@ -69,6 +69,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/s3/api_client.go b/service/s3/api_client.go index 1ddcba2b256..e921189aa41 100644 --- a/service/s3/api_client.go +++ b/service/s3/api_client.go @@ -347,6 +347,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveDisableMultiRegionAccessPoints(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/s3/endpoints.go b/service/s3/endpoints.go index c6012bdb2d3..f10dcab9b84 100644 --- a/service/s3/endpoints.go +++ b/service/s3/endpoints.go @@ -8,7 +8,9 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -204,6 +206,22 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []config.Config + for _, c := range cfg.ConfigSources { + if cs, ok := c.(config.Config); ok { + configSources = append(configSources, cs) + } + } + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/s3/endpoints_config_test.go b/service/s3/endpoints_config_test.go new file mode 100644 index 00000000000..eab499b5bf0 --- /dev/null +++ b/service/s3/endpoints_config_test.go @@ -0,0 +1,146 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package s3 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestConfiguredEndpoints(t *testing.T) { + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3 + +[services testing-s3] +s3 = + endpoint_url = http://config-s3.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3 + +[services testing-s3] +s3 = + endpoint_url = http://config-s3.dev +`, + ExpectURL: aws.String("https://env-s3.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3 +ignore_configured_endpoint_urls = true + +[services testing-s3] +s3 = + endpoint_url = http://config-s3.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3 + +[services testing-s3] +s3 = + endpoint_url = http://config-s3.dev +`, + ExpectURL: aws.String("http://config-s3.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3 + +[services testing-s3] +s3 = + endpoint_url = http://config-s3.dev +`, + ClientEndpoint: aws.String("https://client-s3.dev"), + ExpectURL: aws.String("https://client-s3.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + + awsConfig, err := config.LoadDefaultConfig( + context.TODO(), + config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), + config.WithSharedConfigProfile("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/s3/generated.json b/service/s3/generated.json index 414c8124f8b..b15270c4d7b 100644 --- a/service/s3/generated.json +++ b/service/s3/generated.json @@ -111,6 +111,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/s3/go.mod b/service/s3/go.mod index a44295ee04b..bdcaef722bc 100644 --- a/service/s3/go.mod +++ b/service/s3/go.mod @@ -5,7 +5,9 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 + github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 diff --git a/service/s3/go.sum b/service/s3/go.sum index a646f1d3099..f46582b3ef9 100644 --- a/service/s3/go.sum +++ b/service/s3/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/s3control/api_client.go b/service/s3control/api_client.go index 41f2edbce60..171146692b3 100644 --- a/service/s3control/api_client.go +++ b/service/s3control/api_client.go @@ -316,6 +316,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveUseARNRegion(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/s3control/endpoints.go b/service/s3control/endpoints.go index 56f7fd832c9..6bc6a05b075 100644 --- a/service/s3control/endpoints.go +++ b/service/s3control/endpoints.go @@ -8,7 +8,9 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3control/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -204,6 +206,22 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []config.Config + for _, c := range cfg.ConfigSources { + if cs, ok := c.(config.Config); ok { + configSources = append(configSources, cs) + } + } + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3 Control", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/s3control/endpoints_config_test.go b/service/s3control/endpoints_config_test.go new file mode 100644 index 00000000000..e4621b4c326 --- /dev/null +++ b/service/s3control/endpoints_config_test.go @@ -0,0 +1,146 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package s3control + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestConfiguredEndpoints(t *testing.T) { + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3-control + +[services testing-s3-control] +s3_control = + endpoint_url = http://config-s3-control.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3-control + +[services testing-s3-control] +s3_control = + endpoint_url = http://config-s3-control.dev +`, + ExpectURL: aws.String("https://env-s3-control.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3-control +ignore_configured_endpoint_urls = true + +[services testing-s3-control] +s3_control = + endpoint_url = http://config-s3-control.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3-control + +[services testing-s3-control] +s3_control = + endpoint_url = http://config-s3-control.dev +`, + ExpectURL: aws.String("http://config-s3-control.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3-control + +[services testing-s3-control] +s3_control = + endpoint_url = http://config-s3-control.dev +`, + ClientEndpoint: aws.String("https://client-s3-control.dev"), + ExpectURL: aws.String("https://client-s3-control.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + + awsConfig, err := config.LoadDefaultConfig( + context.TODO(), + config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), + config.WithSharedConfigProfile("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/s3control/generated.json b/service/s3control/generated.json index a8e502cc16d..7ba69ba9396 100644 --- a/service/s3control/generated.json +++ b/service/s3control/generated.json @@ -77,6 +77,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/s3outposts/api_client.go b/service/s3outposts/api_client.go index 55381791c63..181674dd144 100644 --- a/service/s3outposts/api_client.go +++ b/service/s3outposts/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/s3outposts/endpoints.go b/service/s3outposts/endpoints.go index 173b7e8e6bd..caa32c47857 100644 --- a/service/s3outposts/endpoints.go +++ b/service/s3outposts/endpoints.go @@ -8,7 +8,9 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3outposts/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -194,6 +196,22 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + var configSources []config.Config + for _, c := range cfg.ConfigSources { + if cs, ok := c.(config.Config); ok { + configSources = append(configSources, cs) + } + } + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3Outposts", configSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/s3outposts/endpoints_config_test.go b/service/s3outposts/endpoints_config_test.go new file mode 100644 index 00000000000..3200b67921f --- /dev/null +++ b/service/s3outposts/endpoints_config_test.go @@ -0,0 +1,146 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package s3outposts + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestConfiguredEndpoints(t *testing.T) { + cases := map[string]struct { + Env map[string]string + SharedConfigFile string + ClientEndpoint *string + ExpectURL *string + }{ + "env ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3outposts + +[services testing-s3outposts] +s3outposts = + endpoint_url = http://config-s3outposts.dev +`, + ExpectURL: nil, + }, + "env global": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("https://env-global.dev"), + }, + "env service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3outposts + +[services testing-s3outposts] +s3outposts = + endpoint_url = http://config-s3outposts.dev +`, + ExpectURL: aws.String("https://env-s3outposts.dev"), + }, + "config ignore": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3outposts +ignore_configured_endpoint_urls = true + +[services testing-s3outposts] +s3outposts = + endpoint_url = http://config-s3outposts.dev +`, + ExpectURL: nil, + }, + "config global": { + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +`, + ExpectURL: aws.String("http://config-global.dev"), + }, + "config service": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3outposts + +[services testing-s3outposts] +s3outposts = + endpoint_url = http://config-s3outposts.dev +`, + ExpectURL: aws.String("http://config-s3outposts.dev"), + }, + "client": { + Env: map[string]string{ + "AWS_ENDPOINT_URL": "https://env-global.dev", + "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", + }, + SharedConfigFile: `[profile dev] +endpoint_url = http://config-global.dev +services = testing-s3outposts + +[services testing-s3outposts] +s3outposts = + endpoint_url = http://config-s3outposts.dev +`, + ClientEndpoint: aws.String("https://client-s3outposts.dev"), + ExpectURL: aws.String("https://client-s3outposts.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + for k, v := range c.Env { + t.Setenv(k, v) + } + + tmpDir := t.TempDir() + os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + + awsConfig, err := config.LoadDefaultConfig( + context.TODO(), + config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), + config.WithSharedConfigProfile("dev"), + ) + if err != nil { + t.Fatalf("error loading default config: %v", err) + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.ClientEndpoint != nil { + o.BaseEndpoint = c.ClientEndpoint + } + }) + + if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/s3outposts/generated.json b/service/s3outposts/generated.json index d1a97387238..ffd2c6287f5 100644 --- a/service/s3outposts/generated.json +++ b/service/s3outposts/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", From 57cff74f4080b8972ee75ed3274e52dc98f68391 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:05:37 -0700 Subject: [PATCH 02/26] go mod tidy eventbridge, elasticbeanstalk --- service/elasticbeanstalk/go.mod | 2 ++ service/elasticbeanstalk/go.sum | 18 ++++++++++++++++++ service/eventbridge/go.mod | 2 ++ service/eventbridge/go.sum | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index bc8d95e9a65..e91a7b3e44f 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -4,7 +4,9 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 + github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 diff --git a/service/elasticbeanstalk/go.sum b/service/elasticbeanstalk/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/elasticbeanstalk/go.sum +++ b/service/elasticbeanstalk/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/eventbridge/go.mod b/service/eventbridge/go.mod index 449fdddb021..b6cac8c03b3 100644 --- a/service/eventbridge/go.mod +++ b/service/eventbridge/go.mod @@ -4,7 +4,9 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 + github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 github.com/aws/smithy-go v1.15.0 diff --git a/service/eventbridge/go.sum b/service/eventbridge/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/eventbridge/go.sum +++ b/service/eventbridge/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From 1654ee7e6b960413c4307347aec2f6bdfad03ec1 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:14:54 -0700 Subject: [PATCH 03/26] go mod tidy on s3control,s3outposts --- service/s3control/go.mod | 2 ++ service/s3control/go.sum | 18 ++++++++++++++++++ service/s3outposts/go.mod | 2 ++ service/s3outposts/go.sum | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/service/s3control/go.mod b/service/s3control/go.mod index dc62628adc0..7dcca81e92e 100644 --- a/service/s3control/go.mod +++ b/service/s3control/go.mod @@ -4,7 +4,9 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 + github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 github.com/aws/smithy-go v1.15.0 diff --git a/service/s3control/go.sum b/service/s3control/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/s3control/go.sum +++ b/service/s3control/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/s3outposts/go.mod b/service/s3outposts/go.mod index d4927b19798..c6e19fc4f6b 100644 --- a/service/s3outposts/go.mod +++ b/service/s3outposts/go.mod @@ -4,7 +4,9 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 + github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 diff --git a/service/s3outposts/go.sum b/service/s3outposts/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/s3outposts/go.sum +++ b/service/s3outposts/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From 356b584db006506bca74a0601bf7efc2ec65c3c5 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:23:21 -0700 Subject: [PATCH 04/26] go mod tidy this example s3 module --- example/service/s3/listObjects/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/service/s3/listObjects/go.sum b/example/service/s3/listObjects/go.sum index a646f1d3099..bd5e12334b7 100644 --- a/example/service/s3/listObjects/go.sum +++ b/example/service/s3/listObjects/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From eeddfe765bc34e128811b396aafc5f6a788dfa38 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:27:46 -0700 Subject: [PATCH 05/26] go mod tidy again for other go mod --- example/service/s3/usingPrivateLink/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/service/s3/usingPrivateLink/go.sum b/example/service/s3/usingPrivateLink/go.sum index a646f1d3099..bd5e12334b7 100644 --- a/example/service/s3/usingPrivateLink/go.sum +++ b/example/service/s3/usingPrivateLink/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From 6789aec8b8e08e11f698790a53cf5b7680f12188 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:31:52 -0700 Subject: [PATCH 06/26] go mod tidy s3 manager --- feature/s3/manager/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/s3/manager/go.sum b/feature/s3/manager/go.sum index ef5982af332..9ffbde23b19 100644 --- a/feature/s3/manager/go.sum +++ b/feature/s3/manager/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= From 94cc70ae1e352de7289b594aae430d8d8b84a184 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:45:48 -0700 Subject: [PATCH 07/26] go mod tidy service/internal/integrationtest --- service/internal/integrationtest/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/internal/integrationtest/go.sum b/service/internal/integrationtest/go.sum index ef5982af332..9ffbde23b19 100644 --- a/service/internal/integrationtest/go.sum +++ b/service/internal/integrationtest/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= From c136cb71282c2ff53e14c4d9fae5d4100fc6146d Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 12:53:43 -0700 Subject: [PATCH 08/26] change comment --- internal/endpoints/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/endpoints/config/config.go b/internal/endpoints/config/config.go index 24b80f8ec20..49c21a0cb42 100644 --- a/internal/endpoints/config/config.go +++ b/internal/endpoints/config/config.go @@ -6,13 +6,13 @@ import ( ) // ServiceBaseEndpointProvider is needed to search for all providers -// that provide a configured service endpoint. +// that provide a configured service endpoint type ServiceBaseEndpointProvider interface { GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) } // ResolveServiceBaseEndpoint is used to retrieve service endpoints from configured sources -// while allowing for configured endpoints to be disabled. +// while allowing for configured endpoints to be disabled func ResolveServiceBaseEndpoint(ctx context.Context, sdkID string, configs []config.Config) (value string, found bool, err error) { if val, found, _ := config.GetIgnoreConfiguredEndpoints(ctx, configs); found && val { return "", false, nil From a9c102cc06a8fcb9af7239acf1da60ca7e89168a Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 13:01:57 -0700 Subject: [PATCH 09/26] change example url --- config/shared_config_test.go | 2 +- config/testdata/shared_config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/shared_config_test.go b/config/shared_config_test.go index 128bc6dac7b..0c935cd366d 100644 --- a/config/shared_config_test.go +++ b/config/shared_config_test.go @@ -657,7 +657,7 @@ func TestNewSharedConfig(t *testing.T) { Profile: "endpoint_config", Expected: SharedConfig{ Profile: "endpoint_config", - BaseEndpoint: "http://localhost:5567", + BaseEndpoint: "https://example.com", IgnoreConfiguredEndpoints: ptr.Bool(true), }, }} diff --git a/config/testdata/shared_config b/config/testdata/shared_config index 4c50293faaa..0260b7139e9 100644 --- a/config/testdata/shared_config +++ b/config/testdata/shared_config @@ -281,4 +281,4 @@ sdk_ua_app_id = 12345 [profile endpoint_config] ignore_configured_endpoint_urls = true -endpoint_url = http://localhost:5567 +endpoint_url = https://example.com From ccd15bc2c5fc38674e3671580215cdd799432515 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 13:40:53 -0700 Subject: [PATCH 10/26] change urls --- config/env_config_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/env_config_test.go b/config/env_config_test.go index efb85e91c64..988f31a017f 100644 --- a/config/env_config_test.go +++ b/config/env_config_test.go @@ -425,10 +425,10 @@ func TestNewEnvConfig(t *testing.T) { }, 38: { Env: map[string]string{ - "AWS_ENDPOINT_URL": "http://localhost:5567", + "AWS_ENDPOINT_URL": "https://example.com", }, Config: EnvConfig{ - BaseEndpoint: "http://localhost:5567", + BaseEndpoint: "https://example.com", }, }, 39: { From 0d6e3115d5752e9604bb92d9a3e3b6eca12b121d Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 13:54:48 -0700 Subject: [PATCH 11/26] update go.yml --- .github/workflows/go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1b377bdf1b4..388ab769b32 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go-version: [1.19, "1.20"] + go-version: [1.20, 1.21] steps: - uses: actions/checkout@v2 @@ -48,7 +48,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go-version: [1.15, 1.16, 1.17, 1.18] + go-version: [1.15, 1.16, 1.17, 1.18, 1.19] exclude: - os: macos-latest go-version: 1.15 @@ -76,7 +76,7 @@ jobs: strategy: matrix: os: [windows-latest] - go-version: [1.19, "1.20"] + go-version: [1.20, 1.21] env: EACHMODULE_SKIP: "internal\\repotools\\changes" steps: @@ -103,7 +103,7 @@ jobs: strategy: matrix: os: [windows-latest] - go-version: [1.15, 1.16, 1.17, 1.18] + go-version: [1.15, 1.16, 1.17, 1.18, 1.19] env: EACHMODULE_SKIP: "internal\\repotools\\changes" steps: From 3312cb06e4b2b9de08e51652c8d08cf4f34ecab1 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 13:58:53 -0700 Subject: [PATCH 12/26] update go.yml --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 388ab769b32..f1e3ab5c56b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go-version: [1.20, 1.21] + go-version: ["1.20", "1.21"] steps: - uses: actions/checkout@v2 @@ -76,7 +76,7 @@ jobs: strategy: matrix: os: [windows-latest] - go-version: [1.20, 1.21] + go-version: ["1.20", "1.21"] env: EACHMODULE_SKIP: "internal\\repotools\\changes" steps: From 7df8021dbec5fc8ad09233d42f8f5e52ca5bfd01 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Tue, 24 Oct 2023 14:28:59 -0700 Subject: [PATCH 13/26] tidy all modules --- service/internal/benchmark/go.sum | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/service/internal/benchmark/go.sum b/service/internal/benchmark/go.sum index d1bbdd35922..ec67dff9504 100644 --- a/service/internal/benchmark/go.sum +++ b/service/internal/benchmark/go.sum @@ -1,5 +1,21 @@ github.com/aws/aws-sdk-go v1.44.28 h1:h/OAqEqY18wq//v6h4GNPMmCkxuzSDrWuGyrvSiRqf4= github.com/aws/aws-sdk-go v1.44.28/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= From d907beafb7a1bfe9aa10c3a5b7f66c357f0e4f17 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 19:22:14 -0700 Subject: [PATCH 14/26] add replace statements to service go mods --- service/elasticbeanstalk/go.mod | 4 ++++ service/eventbridge/go.mod | 4 ++++ service/s3/go.mod | 4 ++++ service/s3control/go.mod | 4 ++++ service/s3outposts/go.mod | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index e91a7b3e44f..5d67cad41fe 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -15,6 +15,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/eventbridge/go.mod b/service/eventbridge/go.mod index b6cac8c03b3..f9db8aaf841 100644 --- a/service/eventbridge/go.mod +++ b/service/eventbridge/go.mod @@ -15,6 +15,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/s3/go.mod b/service/s3/go.mod index bdcaef722bc..09ea75e6e3d 100644 --- a/service/s3/go.mod +++ b/service/s3/go.mod @@ -20,6 +20,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ diff --git a/service/s3control/go.mod b/service/s3control/go.mod index 7dcca81e92e..abf19814ef3 100644 --- a/service/s3control/go.mod +++ b/service/s3control/go.mod @@ -15,6 +15,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ diff --git a/service/s3outposts/go.mod b/service/s3outposts/go.mod index c6e19fc4f6b..a430bd3c147 100644 --- a/service/s3outposts/go.mod +++ b/service/s3outposts/go.mod @@ -14,6 +14,10 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ From cb3504bc967aa3775af7d4db6c4cb23c619e20c4 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 19:27:58 -0700 Subject: [PATCH 15/26] add clearenv --- .../smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java | 2 ++ config/env_config.go | 2 +- service/elasticbeanstalk/endpoints_config_test.go | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java index f54516a9cf9..dc07b6ebcfc 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -178,6 +178,7 @@ private GoWriter.Writable generateTests() { """ for name, c := range cases { t.Run(name, func(t $testing:P) { + $clearEnv:T() for k, v := range c.Env { t.Setenv(k, v) } @@ -208,6 +209,7 @@ private GoWriter.Writable generateTests() { """, this.commonCodegenArgs, MapUtils.of( + "clearEnv", SymbolUtils.createValueSymbolBuilder("Clearenv", SmithyGoDependency.OS).build(), "writeFile", SymbolUtils.createValueSymbolBuilder("WriteFile", SmithyGoDependency.OS).build(), "joinFile", SymbolUtils.createValueSymbolBuilder("Join", SmithyGoDependency.PATH_FILEPATH).build(), "fileMode", SymbolUtils.createValueSymbolBuilder("FileMode", SmithyGoDependency.OS).build(), diff --git a/config/env_config.go b/config/env_config.go index 4a3e00be6fe..38d7ef72bac 100644 --- a/config/env_config.go +++ b/config/env_config.go @@ -254,7 +254,7 @@ type EnvConfig struct { RetryMode aws.RetryMode // aws sdk app ID that can be added to user agent header string - AppID string + AppID string // Flag used to disable configured endpoints. IgnoreConfiguredEndpoints *bool diff --git a/service/elasticbeanstalk/endpoints_config_test.go b/service/elasticbeanstalk/endpoints_config_test.go index 3a4c29251f4..e5d171638e9 100644 --- a/service/elasticbeanstalk/endpoints_config_test.go +++ b/service/elasticbeanstalk/endpoints_config_test.go @@ -116,6 +116,7 @@ elastic_beanstalk = for name, c := range cases { t.Run(name, func(t *testing.T) { + os.Clearenv() for k, v := range c.Env { t.Setenv(k, v) } From 4105cd25a811a144b20840152906124e5617e445 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 19:28:45 -0700 Subject: [PATCH 16/26] regen s3 --- service/s3/endpoints_config_test.go | 1 + service/s3control/endpoints_config_test.go | 1 + service/s3outposts/endpoints_config_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/service/s3/endpoints_config_test.go b/service/s3/endpoints_config_test.go index eab499b5bf0..ca7c6b1c058 100644 --- a/service/s3/endpoints_config_test.go +++ b/service/s3/endpoints_config_test.go @@ -116,6 +116,7 @@ s3 = for name, c := range cases { t.Run(name, func(t *testing.T) { + os.Clearenv() for k, v := range c.Env { t.Setenv(k, v) } diff --git a/service/s3control/endpoints_config_test.go b/service/s3control/endpoints_config_test.go index e4621b4c326..f9ecbebb7d3 100644 --- a/service/s3control/endpoints_config_test.go +++ b/service/s3control/endpoints_config_test.go @@ -116,6 +116,7 @@ s3_control = for name, c := range cases { t.Run(name, func(t *testing.T) { + os.Clearenv() for k, v := range c.Env { t.Setenv(k, v) } diff --git a/service/s3outposts/endpoints_config_test.go b/service/s3outposts/endpoints_config_test.go index 3200b67921f..9f25c73a9bd 100644 --- a/service/s3outposts/endpoints_config_test.go +++ b/service/s3outposts/endpoints_config_test.go @@ -116,6 +116,7 @@ s3outposts = for name, c := range cases { t.Run(name, func(t *testing.T) { + os.Clearenv() for k, v := range c.Env { t.Setenv(k, v) } From 9b5268ae1da5e40202352ebdc6fe3186cf6f7e0b Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 19:29:38 -0700 Subject: [PATCH 17/26] regen eventbridge --- service/eventbridge/endpoints_config_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/eventbridge/endpoints_config_test.go b/service/eventbridge/endpoints_config_test.go index e10887fa3f0..476b53fff36 100644 --- a/service/eventbridge/endpoints_config_test.go +++ b/service/eventbridge/endpoints_config_test.go @@ -116,6 +116,7 @@ eventbridge = for name, c := range cases { t.Run(name, func(t *testing.T) { + os.Clearenv() for k, v := range c.Env { t.Setenv(k, v) } From ed18944944e6286b39f9dfd02be67ff38a406b9c Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 20:23:38 -0700 Subject: [PATCH 18/26] remove whitespace --- .../go/codegen/AwsEndpointConfigTestGenerator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java index dc07b6ebcfc..c402d3a433d 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -40,7 +40,7 @@ public void writeAdditionalFiles( "testing", SymbolUtils.createPointableSymbolBuilder("T", SmithyGoDependency.TESTING).build(), "awsString", SymbolUtils.createValueSymbolBuilder("String", AwsGoDependency.AWS_CORE).build() ); - + writerFactory.accept("endpoints_config_test.go", settings.getModuleName(), writer -> { writer.write("$W", generate()); }); @@ -85,7 +85,7 @@ private GoWriter.Writable generateCases() { services = testing-$urlSdkId:L [services testing-$urlSdkId:L] -$configSdkId:L = +$configSdkId:L = endpoint_url = http://config-$urlSdkId:L.dev `, ExpectURL: nil, @@ -109,7 +109,7 @@ private GoWriter.Writable generateCases() { services = testing-$urlSdkId:L [services testing-$urlSdkId:L] -$configSdkId:L = +$configSdkId:L = endpoint_url = http://config-$urlSdkId:L.dev `, ExpectURL: $awsString:T("https://env-$urlSdkId:L.dev"), @@ -125,7 +125,7 @@ private GoWriter.Writable generateCases() { ignore_configured_endpoint_urls = true [services testing-$urlSdkId:L] -$configSdkId:L = +$configSdkId:L = endpoint_url = http://config-$urlSdkId:L.dev `, ExpectURL: nil, @@ -194,13 +194,13 @@ private GoWriter.Writable generateTests() { if err != nil { t.Fatalf("error loading default config: %v", err) } - + client := NewFromConfig(awsConfig, func (o *Options) { if c.ClientEndpoint != nil { o.BaseEndpoint = c.ClientEndpoint } }) - + if e, a := c.ExpectURL, client.options.BaseEndpoint; !$deepEqual:T(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } From 8a7b39fbe4d111fbfc4114ac91d2ab3a526ec102 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Wed, 25 Oct 2023 20:26:50 -0700 Subject: [PATCH 19/26] remove whitespace --- .../smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java index c402d3a433d..0591193cb51 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -145,7 +145,7 @@ private GoWriter.Writable generateCases() { services = testing-$urlSdkId:L [services testing-$urlSdkId:L] -$configSdkId:L = +$configSdkId:L = endpoint_url = http://config-$urlSdkId:L.dev `, ExpectURL: $awsString:T("http://config-$urlSdkId:L.dev"), @@ -161,7 +161,7 @@ private GoWriter.Writable generateCases() { services = testing-$urlSdkId:L [services testing-$urlSdkId:L] -$configSdkId:L = +$configSdkId:L = endpoint_url = http://config-$urlSdkId:L.dev `, ClientEndpoint: $awsString:T("https://client-$urlSdkId:L.dev"), From 09644f67895225ce6d199bb6728aaa0db29320c8 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 08:12:00 -0700 Subject: [PATCH 20/26] fixed bug --- ...sEndpointResolverInitializerGenerator.java | 29 ++- config/provider.go | 2 +- config/resolve.go | 7 +- internal/endpoints/config/config.go | 2 +- service/elasticbeanstalk/endpoints.go | 16 +- .../elasticbeanstalk/endpoints_config_test.go | 189 ++++++++---------- 6 files changed, 117 insertions(+), 128 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java index 09b9b932a5e..5201810cdaa 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java @@ -21,12 +21,17 @@ import java.util.List; import java.util.function.Consumer; +import java.util.Map; + public class AwsEndpointResolverInitializerGenerator implements GoIntegration { public static final String RESOLVE_ENDPOINT_RESOLVER_V2 = "resolve" + EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME; public static final String RESOLVE_BASE_ENDPOINT = "resolveBaseEndpoint"; + private Map commonCodegenArgs; + + @Override public void writeAdditionalFiles( GoSettings settings, @@ -34,6 +39,14 @@ public void writeAdditionalFiles( SymbolProvider symbolProvider, TriConsumer> writerFactory ) { + String sdkId = settings.getService(model).expectTrait(ServiceTrait.class).getSdkId(); + this.commonCodegenArgs = MapUtils.of( + "envSdkId", sdkId.toUpperCase().replaceAll(" ", "_"), + "configSdkId", sdkId.toLowerCase().replaceAll(" ", "_"), + "urlSdkId", sdkId.toLowerCase().replaceAll(" ", "-"), + "testing", SymbolUtils.createPointableSymbolBuilder("T", SmithyGoDependency.TESTING).build(), + "awsString", SymbolUtils.createValueSymbolBuilder("String", AwsGoDependency.AWS_CORE).build() + ); writerFactory.accept("endpoints.go", settings.getModuleName(), writer -> { writer.write( @@ -58,13 +71,11 @@ private GoWriter.Writable generateConfigResolverMethod(String sdkId) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []$config:T - for _, c := range cfg.ConfigSources { - if cs, ok := c.($config:T); ok { - configSources = append(configSources, cs) - } - } - value, found, err := $resolveServiceEndpoint:T(context.Background(), "$sdkId:L", configSources) + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_$envSdkId:L") + + value, found, err := $resolveServiceEndpoint:T(context.Background(), "$sdkId:L", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } @@ -73,11 +84,11 @@ private GoWriter.Writable generateConfigResolverMethod(String sdkId) { MapUtils.of( "resolveMethodName", RESOLVE_BASE_ENDPOINT, "awsConfig", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.AWS_CORE).build(), - "config", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.CONFIG).build(), "resolveServiceEndpoint", SymbolUtils.createValueSymbolBuilder( "ResolveServiceBaseEndpoint", AwsGoDependency.INTERNAL_ENDPOINTS_CONFIG).build(), "sdkId", sdkId - ) + ), + this.commonCodegenArgs ); } diff --git a/config/provider.go b/config/provider.go index c77bc784f6a..d5235846011 100644 --- a/config/provider.go +++ b/config/provider.go @@ -130,7 +130,7 @@ type IgnoreConfiguredEndpointsProvider interface { // GetIgnoreConfiguredEndpoints is used in knowing when to disable configured // endpoints feature. -func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []Config) (value bool, found bool, err error) { +func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []interface{}) (value bool, found bool, err error) { for _, cfg := range configs { if p, ok := cfg.(IgnoreConfiguredEndpointsProvider); ok { value, found, err = p.GetIgnoreConfiguredEndpoints(ctx) diff --git a/config/resolve.go b/config/resolve.go index 3c087265ae8..b5a74b23197 100644 --- a/config/resolve.go +++ b/config/resolve.go @@ -107,7 +107,12 @@ func resolveRegion(ctx context.Context, cfg *aws.Config, configs configs) error } func resolveBaseEndpoint(ctx context.Context, cfg *aws.Config, configs configs) error { - if val, found, err := GetIgnoreConfiguredEndpoints(ctx, configs); found && val && err == nil { + var downcastCfgSources []interface{} + for _, cs := range configs { + downcastCfgSources = append(downcastCfgSources, interface{}(cs)) + } + + if val, found, err := GetIgnoreConfiguredEndpoints(ctx, downcastCfgSources); found && val && err == nil { cfg.BaseEndpoint = nil return nil } diff --git a/internal/endpoints/config/config.go b/internal/endpoints/config/config.go index 49c21a0cb42..012ac6c07ab 100644 --- a/internal/endpoints/config/config.go +++ b/internal/endpoints/config/config.go @@ -13,7 +13,7 @@ type ServiceBaseEndpointProvider interface { // ResolveServiceBaseEndpoint is used to retrieve service endpoints from configured sources // while allowing for configured endpoints to be disabled -func ResolveServiceBaseEndpoint(ctx context.Context, sdkID string, configs []config.Config) (value string, found bool, err error) { +func ResolveServiceBaseEndpoint(ctx context.Context, sdkID string, configs []interface{}) (value string, found bool, err error) { if val, found, _ := config.GetIgnoreConfiguredEndpoints(ctx, configs); found && val { return "", false, nil } diff --git a/service/elasticbeanstalk/endpoints.go b/service/elasticbeanstalk/endpoints.go index 7ca9738595d..21fc5d62b51 100644 --- a/service/elasticbeanstalk/endpoints.go +++ b/service/elasticbeanstalk/endpoints.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk/internal/endpoints" @@ -19,6 +18,7 @@ import ( "net/http" "net/url" "strings" + "os" ) // EndpointResolverOptions is the service endpoint resolver options @@ -200,13 +200,15 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []config.Config - for _, c := range cfg.ConfigSources { - if cs, ok := c.(config.Config); ok { - configSources = append(configSources, cs) - } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_BEANSTALK") + + if g && !s { + return } - value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Beanstalk", configSources) + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Beanstalk", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } diff --git a/service/elasticbeanstalk/endpoints_config_test.go b/service/elasticbeanstalk/endpoints_config_test.go index e5d171638e9..540a2bd5ec1 100644 --- a/service/elasticbeanstalk/endpoints_config_test.go +++ b/service/elasticbeanstalk/endpoints_config_test.go @@ -5,141 +5,112 @@ package elasticbeanstalk import ( "context" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" - "os" - "path/filepath" "reflect" "testing" + "os" ) -func TestConfiguredEndpoints(t *testing.T) { +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + + +func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-elastic-beanstalk - -[services testing-elastic-beanstalk] -elastic_beanstalk = - endpoint_url = http://config-elastic-beanstalk.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-elastic-beanstalk - -[services testing-elastic-beanstalk] -elastic_beanstalk = - endpoint_url = http://config-elastic-beanstalk.dev -`, - ExpectURL: aws.String("https://env-elastic-beanstalk.dev"), - }, - "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-elastic-beanstalk -ignore_configured_endpoint_urls = true - -[services testing-elastic-beanstalk] -elastic_beanstalk = - endpoint_url = http://config-elastic-beanstalk.dev -`, - ExpectURL: nil, - }, - "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("http://config-global.dev"), - }, - "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-elastic-beanstalk - -[services testing-elastic-beanstalk] -elastic_beanstalk = - endpoint_url = http://config-elastic-beanstalk.dev -`, - ExpectURL: aws.String("http://config-elastic-beanstalk.dev"), - }, - "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_ELASTIC_BEANSTALK": "https://env-elastic-beanstalk.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-elastic-beanstalk - -[services testing-elastic-beanstalk] -elastic_beanstalk = - endpoint_url = http://config-elastic-beanstalk.dev -`, - ClientEndpoint: aws.String("https://client-elastic-beanstalk.dev"), - ExpectURL: aws.String("https://client-elastic-beanstalk.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + expectURL: aws.String("https://env-elastic-beanstalk.dev"), }, } for name, c := range cases { t.Run(name, func(t *testing.T) { os.Clearenv() - for k, v := range c.Env { - t.Setenv(k, v) + + awsConfig := aws.Config{} + + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) } - tmpDir := t.TempDir() - os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } - awsConfig, err := config.LoadDefaultConfig( - context.TODO(), - config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), - config.WithSharedConfigProfile("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTIC_BEANSTALK", c.envService) } + cfgSources := []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + awsConfig.ConfigSources = cfgSources + client := NewFromConfig(awsConfig, func(o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) From c56df063f4d0c6959f919cb651c59c891cdf11d7 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 08:40:00 -0700 Subject: [PATCH 21/26] env passes codegen --- .../AwsEndpointConfigTestGenerator.java | 222 ++++++++---------- ...sEndpointResolverInitializerGenerator.java | 10 +- service/elasticbeanstalk/endpoints.go | 4 +- .../elasticbeanstalk/endpoints_config_test.go | 60 +++-- service/elasticbeanstalk/go.mod | 22 +- 5 files changed, 147 insertions(+), 171 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java index 0591193cb51..fe1e9524ee0 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -38,7 +38,8 @@ public void writeAdditionalFiles( "configSdkId", sdkId.toLowerCase().replaceAll(" ", "_"), "urlSdkId", sdkId.toLowerCase().replaceAll(" ", "-"), "testing", SymbolUtils.createPointableSymbolBuilder("T", SmithyGoDependency.TESTING).build(), - "awsString", SymbolUtils.createValueSymbolBuilder("String", AwsGoDependency.AWS_CORE).build() + "awsString", SymbolUtils.createValueSymbolBuilder("String", AwsGoDependency.AWS_CORE).build(), + "context", SymbolUtils.createValueSymbolBuilder("Context", SmithyGoDependency.CONTEXT).build() ); writerFactory.accept("endpoints_config_test.go", settings.getModuleName(), writer -> { @@ -47,12 +48,55 @@ public void writeAdditionalFiles( } - private GoWriter.Writable generate() { return (GoWriter w) -> { w.write( """ - func TestConfiguredEndpoints(t $P) { + $W + + $W + """, + generateMockProviders(), + generateTestFunction() + ); + }; + } + + private GoWriter.Writable generateMockProviders() { + return goTemplate( + """ + type mockConfigSource struct { + global string + service string + ignore bool + } + + // GetIgnoreConfiguredEndpoints is used in knowing when to disable configured + // endpoints feature. + func (m mockConfigSource) GetIgnoreConfiguredEndpoints($context:T) (bool, bool, error) { + return m.ignore, m.ignore, nil + } + + // GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use + // with configured endpoints. + func (m mockConfigSource) GetServiceBaseEndpoint(ctx $context:T, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil + } + + """, + this.commonCodegenArgs + ); + } + + + private GoWriter.Writable generateTestFunction() { + return (GoWriter w) -> { + w.write( + """ + func TestResolveBaseEndpoint(t $P) { $W $W @@ -69,103 +113,35 @@ private GoWriter.Writable generateCases() { return goTemplate( """ cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-$urlSdkId:L - -[services testing-$urlSdkId:L] -$configSdkId:L = - endpoint_url = http://config-$urlSdkId:L.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-$urlSdkId:L.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: $awsString:T("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-$urlSdkId:L - -[services testing-$urlSdkId:L] -$configSdkId:L = - endpoint_url = http://config-$urlSdkId:L.dev -`, - ExpectURL: $awsString:T("https://env-$urlSdkId:L.dev"), - }, - "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-$urlSdkId:L -ignore_configured_endpoint_urls = true - -[services testing-$urlSdkId:L] -$configSdkId:L = - endpoint_url = http://config-$urlSdkId:L.dev -`, - ExpectURL: nil, - }, - "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: $awsString:T("http://config-global.dev"), - }, - "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-$urlSdkId:L - -[services testing-$urlSdkId:L] -$configSdkId:L = - endpoint_url = http://config-$urlSdkId:L.dev -`, - ExpectURL: $awsString:T("http://config-$urlSdkId:L.dev"), - }, - "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_$envSdkId:L": "https://env-$urlSdkId:L.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-$urlSdkId:L - -[services testing-$urlSdkId:L] -$configSdkId:L = - endpoint_url = http://config-$urlSdkId:L.dev -`, - ClientEndpoint: $awsString:T("https://client-$urlSdkId:L.dev"), - ExpectURL: $awsString:T("https://client-$urlSdkId:L.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-$urlSdkId:L.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + expectURL: aws.String("https://env-$urlSdkId:L.dev"), }, } """, @@ -179,29 +155,45 @@ private GoWriter.Writable generateTests() { for name, c := range cases { t.Run(name, func(t $testing:P) { $clearEnv:T() - for k, v := range c.Env { - t.Setenv(k, v) - } - tmpDir := t.TempDir() - $writeFile:T($joinFile:T(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), $fileMode:T(int(0777))) - - awsConfig, err := $loadDefaultConfig:T( - $contextTodo:T(), - $withSharedConfig:T([]string{$joinFile:T(tmpDir, "test_shared_config")}), - $withSharedConfigProfile:T("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + awsConfig := $awsConfig:T{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = $awsString:T(c.configGlobal) } - + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = $awsString:T(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_$envSdkId:L", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + client := NewFromConfig(awsConfig, func (o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !$deepEqual:T(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !$deepEqual:T(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) @@ -210,13 +202,7 @@ private GoWriter.Writable generateTests() { this.commonCodegenArgs, MapUtils.of( "clearEnv", SymbolUtils.createValueSymbolBuilder("Clearenv", SmithyGoDependency.OS).build(), - "writeFile", SymbolUtils.createValueSymbolBuilder("WriteFile", SmithyGoDependency.OS).build(), - "joinFile", SymbolUtils.createValueSymbolBuilder("Join", SmithyGoDependency.PATH_FILEPATH).build(), - "fileMode", SymbolUtils.createValueSymbolBuilder("FileMode", SmithyGoDependency.OS).build(), - "loadDefaultConfig", SymbolUtils.createValueSymbolBuilder("LoadDefaultConfig", AwsGoDependency.CONFIG).build(), - "contextTodo", SymbolUtils.createValueSymbolBuilder("TODO", SmithyGoDependency.CONTEXT).build(), - "withSharedConfig", SymbolUtils.createValueSymbolBuilder("WithSharedConfigFiles", AwsGoDependency.CONFIG).build(), - "withSharedConfigProfile", SymbolUtils.createValueSymbolBuilder("WithSharedConfigProfile", AwsGoDependency.CONFIG).build(), + "awsConfig", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.AWS_CORE).build(), "deepEqual", SymbolUtils.createValueSymbolBuilder("DeepEqual", SmithyGoDependency.REFLECT).build() ) ); diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java index 5201810cdaa..d43295bc6e6 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java @@ -7,6 +7,7 @@ import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.go.codegen.GoSettings; import software.amazon.smithy.go.codegen.GoWriter; +import software.amazon.smithy.go.codegen.SmithyGoDependency; import software.amazon.smithy.go.codegen.SymbolUtils; import software.amazon.smithy.go.codegen.TriConsumer; import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator; @@ -72,8 +73,12 @@ private GoWriter.Writable generateConfigResolverMethod(String sdkId) { o.BaseEndpoint = cfg.BaseEndpoint } - _, g := os.LookupEnv("AWS_ENDPOINT_URL") - _, s := os.LookupEnv("AWS_ENDPOINT_URL_$envSdkId:L") + _, g := $lookupEnv:T("AWS_ENDPOINT_URL") + _, s := $lookupEnv:T("AWS_ENDPOINT_URL_$envSdkId:L") + + if g && !s { + return + } value, found, err := $resolveServiceEndpoint:T(context.Background(), "$sdkId:L", cfg.ConfigSources) if found && err == nil { @@ -84,6 +89,7 @@ private GoWriter.Writable generateConfigResolverMethod(String sdkId) { MapUtils.of( "resolveMethodName", RESOLVE_BASE_ENDPOINT, "awsConfig", SymbolUtils.createValueSymbolBuilder("Config", AwsGoDependency.AWS_CORE).build(), + "lookupEnv", SymbolUtils.createValueSymbolBuilder("LookupEnv", SmithyGoDependency.OS).build(), "resolveServiceEndpoint", SymbolUtils.createValueSymbolBuilder( "ResolveServiceBaseEndpoint", AwsGoDependency.INTERNAL_ENDPOINTS_CONFIG).build(), "sdkId", sdkId diff --git a/service/elasticbeanstalk/endpoints.go b/service/elasticbeanstalk/endpoints.go index 21fc5d62b51..103f81beae5 100644 --- a/service/elasticbeanstalk/endpoints.go +++ b/service/elasticbeanstalk/endpoints.go @@ -17,8 +17,8 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" - "strings" "os" + "strings" ) // EndpointResolverOptions is the service endpoint resolver options @@ -204,7 +204,7 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { _, g := os.LookupEnv("AWS_ENDPOINT_URL") _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_BEANSTALK") - if g && !s { + if g && !s { return } diff --git a/service/elasticbeanstalk/endpoints_config_test.go b/service/elasticbeanstalk/endpoints_config_test.go index 540a2bd5ec1..521a6171fc8 100644 --- a/service/elasticbeanstalk/endpoints_config_test.go +++ b/service/elasticbeanstalk/endpoints_config_test.go @@ -5,15 +5,15 @@ package elasticbeanstalk import ( "context" "github.com/aws/aws-sdk-go-v2/aws" + "os" "reflect" "testing" - "os" ) type mockConfigSource struct { - global string + global string service string - ignore bool + ignore bool } // GetIgnoreConfiguredEndpoints is used in knowing when to disable configured @@ -31,38 +31,37 @@ func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID stri return "", false, nil } - func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - envGlobal string - envService string - envIgnore bool - configGlobal string - configService string - configIgnore bool - clientEndpoint *string - expectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - envGlobal: "https://env-global.dev", - envService: "https://env-elastic-beanstalk.dev", - envIgnore: true, - configGlobal: "http://config-global.dev", + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", configService: "http://config-elastic-beanstalk.dev", - expectURL: nil, + expectURL: nil, }, "env global": { - envGlobal: "https://env-global.dev", - configGlobal: "http://config-global.dev", + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", configService: "http://config-elastic-beanstalk.dev", - expectURL: aws.String("https://env-global.dev"), + expectURL: aws.String("https://env-global.dev"), }, "env service": { - envGlobal: "https://env-global.dev", - envService: "https://env-elastic-beanstalk.dev", - configGlobal: "http://config-global.dev", + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + configGlobal: "http://config-global.dev", configService: "http://config-elastic-beanstalk.dev", - expectURL: aws.String("https://env-elastic-beanstalk.dev"), + expectURL: aws.String("https://env-elastic-beanstalk.dev"), }, } @@ -71,7 +70,6 @@ func TestResolveBaseEndpoint(t *testing.T) { os.Clearenv() awsConfig := aws.Config{} - ignore := c.envIgnore || c.configIgnore if c.configGlobal != "" && !ignore { @@ -89,21 +87,19 @@ func TestResolveBaseEndpoint(t *testing.T) { t.Setenv("AWS_ENDPOINT_URL_ELASTIC_BEANSTALK", c.envService) } - cfgSources := []interface{}{ + awsConfig.ConfigSources = []interface{}{ mockConfigSource{ - global: c.envGlobal, + global: c.envGlobal, service: c.envService, - ignore: c.envIgnore, + ignore: c.envIgnore, }, mockConfigSource{ - global: c.configGlobal, + global: c.configGlobal, service: c.configService, - ignore: c.configIgnore, + ignore: c.configIgnore, }, } - awsConfig.ConfigSources = cfgSources - client := NewFromConfig(awsConfig, func(o *Options) { if c.clientEndpoint != nil { o.BaseEndpoint = c.clientEndpoint diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index 5d67cad41fe..49be880e31e 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -3,22 +3,10 @@ module github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk go 1.15 require ( - github.com/aws/aws-sdk-go-v2 v1.21.2 - github.com/aws/aws-sdk-go-v2/config v1.19.1 - github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 - github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 - github.com/aws/smithy-go v1.15.0 - github.com/google/go-cmp v0.5.8 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 + github.com/aws/smithy-go v1.4.0 + github.com/google/go-cmp v0.5.4 github.com/jmespath/go-jmespath v0.4.0 + github.com/aws/aws-sdk-go-v2 v1.4.0 + github.com/aws/aws-sdk-go-v2/internal/configsources v0.0.0-00010101000000-000000000000 ) - -replace github.com/aws/aws-sdk-go-v2 => ../../ - -replace github.com/aws/aws-sdk-go-v2/config => ../../config - -replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ - -replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ - -replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ From fc35a6b677e5b5ad11d267c64bea8f7b87860944 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 08:49:55 -0700 Subject: [PATCH 22/26] eb all tests pass codegen --- .../AwsEndpointConfigTestGenerator.java | 25 +++++++++++++++++++ .../elasticbeanstalk/endpoints_config_test.go | 25 +++++++++++++++++++ service/elasticbeanstalk/go.mod | 6 ++--- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java index fe1e9524ee0..c0aa30e80f7 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointConfigTestGenerator.java @@ -143,6 +143,31 @@ private GoWriter.Writable generateCases() { configService: "http://config-$urlSdkId:L.dev", expectURL: aws.String("https://env-$urlSdkId:L.dev"), }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-$urlSdkId:L.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + expectURL: aws.String("http://config-$urlSdkId:L.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-$urlSdkId:L.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-$urlSdkId:L.dev", + clientEndpoint: aws.String("https://client-$urlSdkId:L.dev"), + expectURL: aws.String("https://client-$urlSdkId:L.dev"), + }, } """, this.commonCodegenArgs diff --git a/service/elasticbeanstalk/endpoints_config_test.go b/service/elasticbeanstalk/endpoints_config_test.go index 521a6171fc8..f7f1c51e266 100644 --- a/service/elasticbeanstalk/endpoints_config_test.go +++ b/service/elasticbeanstalk/endpoints_config_test.go @@ -63,6 +63,31 @@ func TestResolveBaseEndpoint(t *testing.T) { configService: "http://config-elastic-beanstalk.dev", expectURL: aws.String("https://env-elastic-beanstalk.dev"), }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + expectURL: aws.String("http://config-elastic-beanstalk.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-beanstalk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-beanstalk.dev", + clientEndpoint: aws.String("https://client-elastic-beanstalk.dev"), + expectURL: aws.String("https://client-elastic-beanstalk.dev"), + }, } for name, c := range cases { diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index 49be880e31e..10fe0610e91 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -3,10 +3,10 @@ module github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk go 1.15 require ( - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 - github.com/aws/smithy-go v1.4.0 - github.com/google/go-cmp v0.5.4 github.com/jmespath/go-jmespath v0.4.0 github.com/aws/aws-sdk-go-v2 v1.4.0 github.com/aws/aws-sdk-go-v2/internal/configsources v0.0.0-00010101000000-000000000000 + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 + github.com/aws/smithy-go v1.4.0 + github.com/google/go-cmp v0.5.4 ) From e8053a99bf02f50b348482d08d85fb4136a619b7 Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 10:17:24 -0700 Subject: [PATCH 23/26] regen everything --- config/go.mod | 5 + config/go.sum | 3 + credentials/go.mod | 9 + credentials/go.sum | 7 + example/service/dynamodb/createTable/go.mod | 2 + example/service/dynamodb/createTable/go.sum | 2 + example/service/dynamodb/scanItems/go.mod | 2 + example/service/dynamodb/scanItems/go.sum | 2 + example/service/s3/listObjects/go.mod | 2 + example/service/s3/usingPrivateLink/go.mod | 2 + feature/dynamodb/attributevalue/go.mod | 18 ++ feature/dynamodb/expression/go.mod | 19 ++ feature/dynamodb/expression/go.sum | 18 ++ feature/dynamodbstreams/attributevalue/go.mod | 18 ++ .../ec2/imds/internal/configtesting/go.mod | 2 + .../ec2/imds/internal/configtesting/go.sum | 2 + feature/s3/manager/go.mod | 2 + internal/configsources/configtesting/go.mod | 2 + internal/configsources/configtesting/go.sum | 2 + internal/endpoints/config/go.mod | 2 + internal/endpoints/config/go.sum | 1 + .../protocoltest/awsrestjson/api_client.go | 1 + .../protocoltest/awsrestjson/endpoints.go | 20 ++ .../awsrestjson/endpoints_config_test.go | 139 +++++++++++++ .../protocoltest/awsrestjson/generated.json | 1 + internal/protocoltest/awsrestjson/go.mod | 19 ++ internal/protocoltest/awsrestjson/go.sum | 18 ++ internal/protocoltest/ec2query/api_client.go | 1 + internal/protocoltest/ec2query/endpoints.go | 20 ++ .../ec2query/endpoints_config_test.go | 139 +++++++++++++ internal/protocoltest/ec2query/generated.json | 1 + internal/protocoltest/ec2query/go.mod | 19 ++ internal/protocoltest/ec2query/go.sum | 18 ++ internal/protocoltest/jsonrpc/api_client.go | 1 + internal/protocoltest/jsonrpc/endpoints.go | 20 ++ .../jsonrpc/endpoints_config_test.go | 139 +++++++++++++ internal/protocoltest/jsonrpc/generated.json | 1 + internal/protocoltest/jsonrpc/go.mod | 19 ++ internal/protocoltest/jsonrpc/go.sum | 18 ++ internal/protocoltest/jsonrpc10/api_client.go | 1 + internal/protocoltest/jsonrpc10/endpoints.go | 20 ++ .../jsonrpc10/endpoints_config_test.go | 139 +++++++++++++ .../protocoltest/jsonrpc10/generated.json | 1 + internal/protocoltest/jsonrpc10/go.mod | 19 ++ internal/protocoltest/jsonrpc10/go.sum | 18 ++ internal/protocoltest/query/api_client.go | 1 + internal/protocoltest/query/endpoints.go | 20 ++ .../query/endpoints_config_test.go | 139 +++++++++++++ internal/protocoltest/query/generated.json | 1 + internal/protocoltest/query/go.mod | 19 ++ internal/protocoltest/query/go.sum | 18 ++ internal/protocoltest/restxml/api_client.go | 1 + internal/protocoltest/restxml/endpoints.go | 20 ++ .../restxml/endpoints_config_test.go | 139 +++++++++++++ internal/protocoltest/restxml/generated.json | 1 + internal/protocoltest/restxml/go.mod | 19 ++ internal/protocoltest/restxml/go.sum | 18 ++ .../restxmlwithnamespace/api_client.go | 1 + .../restxmlwithnamespace/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../restxmlwithnamespace/generated.json | 1 + .../protocoltest/restxmlwithnamespace/go.mod | 19 ++ .../protocoltest/restxmlwithnamespace/go.sum | 18 ++ service/accessanalyzer/api_client.go | 1 + service/accessanalyzer/endpoints.go | 20 ++ .../accessanalyzer/endpoints_config_test.go | 139 +++++++++++++ service/accessanalyzer/generated.json | 1 + service/accessanalyzer/go.mod | 19 ++ service/accessanalyzer/go.sum | 18 ++ service/account/api_client.go | 1 + service/account/endpoints.go | 20 ++ service/account/endpoints_config_test.go | 139 +++++++++++++ service/account/generated.json | 1 + service/account/go.mod | 19 ++ service/account/go.sum | 18 ++ service/acm/api_client.go | 1 + service/acm/endpoints.go | 20 ++ service/acm/endpoints_config_test.go | 139 +++++++++++++ service/acm/generated.json | 1 + service/acm/go.mod | 19 ++ service/acm/go.sum | 18 ++ service/acmpca/api_client.go | 1 + service/acmpca/endpoints.go | 20 ++ service/acmpca/endpoints_config_test.go | 139 +++++++++++++ service/acmpca/generated.json | 1 + service/acmpca/go.mod | 19 ++ service/acmpca/go.sum | 18 ++ service/alexaforbusiness/api_client.go | 1 + service/alexaforbusiness/endpoints.go | 20 ++ .../alexaforbusiness/endpoints_config_test.go | 139 +++++++++++++ service/alexaforbusiness/generated.json | 1 + service/alexaforbusiness/go.mod | 19 ++ service/alexaforbusiness/go.sum | 18 ++ service/amp/api_client.go | 1 + service/amp/endpoints.go | 20 ++ service/amp/endpoints_config_test.go | 139 +++++++++++++ service/amp/generated.json | 1 + service/amp/go.mod | 19 ++ service/amp/go.sum | 18 ++ service/amplify/api_client.go | 1 + service/amplify/endpoints.go | 20 ++ service/amplify/endpoints_config_test.go | 139 +++++++++++++ service/amplify/generated.json | 1 + service/amplify/go.mod | 19 ++ service/amplify/go.sum | 18 ++ service/amplifybackend/api_client.go | 1 + service/amplifybackend/endpoints.go | 20 ++ .../amplifybackend/endpoints_config_test.go | 139 +++++++++++++ service/amplifybackend/generated.json | 1 + service/amplifybackend/go.mod | 19 ++ service/amplifybackend/go.sum | 18 ++ service/amplifyuibuilder/api_client.go | 1 + service/amplifyuibuilder/endpoints.go | 20 ++ .../amplifyuibuilder/endpoints_config_test.go | 139 +++++++++++++ service/amplifyuibuilder/generated.json | 1 + service/amplifyuibuilder/go.mod | 19 ++ service/amplifyuibuilder/go.sum | 18 ++ service/apigateway/api_client.go | 1 + service/apigateway/endpoints.go | 20 ++ service/apigateway/endpoints_config_test.go | 139 +++++++++++++ service/apigateway/generated.json | 1 + service/apigateway/go.mod | 19 ++ service/apigateway/go.sum | 18 ++ service/apigatewaymanagementapi/api_client.go | 1 + service/apigatewaymanagementapi/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../apigatewaymanagementapi/generated.json | 1 + service/apigatewaymanagementapi/go.mod | 19 ++ service/apigatewaymanagementapi/go.sum | 18 ++ service/apigatewayv2/api_client.go | 1 + service/apigatewayv2/endpoints.go | 20 ++ service/apigatewayv2/endpoints_config_test.go | 139 +++++++++++++ service/apigatewayv2/generated.json | 1 + service/apigatewayv2/go.mod | 19 ++ service/apigatewayv2/go.sum | 18 ++ service/appconfig/api_client.go | 1 + service/appconfig/endpoints.go | 20 ++ service/appconfig/endpoints_config_test.go | 139 +++++++++++++ service/appconfig/generated.json | 1 + service/appconfig/go.mod | 19 ++ service/appconfig/go.sum | 18 ++ service/appconfigdata/api_client.go | 1 + service/appconfigdata/endpoints.go | 20 ++ .../appconfigdata/endpoints_config_test.go | 139 +++++++++++++ service/appconfigdata/generated.json | 1 + service/appconfigdata/go.mod | 19 ++ service/appconfigdata/go.sum | 18 ++ service/appfabric/api_client.go | 1 + service/appfabric/endpoints.go | 20 ++ service/appfabric/endpoints_config_test.go | 139 +++++++++++++ service/appfabric/generated.json | 1 + service/appfabric/go.mod | 19 ++ service/appfabric/go.sum | 18 ++ service/appflow/api_client.go | 1 + service/appflow/endpoints.go | 20 ++ service/appflow/endpoints_config_test.go | 139 +++++++++++++ service/appflow/generated.json | 1 + service/appflow/go.mod | 19 ++ service/appflow/go.sum | 18 ++ service/appintegrations/api_client.go | 1 + service/appintegrations/endpoints.go | 20 ++ .../appintegrations/endpoints_config_test.go | 139 +++++++++++++ service/appintegrations/generated.json | 1 + service/appintegrations/go.mod | 19 ++ service/appintegrations/go.sum | 18 ++ service/applicationautoscaling/api_client.go | 1 + service/applicationautoscaling/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/applicationautoscaling/generated.json | 1 + service/applicationautoscaling/go.mod | 19 ++ service/applicationautoscaling/go.sum | 18 ++ service/applicationcostprofiler/api_client.go | 1 + service/applicationcostprofiler/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../applicationcostprofiler/generated.json | 1 + service/applicationcostprofiler/go.mod | 19 ++ service/applicationcostprofiler/go.sum | 18 ++ .../applicationdiscoveryservice/api_client.go | 1 + .../applicationdiscoveryservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + service/applicationdiscoveryservice/go.mod | 19 ++ service/applicationdiscoveryservice/go.sum | 18 ++ service/applicationinsights/api_client.go | 1 + service/applicationinsights/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/applicationinsights/generated.json | 1 + service/applicationinsights/go.mod | 19 ++ service/applicationinsights/go.sum | 18 ++ service/appmesh/api_client.go | 1 + service/appmesh/endpoints.go | 20 ++ service/appmesh/endpoints_config_test.go | 139 +++++++++++++ service/appmesh/generated.json | 1 + service/appmesh/go.mod | 19 ++ service/appmesh/go.sum | 18 ++ service/apprunner/api_client.go | 1 + service/apprunner/endpoints.go | 20 ++ service/apprunner/endpoints_config_test.go | 139 +++++++++++++ service/apprunner/generated.json | 1 + service/apprunner/go.mod | 19 ++ service/apprunner/go.sum | 18 ++ service/appstream/api_client.go | 1 + service/appstream/endpoints.go | 20 ++ service/appstream/endpoints_config_test.go | 139 +++++++++++++ service/appstream/generated.json | 1 + service/appstream/go.mod | 19 ++ service/appstream/go.sum | 18 ++ service/appsync/api_client.go | 1 + service/appsync/endpoints.go | 20 ++ service/appsync/endpoints_config_test.go | 139 +++++++++++++ service/appsync/generated.json | 1 + service/appsync/go.mod | 19 ++ service/appsync/go.sum | 18 ++ service/arczonalshift/api_client.go | 1 + service/arczonalshift/endpoints.go | 20 ++ .../arczonalshift/endpoints_config_test.go | 139 +++++++++++++ service/arczonalshift/generated.json | 1 + service/arczonalshift/go.mod | 19 ++ service/arczonalshift/go.sum | 18 ++ service/athena/api_client.go | 1 + service/athena/endpoints.go | 20 ++ service/athena/endpoints_config_test.go | 139 +++++++++++++ service/athena/generated.json | 1 + service/athena/go.mod | 19 ++ service/athena/go.sum | 18 ++ service/auditmanager/api_client.go | 1 + service/auditmanager/endpoints.go | 20 ++ service/auditmanager/endpoints_config_test.go | 139 +++++++++++++ service/auditmanager/generated.json | 1 + service/auditmanager/go.mod | 19 ++ service/auditmanager/go.sum | 18 ++ service/autoscaling/api_client.go | 1 + service/autoscaling/endpoints.go | 20 ++ service/autoscaling/endpoints_config_test.go | 139 +++++++++++++ service/autoscaling/generated.json | 1 + service/autoscaling/go.mod | 19 ++ service/autoscaling/go.sum | 18 ++ service/autoscalingplans/api_client.go | 1 + service/autoscalingplans/endpoints.go | 20 ++ .../autoscalingplans/endpoints_config_test.go | 139 +++++++++++++ service/autoscalingplans/generated.json | 1 + service/autoscalingplans/go.mod | 19 ++ service/autoscalingplans/go.sum | 18 ++ service/backup/api_client.go | 1 + service/backup/endpoints.go | 20 ++ service/backup/endpoints_config_test.go | 139 +++++++++++++ service/backup/generated.json | 1 + service/backup/go.mod | 19 ++ service/backup/go.sum | 18 ++ service/backupgateway/api_client.go | 1 + service/backupgateway/endpoints.go | 20 ++ .../backupgateway/endpoints_config_test.go | 139 +++++++++++++ service/backupgateway/generated.json | 1 + service/backupgateway/go.mod | 19 ++ service/backupgateway/go.sum | 18 ++ service/backupstorage/api_client.go | 1 + service/backupstorage/endpoints.go | 20 ++ .../backupstorage/endpoints_config_test.go | 139 +++++++++++++ service/backupstorage/generated.json | 1 + service/backupstorage/go.mod | 19 ++ service/backupstorage/go.sum | 18 ++ service/batch/api_client.go | 1 + service/batch/endpoints.go | 20 ++ service/batch/endpoints_config_test.go | 139 +++++++++++++ service/batch/generated.json | 1 + service/batch/go.mod | 19 ++ service/batch/go.sum | 18 ++ service/bedrock/api_client.go | 1 + service/bedrock/endpoints.go | 20 ++ service/bedrock/endpoints_config_test.go | 139 +++++++++++++ service/bedrock/generated.json | 1 + service/bedrock/go.mod | 19 ++ service/bedrock/go.sum | 18 ++ service/bedrockruntime/api_client.go | 1 + service/bedrockruntime/endpoints.go | 20 ++ .../bedrockruntime/endpoints_config_test.go | 139 +++++++++++++ service/bedrockruntime/generated.json | 1 + service/bedrockruntime/go.mod | 19 ++ service/bedrockruntime/go.sum | 18 ++ service/billingconductor/api_client.go | 1 + service/billingconductor/endpoints.go | 20 ++ .../billingconductor/endpoints_config_test.go | 139 +++++++++++++ service/billingconductor/generated.json | 1 + service/billingconductor/go.mod | 19 ++ service/billingconductor/go.sum | 18 ++ service/braket/api_client.go | 1 + service/braket/endpoints.go | 20 ++ service/braket/endpoints_config_test.go | 139 +++++++++++++ service/braket/generated.json | 1 + service/braket/go.mod | 19 ++ service/braket/go.sum | 18 ++ service/budgets/api_client.go | 1 + service/budgets/endpoints.go | 20 ++ service/budgets/endpoints_config_test.go | 139 +++++++++++++ service/budgets/generated.json | 1 + service/budgets/go.mod | 19 ++ service/budgets/go.sum | 18 ++ service/chime/api_client.go | 1 + service/chime/endpoints.go | 20 ++ service/chime/endpoints_config_test.go | 139 +++++++++++++ service/chime/generated.json | 1 + service/chime/go.mod | 19 ++ service/chime/go.sum | 18 ++ service/chimesdkidentity/api_client.go | 1 + service/chimesdkidentity/endpoints.go | 20 ++ .../chimesdkidentity/endpoints_config_test.go | 139 +++++++++++++ service/chimesdkidentity/generated.json | 1 + service/chimesdkidentity/go.mod | 19 ++ service/chimesdkidentity/go.sum | 18 ++ service/chimesdkmediapipelines/api_client.go | 1 + service/chimesdkmediapipelines/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/chimesdkmediapipelines/generated.json | 1 + service/chimesdkmediapipelines/go.mod | 19 ++ service/chimesdkmediapipelines/go.sum | 18 ++ service/chimesdkmeetings/api_client.go | 1 + service/chimesdkmeetings/endpoints.go | 20 ++ .../chimesdkmeetings/endpoints_config_test.go | 139 +++++++++++++ service/chimesdkmeetings/generated.json | 1 + service/chimesdkmeetings/go.mod | 19 ++ service/chimesdkmeetings/go.sum | 18 ++ service/chimesdkmessaging/api_client.go | 1 + service/chimesdkmessaging/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/chimesdkmessaging/generated.json | 1 + service/chimesdkmessaging/go.mod | 19 ++ service/chimesdkmessaging/go.sum | 18 ++ service/chimesdkvoice/api_client.go | 1 + service/chimesdkvoice/endpoints.go | 20 ++ .../chimesdkvoice/endpoints_config_test.go | 139 +++++++++++++ service/chimesdkvoice/generated.json | 1 + service/chimesdkvoice/go.mod | 19 ++ service/chimesdkvoice/go.sum | 18 ++ service/cleanrooms/api_client.go | 1 + service/cleanrooms/endpoints.go | 20 ++ service/cleanrooms/endpoints_config_test.go | 139 +++++++++++++ service/cleanrooms/generated.json | 1 + service/cleanrooms/go.mod | 19 ++ service/cleanrooms/go.sum | 18 ++ service/cloud9/api_client.go | 1 + service/cloud9/endpoints.go | 20 ++ service/cloud9/endpoints_config_test.go | 139 +++++++++++++ service/cloud9/generated.json | 1 + service/cloud9/go.mod | 19 ++ service/cloud9/go.sum | 18 ++ service/cloudcontrol/api_client.go | 1 + service/cloudcontrol/endpoints.go | 20 ++ service/cloudcontrol/endpoints_config_test.go | 139 +++++++++++++ service/cloudcontrol/generated.json | 1 + service/cloudcontrol/go.mod | 19 ++ service/cloudcontrol/go.sum | 18 ++ service/clouddirectory/api_client.go | 1 + service/clouddirectory/endpoints.go | 20 ++ .../clouddirectory/endpoints_config_test.go | 139 +++++++++++++ service/clouddirectory/generated.json | 1 + service/clouddirectory/go.mod | 19 ++ service/clouddirectory/go.sum | 18 ++ service/cloudformation/api_client.go | 1 + service/cloudformation/endpoints.go | 20 ++ .../cloudformation/endpoints_config_test.go | 139 +++++++++++++ service/cloudformation/generated.json | 1 + service/cloudformation/go.mod | 19 ++ service/cloudformation/go.sum | 18 ++ service/cloudfront/api_client.go | 1 + service/cloudfront/endpoints.go | 20 ++ service/cloudfront/endpoints_config_test.go | 139 +++++++++++++ service/cloudfront/generated.json | 1 + service/cloudfront/go.mod | 19 ++ service/cloudfront/go.sum | 18 ++ service/cloudhsm/api_client.go | 1 + service/cloudhsm/endpoints.go | 20 ++ service/cloudhsm/endpoints_config_test.go | 139 +++++++++++++ service/cloudhsm/generated.json | 1 + service/cloudhsm/go.mod | 19 ++ service/cloudhsm/go.sum | 18 ++ service/cloudhsmv2/api_client.go | 1 + service/cloudhsmv2/endpoints.go | 20 ++ service/cloudhsmv2/endpoints_config_test.go | 139 +++++++++++++ service/cloudhsmv2/generated.json | 1 + service/cloudhsmv2/go.mod | 19 ++ service/cloudhsmv2/go.sum | 18 ++ service/cloudsearch/api_client.go | 1 + service/cloudsearch/endpoints.go | 20 ++ service/cloudsearch/endpoints_config_test.go | 139 +++++++++++++ service/cloudsearch/generated.json | 1 + service/cloudsearch/go.mod | 19 ++ service/cloudsearch/go.sum | 18 ++ service/cloudsearchdomain/api_client.go | 1 + service/cloudsearchdomain/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/cloudsearchdomain/generated.json | 1 + service/cloudsearchdomain/go.mod | 19 ++ service/cloudsearchdomain/go.sum | 18 ++ service/cloudtrail/api_client.go | 1 + service/cloudtrail/endpoints.go | 20 ++ service/cloudtrail/endpoints_config_test.go | 139 +++++++++++++ service/cloudtrail/generated.json | 1 + service/cloudtrail/go.mod | 19 ++ service/cloudtrail/go.sum | 18 ++ service/cloudtraildata/api_client.go | 1 + service/cloudtraildata/endpoints.go | 20 ++ .../cloudtraildata/endpoints_config_test.go | 139 +++++++++++++ service/cloudtraildata/generated.json | 1 + service/cloudtraildata/go.mod | 19 ++ service/cloudtraildata/go.sum | 18 ++ service/cloudwatch/api_client.go | 1 + service/cloudwatch/endpoints.go | 20 ++ service/cloudwatch/endpoints_config_test.go | 139 +++++++++++++ service/cloudwatch/generated.json | 1 + service/cloudwatch/go.mod | 19 ++ service/cloudwatch/go.sum | 18 ++ service/cloudwatchevents/api_client.go | 1 + service/cloudwatchevents/endpoints.go | 20 ++ .../cloudwatchevents/endpoints_config_test.go | 139 +++++++++++++ service/cloudwatchevents/generated.json | 1 + service/cloudwatchevents/go.mod | 19 ++ service/cloudwatchevents/go.sum | 18 ++ service/cloudwatchlogs/api_client.go | 1 + service/cloudwatchlogs/endpoints.go | 20 ++ .../cloudwatchlogs/endpoints_config_test.go | 139 +++++++++++++ service/cloudwatchlogs/generated.json | 1 + service/cloudwatchlogs/go.mod | 19 ++ service/cloudwatchlogs/go.sum | 18 ++ service/codeartifact/api_client.go | 1 + service/codeartifact/endpoints.go | 20 ++ service/codeartifact/endpoints_config_test.go | 139 +++++++++++++ service/codeartifact/generated.json | 1 + service/codeartifact/go.mod | 19 ++ service/codeartifact/go.sum | 18 ++ service/codebuild/api_client.go | 1 + service/codebuild/endpoints.go | 20 ++ service/codebuild/endpoints_config_test.go | 139 +++++++++++++ service/codebuild/generated.json | 1 + service/codebuild/go.mod | 19 ++ service/codebuild/go.sum | 18 ++ service/codecatalyst/api_client.go | 1 + service/codecatalyst/endpoints.go | 20 ++ service/codecatalyst/endpoints_config_test.go | 139 +++++++++++++ service/codecatalyst/generated.json | 1 + service/codecatalyst/go.mod | 19 ++ service/codecatalyst/go.sum | 18 ++ service/codecommit/api_client.go | 1 + service/codecommit/endpoints.go | 20 ++ service/codecommit/endpoints_config_test.go | 139 +++++++++++++ service/codecommit/generated.json | 1 + service/codecommit/go.mod | 19 ++ service/codecommit/go.sum | 18 ++ service/codedeploy/api_client.go | 1 + service/codedeploy/endpoints.go | 20 ++ service/codedeploy/endpoints_config_test.go | 139 +++++++++++++ service/codedeploy/generated.json | 1 + service/codedeploy/go.mod | 19 ++ service/codedeploy/go.sum | 18 ++ service/codeguruprofiler/api_client.go | 1 + service/codeguruprofiler/endpoints.go | 20 ++ .../codeguruprofiler/endpoints_config_test.go | 139 +++++++++++++ service/codeguruprofiler/generated.json | 1 + service/codeguruprofiler/go.mod | 19 ++ service/codeguruprofiler/go.sum | 18 ++ service/codegurureviewer/api_client.go | 1 + service/codegurureviewer/endpoints.go | 20 ++ .../codegurureviewer/endpoints_config_test.go | 139 +++++++++++++ service/codegurureviewer/generated.json | 1 + service/codegurureviewer/go.mod | 19 ++ service/codegurureviewer/go.sum | 18 ++ service/codegurusecurity/api_client.go | 1 + service/codegurusecurity/endpoints.go | 20 ++ .../codegurusecurity/endpoints_config_test.go | 139 +++++++++++++ service/codegurusecurity/generated.json | 1 + service/codegurusecurity/go.mod | 19 ++ service/codegurusecurity/go.sum | 18 ++ service/codepipeline/api_client.go | 1 + service/codepipeline/endpoints.go | 20 ++ service/codepipeline/endpoints_config_test.go | 139 +++++++++++++ service/codepipeline/generated.json | 1 + service/codepipeline/go.mod | 19 ++ service/codepipeline/go.sum | 18 ++ service/codestar/api_client.go | 1 + service/codestar/endpoints.go | 20 ++ service/codestar/endpoints_config_test.go | 139 +++++++++++++ service/codestar/generated.json | 1 + service/codestar/go.mod | 19 ++ service/codestar/go.sum | 18 ++ service/codestarconnections/api_client.go | 1 + service/codestarconnections/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/codestarconnections/generated.json | 1 + service/codestarconnections/go.mod | 19 ++ service/codestarconnections/go.sum | 18 ++ service/codestarnotifications/api_client.go | 1 + service/codestarnotifications/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/codestarnotifications/generated.json | 1 + service/codestarnotifications/go.mod | 19 ++ service/codestarnotifications/go.sum | 18 ++ service/cognitoidentity/api_client.go | 1 + service/cognitoidentity/endpoints.go | 20 ++ .../cognitoidentity/endpoints_config_test.go | 139 +++++++++++++ service/cognitoidentity/generated.json | 1 + service/cognitoidentity/go.mod | 19 ++ service/cognitoidentity/go.sum | 18 ++ service/cognitoidentityprovider/api_client.go | 1 + service/cognitoidentityprovider/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../cognitoidentityprovider/generated.json | 1 + service/cognitoidentityprovider/go.mod | 19 ++ service/cognitoidentityprovider/go.sum | 18 ++ service/cognitosync/api_client.go | 1 + service/cognitosync/endpoints.go | 20 ++ service/cognitosync/endpoints_config_test.go | 139 +++++++++++++ service/cognitosync/generated.json | 1 + service/cognitosync/go.mod | 19 ++ service/cognitosync/go.sum | 18 ++ service/comprehend/api_client.go | 1 + service/comprehend/endpoints.go | 20 ++ service/comprehend/endpoints_config_test.go | 139 +++++++++++++ service/comprehend/generated.json | 1 + service/comprehend/go.mod | 19 ++ service/comprehend/go.sum | 18 ++ service/comprehendmedical/api_client.go | 1 + service/comprehendmedical/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/comprehendmedical/generated.json | 1 + service/comprehendmedical/go.mod | 19 ++ service/comprehendmedical/go.sum | 18 ++ service/computeoptimizer/api_client.go | 1 + service/computeoptimizer/endpoints.go | 20 ++ .../computeoptimizer/endpoints_config_test.go | 139 +++++++++++++ service/computeoptimizer/generated.json | 1 + service/computeoptimizer/go.mod | 19 ++ service/computeoptimizer/go.sum | 18 ++ service/configservice/api_client.go | 1 + service/configservice/endpoints.go | 20 ++ .../configservice/endpoints_config_test.go | 139 +++++++++++++ service/configservice/generated.json | 1 + service/configservice/go.mod | 19 ++ service/configservice/go.sum | 18 ++ service/connect/api_client.go | 1 + service/connect/endpoints.go | 20 ++ service/connect/endpoints_config_test.go | 139 +++++++++++++ service/connect/generated.json | 1 + service/connect/go.mod | 19 ++ service/connect/go.sum | 18 ++ service/connectcampaigns/api_client.go | 1 + service/connectcampaigns/endpoints.go | 20 ++ .../connectcampaigns/endpoints_config_test.go | 139 +++++++++++++ service/connectcampaigns/generated.json | 1 + service/connectcampaigns/go.mod | 19 ++ service/connectcampaigns/go.sum | 18 ++ service/connectcases/api_client.go | 1 + service/connectcases/endpoints.go | 20 ++ service/connectcases/endpoints_config_test.go | 139 +++++++++++++ service/connectcases/generated.json | 1 + service/connectcases/go.mod | 19 ++ service/connectcases/go.sum | 18 ++ service/connectcontactlens/api_client.go | 1 + service/connectcontactlens/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/connectcontactlens/generated.json | 1 + service/connectcontactlens/go.mod | 19 ++ service/connectcontactlens/go.sum | 18 ++ service/connectparticipant/api_client.go | 1 + service/connectparticipant/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/connectparticipant/generated.json | 1 + service/connectparticipant/go.mod | 19 ++ service/connectparticipant/go.sum | 18 ++ service/controltower/api_client.go | 1 + service/controltower/endpoints.go | 20 ++ service/controltower/endpoints_config_test.go | 139 +++++++++++++ service/controltower/generated.json | 1 + service/controltower/go.mod | 19 ++ service/controltower/go.sum | 18 ++ .../costandusagereportservice/api_client.go | 1 + .../costandusagereportservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../costandusagereportservice/generated.json | 1 + service/costandusagereportservice/go.mod | 19 ++ service/costandusagereportservice/go.sum | 18 ++ service/costexplorer/api_client.go | 1 + service/costexplorer/endpoints.go | 20 ++ service/costexplorer/endpoints_config_test.go | 139 +++++++++++++ service/costexplorer/generated.json | 1 + service/costexplorer/go.mod | 19 ++ service/costexplorer/go.sum | 18 ++ service/customerprofiles/api_client.go | 1 + service/customerprofiles/endpoints.go | 20 ++ .../customerprofiles/endpoints_config_test.go | 139 +++++++++++++ service/customerprofiles/generated.json | 1 + service/customerprofiles/go.mod | 19 ++ service/customerprofiles/go.sum | 18 ++ .../databasemigrationservice/api_client.go | 1 + service/databasemigrationservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../databasemigrationservice/generated.json | 1 + service/databasemigrationservice/go.mod | 19 ++ service/databasemigrationservice/go.sum | 18 ++ service/databrew/api_client.go | 1 + service/databrew/endpoints.go | 20 ++ service/databrew/endpoints_config_test.go | 139 +++++++++++++ service/databrew/generated.json | 1 + service/databrew/go.mod | 19 ++ service/databrew/go.sum | 18 ++ service/dataexchange/api_client.go | 1 + service/dataexchange/endpoints.go | 20 ++ service/dataexchange/endpoints_config_test.go | 139 +++++++++++++ service/dataexchange/generated.json | 1 + service/dataexchange/go.mod | 19 ++ service/dataexchange/go.sum | 18 ++ service/datapipeline/api_client.go | 1 + service/datapipeline/endpoints.go | 20 ++ service/datapipeline/endpoints_config_test.go | 139 +++++++++++++ service/datapipeline/generated.json | 1 + service/datapipeline/go.mod | 19 ++ service/datapipeline/go.sum | 18 ++ service/datasync/api_client.go | 1 + service/datasync/endpoints.go | 20 ++ service/datasync/endpoints_config_test.go | 139 +++++++++++++ service/datasync/generated.json | 1 + service/datasync/go.mod | 19 ++ service/datasync/go.sum | 18 ++ service/datazone/api_client.go | 1 + service/datazone/endpoints.go | 20 ++ service/datazone/endpoints_config_test.go | 139 +++++++++++++ service/datazone/generated.json | 1 + service/datazone/go.mod | 19 ++ service/datazone/go.sum | 18 ++ service/dax/api_client.go | 1 + service/dax/endpoints.go | 20 ++ service/dax/endpoints_config_test.go | 139 +++++++++++++ service/dax/generated.json | 1 + service/dax/go.mod | 19 ++ service/dax/go.sum | 18 ++ service/detective/api_client.go | 1 + service/detective/endpoints.go | 20 ++ service/detective/endpoints_config_test.go | 139 +++++++++++++ service/detective/generated.json | 1 + service/detective/go.mod | 19 ++ service/detective/go.sum | 18 ++ service/devicefarm/api_client.go | 1 + service/devicefarm/endpoints.go | 20 ++ service/devicefarm/endpoints_config_test.go | 139 +++++++++++++ service/devicefarm/generated.json | 1 + service/devicefarm/go.mod | 19 ++ service/devicefarm/go.sum | 18 ++ service/devopsguru/api_client.go | 1 + service/devopsguru/endpoints.go | 20 ++ service/devopsguru/endpoints_config_test.go | 139 +++++++++++++ service/devopsguru/generated.json | 1 + service/devopsguru/go.mod | 19 ++ service/devopsguru/go.sum | 18 ++ service/directconnect/api_client.go | 1 + service/directconnect/endpoints.go | 20 ++ .../directconnect/endpoints_config_test.go | 139 +++++++++++++ service/directconnect/generated.json | 1 + service/directconnect/go.mod | 19 ++ service/directconnect/go.sum | 18 ++ service/directoryservice/api_client.go | 1 + service/directoryservice/endpoints.go | 20 ++ .../directoryservice/endpoints_config_test.go | 139 +++++++++++++ service/directoryservice/generated.json | 1 + service/directoryservice/go.mod | 19 ++ service/directoryservice/go.sum | 18 ++ service/dlm/api_client.go | 1 + service/dlm/endpoints.go | 20 ++ service/dlm/endpoints_config_test.go | 139 +++++++++++++ service/dlm/generated.json | 1 + service/dlm/go.mod | 19 ++ service/dlm/go.sum | 18 ++ service/docdb/api_client.go | 1 + service/docdb/endpoints.go | 20 ++ service/docdb/endpoints_config_test.go | 139 +++++++++++++ service/docdb/generated.json | 1 + service/docdb/go.mod | 17 ++ service/docdb/go.sum | 16 ++ service/docdbelastic/api_client.go | 1 + service/docdbelastic/endpoints.go | 20 ++ service/docdbelastic/endpoints_config_test.go | 139 +++++++++++++ service/docdbelastic/generated.json | 1 + service/docdbelastic/go.mod | 19 ++ service/docdbelastic/go.sum | 18 ++ service/drs/api_client.go | 1 + service/drs/endpoints.go | 20 ++ service/drs/endpoints_config_test.go | 139 +++++++++++++ service/drs/generated.json | 1 + service/drs/go.mod | 19 ++ service/drs/go.sum | 18 ++ service/dynamodb/api_client.go | 1 + service/dynamodb/endpoints.go | 20 ++ service/dynamodb/endpoints_config_test.go | 139 +++++++++++++ service/dynamodb/generated.json | 1 + service/dynamodb/go.mod | 19 ++ service/dynamodb/go.sum | 18 ++ service/dynamodbstreams/api_client.go | 1 + service/dynamodbstreams/endpoints.go | 20 ++ .../dynamodbstreams/endpoints_config_test.go | 139 +++++++++++++ service/dynamodbstreams/generated.json | 1 + service/dynamodbstreams/go.mod | 19 ++ service/dynamodbstreams/go.sum | 18 ++ service/ebs/api_client.go | 1 + service/ebs/endpoints.go | 20 ++ service/ebs/endpoints_config_test.go | 139 +++++++++++++ service/ebs/generated.json | 1 + service/ebs/go.mod | 19 ++ service/ebs/go.sum | 18 ++ service/ec2/api_client.go | 1 + service/ec2/endpoints.go | 20 ++ service/ec2/endpoints_config_test.go | 139 +++++++++++++ service/ec2/generated.json | 1 + service/ec2/go.mod | 17 ++ service/ec2/go.sum | 16 ++ service/ec2instanceconnect/api_client.go | 1 + service/ec2instanceconnect/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/ec2instanceconnect/generated.json | 1 + service/ec2instanceconnect/go.mod | 19 ++ service/ec2instanceconnect/go.sum | 18 ++ service/ecr/api_client.go | 1 + service/ecr/endpoints.go | 20 ++ service/ecr/endpoints_config_test.go | 139 +++++++++++++ service/ecr/generated.json | 1 + service/ecr/go.mod | 19 ++ service/ecr/go.sum | 18 ++ service/ecrpublic/api_client.go | 1 + service/ecrpublic/endpoints.go | 20 ++ service/ecrpublic/endpoints_config_test.go | 139 +++++++++++++ service/ecrpublic/generated.json | 1 + service/ecrpublic/go.mod | 19 ++ service/ecrpublic/go.sum | 18 ++ service/ecs/api_client.go | 1 + service/ecs/endpoints.go | 20 ++ service/ecs/endpoints_config_test.go | 139 +++++++++++++ service/ecs/generated.json | 1 + service/ecs/go.mod | 19 ++ service/ecs/go.sum | 18 ++ service/efs/api_client.go | 1 + service/efs/endpoints.go | 20 ++ service/efs/endpoints_config_test.go | 139 +++++++++++++ service/efs/generated.json | 1 + service/efs/go.mod | 19 ++ service/efs/go.sum | 18 ++ service/eks/api_client.go | 1 + service/eks/endpoints.go | 20 ++ service/eks/endpoints_config_test.go | 139 +++++++++++++ service/eks/generated.json | 1 + service/eks/go.mod | 19 ++ service/eks/go.sum | 18 ++ service/elasticache/api_client.go | 1 + service/elasticache/endpoints.go | 20 ++ service/elasticache/endpoints_config_test.go | 139 +++++++++++++ service/elasticache/generated.json | 1 + service/elasticache/go.mod | 19 ++ service/elasticache/go.sum | 18 ++ service/elasticbeanstalk/go.mod | 35 +++- service/elasticinference/api_client.go | 1 + service/elasticinference/endpoints.go | 20 ++ .../elasticinference/endpoints_config_test.go | 139 +++++++++++++ service/elasticinference/generated.json | 1 + service/elasticinference/go.mod | 19 ++ service/elasticinference/go.sum | 18 ++ service/elasticloadbalancing/api_client.go | 1 + service/elasticloadbalancing/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/elasticloadbalancing/generated.json | 1 + service/elasticloadbalancing/go.mod | 19 ++ service/elasticloadbalancing/go.sum | 18 ++ service/elasticloadbalancingv2/api_client.go | 1 + service/elasticloadbalancingv2/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/elasticloadbalancingv2/generated.json | 1 + service/elasticloadbalancingv2/go.mod | 19 ++ service/elasticloadbalancingv2/go.sum | 18 ++ service/elasticsearchservice/api_client.go | 1 + service/elasticsearchservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/elasticsearchservice/generated.json | 1 + service/elasticsearchservice/go.mod | 19 ++ service/elasticsearchservice/go.sum | 18 ++ service/elastictranscoder/api_client.go | 1 + service/elastictranscoder/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/elastictranscoder/generated.json | 1 + service/elastictranscoder/go.mod | 19 ++ service/elastictranscoder/go.sum | 18 ++ service/emr/api_client.go | 1 + service/emr/endpoints.go | 20 ++ service/emr/endpoints_config_test.go | 139 +++++++++++++ service/emr/generated.json | 1 + service/emr/go.mod | 19 ++ service/emr/go.sum | 18 ++ service/emrcontainers/api_client.go | 1 + service/emrcontainers/endpoints.go | 20 ++ .../emrcontainers/endpoints_config_test.go | 139 +++++++++++++ service/emrcontainers/generated.json | 1 + service/emrcontainers/go.mod | 19 ++ service/emrcontainers/go.sum | 18 ++ service/emrserverless/api_client.go | 1 + service/emrserverless/endpoints.go | 20 ++ .../emrserverless/endpoints_config_test.go | 139 +++++++++++++ service/emrserverless/generated.json | 1 + service/emrserverless/go.mod | 19 ++ service/emrserverless/go.sum | 18 ++ service/entityresolution/api_client.go | 1 + service/entityresolution/endpoints.go | 20 ++ .../entityresolution/endpoints_config_test.go | 139 +++++++++++++ service/entityresolution/generated.json | 1 + service/entityresolution/go.mod | 19 ++ service/entityresolution/go.sum | 18 ++ service/eventbridge/endpoints.go | 16 +- service/eventbridge/endpoints_config_test.go | 192 +++++++++--------- service/eventbridge/go.mod | 19 +- service/evidently/api_client.go | 1 + service/evidently/endpoints.go | 20 ++ service/evidently/endpoints_config_test.go | 139 +++++++++++++ service/evidently/generated.json | 1 + service/evidently/go.mod | 19 ++ service/evidently/go.sum | 18 ++ service/finspace/api_client.go | 1 + service/finspace/endpoints.go | 20 ++ service/finspace/endpoints_config_test.go | 139 +++++++++++++ service/finspace/generated.json | 1 + service/finspace/go.mod | 19 ++ service/finspace/go.sum | 18 ++ service/finspacedata/api_client.go | 1 + service/finspacedata/endpoints.go | 20 ++ service/finspacedata/endpoints_config_test.go | 139 +++++++++++++ service/finspacedata/generated.json | 1 + service/finspacedata/go.mod | 19 ++ service/finspacedata/go.sum | 18 ++ service/firehose/api_client.go | 1 + service/firehose/endpoints.go | 20 ++ service/firehose/endpoints_config_test.go | 139 +++++++++++++ service/firehose/generated.json | 1 + service/firehose/go.mod | 19 ++ service/firehose/go.sum | 18 ++ service/fis/api_client.go | 1 + service/fis/endpoints.go | 20 ++ service/fis/endpoints_config_test.go | 139 +++++++++++++ service/fis/generated.json | 1 + service/fis/go.mod | 19 ++ service/fis/go.sum | 18 ++ service/fms/api_client.go | 1 + service/fms/endpoints.go | 20 ++ service/fms/endpoints_config_test.go | 139 +++++++++++++ service/fms/generated.json | 1 + service/fms/go.mod | 19 ++ service/fms/go.sum | 18 ++ service/forecast/api_client.go | 1 + service/forecast/endpoints.go | 20 ++ service/forecast/endpoints_config_test.go | 139 +++++++++++++ service/forecast/generated.json | 1 + service/forecast/go.mod | 19 ++ service/forecast/go.sum | 18 ++ service/forecastquery/api_client.go | 1 + service/forecastquery/endpoints.go | 20 ++ .../forecastquery/endpoints_config_test.go | 139 +++++++++++++ service/forecastquery/generated.json | 1 + service/forecastquery/go.mod | 19 ++ service/forecastquery/go.sum | 18 ++ service/frauddetector/api_client.go | 1 + service/frauddetector/endpoints.go | 20 ++ .../frauddetector/endpoints_config_test.go | 139 +++++++++++++ service/frauddetector/generated.json | 1 + service/frauddetector/go.mod | 19 ++ service/frauddetector/go.sum | 18 ++ service/fsx/api_client.go | 1 + service/fsx/endpoints.go | 20 ++ service/fsx/endpoints_config_test.go | 139 +++++++++++++ service/fsx/generated.json | 1 + service/fsx/go.mod | 19 ++ service/fsx/go.sum | 18 ++ service/gamelift/api_client.go | 1 + service/gamelift/endpoints.go | 20 ++ service/gamelift/endpoints_config_test.go | 139 +++++++++++++ service/gamelift/generated.json | 1 + service/gamelift/go.mod | 19 ++ service/gamelift/go.sum | 18 ++ service/glacier/api_client.go | 1 + service/glacier/endpoints.go | 20 ++ service/glacier/endpoints_config_test.go | 139 +++++++++++++ service/glacier/generated.json | 1 + service/glacier/go.mod | 19 ++ service/glacier/go.sum | 18 ++ service/globalaccelerator/api_client.go | 1 + service/globalaccelerator/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/globalaccelerator/generated.json | 1 + service/globalaccelerator/go.mod | 19 ++ service/globalaccelerator/go.sum | 18 ++ service/glue/api_client.go | 1 + service/glue/endpoints.go | 20 ++ service/glue/endpoints_config_test.go | 139 +++++++++++++ service/glue/generated.json | 1 + service/glue/go.mod | 19 ++ service/glue/go.sum | 18 ++ service/grafana/api_client.go | 1 + service/grafana/endpoints.go | 20 ++ service/grafana/endpoints_config_test.go | 139 +++++++++++++ service/grafana/generated.json | 1 + service/grafana/go.mod | 19 ++ service/grafana/go.sum | 18 ++ service/greengrass/api_client.go | 1 + service/greengrass/endpoints.go | 20 ++ service/greengrass/endpoints_config_test.go | 139 +++++++++++++ service/greengrass/generated.json | 1 + service/greengrass/go.mod | 19 ++ service/greengrass/go.sum | 18 ++ service/greengrassv2/api_client.go | 1 + service/greengrassv2/endpoints.go | 20 ++ service/greengrassv2/endpoints_config_test.go | 139 +++++++++++++ service/greengrassv2/generated.json | 1 + service/greengrassv2/go.mod | 19 ++ service/greengrassv2/go.sum | 18 ++ service/groundstation/api_client.go | 1 + service/groundstation/endpoints.go | 20 ++ .../groundstation/endpoints_config_test.go | 139 +++++++++++++ service/groundstation/generated.json | 1 + service/groundstation/go.mod | 19 ++ service/groundstation/go.sum | 18 ++ service/guardduty/api_client.go | 1 + service/guardduty/endpoints.go | 20 ++ service/guardduty/endpoints_config_test.go | 139 +++++++++++++ service/guardduty/generated.json | 1 + service/guardduty/go.mod | 19 ++ service/guardduty/go.sum | 18 ++ service/health/api_client.go | 1 + service/health/endpoints.go | 20 ++ service/health/endpoints_config_test.go | 139 +++++++++++++ service/health/generated.json | 1 + service/health/go.mod | 19 ++ service/health/go.sum | 18 ++ service/healthlake/api_client.go | 1 + service/healthlake/endpoints.go | 20 ++ service/healthlake/endpoints_config_test.go | 139 +++++++++++++ service/healthlake/generated.json | 1 + service/healthlake/go.mod | 19 ++ service/healthlake/go.sum | 18 ++ service/honeycode/api_client.go | 1 + service/honeycode/endpoints.go | 20 ++ service/honeycode/endpoints_config_test.go | 139 +++++++++++++ service/honeycode/generated.json | 1 + service/honeycode/go.mod | 19 ++ service/honeycode/go.sum | 18 ++ service/iam/api_client.go | 1 + service/iam/endpoints.go | 20 ++ service/iam/endpoints_config_test.go | 139 +++++++++++++ service/iam/generated.json | 1 + service/iam/go.mod | 19 ++ service/iam/go.sum | 18 ++ service/identitystore/api_client.go | 1 + service/identitystore/endpoints.go | 20 ++ .../identitystore/endpoints_config_test.go | 139 +++++++++++++ service/identitystore/generated.json | 1 + service/identitystore/go.mod | 19 ++ service/identitystore/go.sum | 18 ++ service/imagebuilder/api_client.go | 1 + service/imagebuilder/endpoints.go | 20 ++ service/imagebuilder/endpoints_config_test.go | 139 +++++++++++++ service/imagebuilder/generated.json | 1 + service/imagebuilder/go.mod | 19 ++ service/imagebuilder/go.sum | 18 ++ service/inspector/api_client.go | 1 + service/inspector/endpoints.go | 20 ++ service/inspector/endpoints_config_test.go | 139 +++++++++++++ service/inspector/generated.json | 1 + service/inspector/go.mod | 19 ++ service/inspector/go.sum | 18 ++ service/inspector2/api_client.go | 1 + service/inspector2/endpoints.go | 20 ++ service/inspector2/endpoints_config_test.go | 139 +++++++++++++ service/inspector2/generated.json | 1 + service/inspector2/go.mod | 19 ++ service/inspector2/go.sum | 18 ++ service/internal/benchmark/go.mod | 16 ++ service/internal/eventstreamtesting/go.mod | 6 + service/internal/eventstreamtesting/go.sum | 3 + service/internal/integrationtest/go.mod | 2 + service/internetmonitor/api_client.go | 1 + service/internetmonitor/endpoints.go | 20 ++ .../internetmonitor/endpoints_config_test.go | 139 +++++++++++++ service/internetmonitor/generated.json | 1 + service/internetmonitor/go.mod | 19 ++ service/internetmonitor/go.sum | 18 ++ service/iot/api_client.go | 1 + service/iot/endpoints.go | 20 ++ service/iot/endpoints_config_test.go | 139 +++++++++++++ service/iot/generated.json | 1 + service/iot/go.mod | 19 ++ service/iot/go.sum | 18 ++ service/iot1clickdevicesservice/api_client.go | 1 + service/iot1clickdevicesservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../iot1clickdevicesservice/generated.json | 1 + service/iot1clickdevicesservice/go.mod | 19 ++ service/iot1clickdevicesservice/go.sum | 18 ++ service/iot1clickprojects/api_client.go | 1 + service/iot1clickprojects/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/iot1clickprojects/generated.json | 1 + service/iot1clickprojects/go.mod | 19 ++ service/iot1clickprojects/go.sum | 18 ++ service/iotanalytics/api_client.go | 1 + service/iotanalytics/endpoints.go | 20 ++ service/iotanalytics/endpoints_config_test.go | 139 +++++++++++++ service/iotanalytics/generated.json | 1 + service/iotanalytics/go.mod | 19 ++ service/iotanalytics/go.sum | 18 ++ service/iotdataplane/api_client.go | 1 + service/iotdataplane/endpoints.go | 20 ++ service/iotdataplane/endpoints_config_test.go | 139 +++++++++++++ service/iotdataplane/generated.json | 1 + service/iotdataplane/go.mod | 19 ++ service/iotdataplane/go.sum | 18 ++ service/iotdeviceadvisor/api_client.go | 1 + service/iotdeviceadvisor/endpoints.go | 20 ++ .../iotdeviceadvisor/endpoints_config_test.go | 139 +++++++++++++ service/iotdeviceadvisor/generated.json | 1 + service/iotdeviceadvisor/go.mod | 19 ++ service/iotdeviceadvisor/go.sum | 18 ++ service/iotevents/api_client.go | 1 + service/iotevents/endpoints.go | 20 ++ service/iotevents/endpoints_config_test.go | 139 +++++++++++++ service/iotevents/generated.json | 1 + service/iotevents/go.mod | 19 ++ service/iotevents/go.sum | 18 ++ service/ioteventsdata/api_client.go | 1 + service/ioteventsdata/endpoints.go | 20 ++ .../ioteventsdata/endpoints_config_test.go | 139 +++++++++++++ service/ioteventsdata/generated.json | 1 + service/ioteventsdata/go.mod | 19 ++ service/ioteventsdata/go.sum | 18 ++ service/iotfleethub/api_client.go | 1 + service/iotfleethub/endpoints.go | 20 ++ service/iotfleethub/endpoints_config_test.go | 139 +++++++++++++ service/iotfleethub/generated.json | 1 + service/iotfleethub/go.mod | 19 ++ service/iotfleethub/go.sum | 18 ++ service/iotfleetwise/api_client.go | 1 + service/iotfleetwise/endpoints.go | 20 ++ service/iotfleetwise/endpoints_config_test.go | 139 +++++++++++++ service/iotfleetwise/generated.json | 1 + service/iotfleetwise/go.mod | 19 ++ service/iotfleetwise/go.sum | 18 ++ service/iotjobsdataplane/api_client.go | 1 + service/iotjobsdataplane/endpoints.go | 20 ++ .../iotjobsdataplane/endpoints_config_test.go | 139 +++++++++++++ service/iotjobsdataplane/generated.json | 1 + service/iotjobsdataplane/go.mod | 19 ++ service/iotjobsdataplane/go.sum | 18 ++ service/iotroborunner/api_client.go | 1 + service/iotroborunner/endpoints.go | 20 ++ .../iotroborunner/endpoints_config_test.go | 139 +++++++++++++ service/iotroborunner/generated.json | 1 + service/iotroborunner/go.mod | 19 ++ service/iotroborunner/go.sum | 18 ++ service/iotsecuretunneling/api_client.go | 1 + service/iotsecuretunneling/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/iotsecuretunneling/generated.json | 1 + service/iotsecuretunneling/go.mod | 19 ++ service/iotsecuretunneling/go.sum | 18 ++ service/iotsitewise/api_client.go | 1 + service/iotsitewise/endpoints.go | 20 ++ service/iotsitewise/endpoints_config_test.go | 139 +++++++++++++ service/iotsitewise/generated.json | 1 + service/iotsitewise/go.mod | 19 ++ service/iotsitewise/go.sum | 18 ++ service/iotthingsgraph/api_client.go | 1 + service/iotthingsgraph/endpoints.go | 20 ++ .../iotthingsgraph/endpoints_config_test.go | 139 +++++++++++++ service/iotthingsgraph/generated.json | 1 + service/iotthingsgraph/go.mod | 19 ++ service/iotthingsgraph/go.sum | 18 ++ service/iottwinmaker/api_client.go | 1 + service/iottwinmaker/endpoints.go | 20 ++ service/iottwinmaker/endpoints_config_test.go | 139 +++++++++++++ service/iottwinmaker/generated.json | 1 + service/iottwinmaker/go.mod | 19 ++ service/iottwinmaker/go.sum | 18 ++ service/iotwireless/api_client.go | 1 + service/iotwireless/endpoints.go | 20 ++ service/iotwireless/endpoints_config_test.go | 139 +++++++++++++ service/iotwireless/generated.json | 1 + service/iotwireless/go.mod | 19 ++ service/iotwireless/go.sum | 18 ++ service/ivs/api_client.go | 1 + service/ivs/endpoints.go | 20 ++ service/ivs/endpoints_config_test.go | 139 +++++++++++++ service/ivs/generated.json | 1 + service/ivs/go.mod | 19 ++ service/ivs/go.sum | 18 ++ service/ivschat/api_client.go | 1 + service/ivschat/endpoints.go | 20 ++ service/ivschat/endpoints_config_test.go | 139 +++++++++++++ service/ivschat/generated.json | 1 + service/ivschat/go.mod | 19 ++ service/ivschat/go.sum | 18 ++ service/ivsrealtime/api_client.go | 1 + service/ivsrealtime/endpoints.go | 20 ++ service/ivsrealtime/endpoints_config_test.go | 139 +++++++++++++ service/ivsrealtime/generated.json | 1 + service/ivsrealtime/go.mod | 19 ++ service/ivsrealtime/go.sum | 18 ++ service/kafka/api_client.go | 1 + service/kafka/endpoints.go | 20 ++ service/kafka/endpoints_config_test.go | 139 +++++++++++++ service/kafka/generated.json | 1 + service/kafka/go.mod | 19 ++ service/kafka/go.sum | 18 ++ service/kafkaconnect/api_client.go | 1 + service/kafkaconnect/endpoints.go | 20 ++ service/kafkaconnect/endpoints_config_test.go | 139 +++++++++++++ service/kafkaconnect/generated.json | 1 + service/kafkaconnect/go.mod | 19 ++ service/kafkaconnect/go.sum | 18 ++ service/kendra/api_client.go | 1 + service/kendra/endpoints.go | 20 ++ service/kendra/endpoints_config_test.go | 139 +++++++++++++ service/kendra/generated.json | 1 + service/kendra/go.mod | 19 ++ service/kendra/go.sum | 18 ++ service/kendraranking/api_client.go | 1 + service/kendraranking/endpoints.go | 20 ++ .../kendraranking/endpoints_config_test.go | 139 +++++++++++++ service/kendraranking/generated.json | 1 + service/kendraranking/go.mod | 19 ++ service/kendraranking/go.sum | 18 ++ service/keyspaces/api_client.go | 1 + service/keyspaces/endpoints.go | 20 ++ service/keyspaces/endpoints_config_test.go | 139 +++++++++++++ service/keyspaces/generated.json | 1 + service/keyspaces/go.mod | 19 ++ service/keyspaces/go.sum | 18 ++ service/kinesis/api_client.go | 1 + service/kinesis/endpoints.go | 20 ++ service/kinesis/endpoints_config_test.go | 139 +++++++++++++ service/kinesis/generated.json | 1 + service/kinesis/go.mod | 19 ++ service/kinesis/go.sum | 18 ++ service/kinesis/internal/testing/go.mod | 6 + service/kinesis/internal/testing/go.sum | 6 + service/kinesisanalytics/api_client.go | 1 + service/kinesisanalytics/endpoints.go | 20 ++ .../kinesisanalytics/endpoints_config_test.go | 139 +++++++++++++ service/kinesisanalytics/generated.json | 1 + service/kinesisanalytics/go.mod | 19 ++ service/kinesisanalytics/go.sum | 18 ++ service/kinesisanalyticsv2/api_client.go | 1 + service/kinesisanalyticsv2/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/kinesisanalyticsv2/generated.json | 1 + service/kinesisanalyticsv2/go.mod | 19 ++ service/kinesisanalyticsv2/go.sum | 18 ++ service/kinesisvideo/api_client.go | 1 + service/kinesisvideo/endpoints.go | 20 ++ service/kinesisvideo/endpoints_config_test.go | 139 +++++++++++++ service/kinesisvideo/generated.json | 1 + service/kinesisvideo/go.mod | 19 ++ service/kinesisvideo/go.sum | 18 ++ .../kinesisvideoarchivedmedia/api_client.go | 1 + .../kinesisvideoarchivedmedia/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../kinesisvideoarchivedmedia/generated.json | 1 + service/kinesisvideoarchivedmedia/go.mod | 19 ++ service/kinesisvideoarchivedmedia/go.sum | 18 ++ service/kinesisvideomedia/api_client.go | 1 + service/kinesisvideomedia/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/kinesisvideomedia/generated.json | 1 + service/kinesisvideomedia/go.mod | 19 ++ service/kinesisvideomedia/go.sum | 18 ++ service/kinesisvideosignaling/api_client.go | 1 + service/kinesisvideosignaling/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/kinesisvideosignaling/generated.json | 1 + service/kinesisvideosignaling/go.mod | 19 ++ service/kinesisvideosignaling/go.sum | 18 ++ .../kinesisvideowebrtcstorage/api_client.go | 1 + .../kinesisvideowebrtcstorage/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../kinesisvideowebrtcstorage/generated.json | 1 + service/kinesisvideowebrtcstorage/go.mod | 19 ++ service/kinesisvideowebrtcstorage/go.sum | 18 ++ service/kms/api_client.go | 1 + service/kms/endpoints.go | 20 ++ service/kms/endpoints_config_test.go | 139 +++++++++++++ service/kms/generated.json | 1 + service/kms/go.mod | 19 ++ service/kms/go.sum | 18 ++ service/lakeformation/api_client.go | 1 + service/lakeformation/endpoints.go | 20 ++ .../lakeformation/endpoints_config_test.go | 139 +++++++++++++ service/lakeformation/generated.json | 1 + service/lakeformation/go.mod | 19 ++ service/lakeformation/go.sum | 18 ++ service/lambda/api_client.go | 1 + service/lambda/endpoints.go | 20 ++ service/lambda/endpoints_config_test.go | 139 +++++++++++++ service/lambda/generated.json | 1 + service/lambda/go.mod | 19 ++ service/lambda/go.sum | 18 ++ service/lexmodelbuildingservice/api_client.go | 1 + service/lexmodelbuildingservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../lexmodelbuildingservice/generated.json | 1 + service/lexmodelbuildingservice/go.mod | 19 ++ service/lexmodelbuildingservice/go.sum | 18 ++ service/lexmodelsv2/api_client.go | 1 + service/lexmodelsv2/endpoints.go | 20 ++ service/lexmodelsv2/endpoints_config_test.go | 139 +++++++++++++ service/lexmodelsv2/generated.json | 1 + service/lexmodelsv2/go.mod | 19 ++ service/lexmodelsv2/go.sum | 18 ++ service/lexruntimeservice/api_client.go | 1 + service/lexruntimeservice/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/lexruntimeservice/generated.json | 1 + service/lexruntimeservice/go.mod | 19 ++ service/lexruntimeservice/go.sum | 18 ++ service/lexruntimev2/api_client.go | 1 + service/lexruntimev2/endpoints.go | 20 ++ service/lexruntimev2/endpoints_config_test.go | 139 +++++++++++++ service/lexruntimev2/generated.json | 1 + service/lexruntimev2/go.mod | 19 ++ service/lexruntimev2/go.sum | 18 ++ service/licensemanager/api_client.go | 1 + service/licensemanager/endpoints.go | 20 ++ .../licensemanager/endpoints_config_test.go | 139 +++++++++++++ service/licensemanager/generated.json | 1 + service/licensemanager/go.mod | 19 ++ service/licensemanager/go.sum | 18 ++ .../api_client.go | 1 + .../endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + .../licensemanagerlinuxsubscriptions/go.mod | 19 ++ .../licensemanagerlinuxsubscriptions/go.sum | 18 ++ .../api_client.go | 1 + .../endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + .../licensemanagerusersubscriptions/go.mod | 19 ++ .../licensemanagerusersubscriptions/go.sum | 18 ++ service/lightsail/api_client.go | 1 + service/lightsail/endpoints.go | 20 ++ service/lightsail/endpoints_config_test.go | 139 +++++++++++++ service/lightsail/generated.json | 1 + service/lightsail/go.mod | 19 ++ service/lightsail/go.sum | 18 ++ service/location/api_client.go | 1 + service/location/endpoints.go | 20 ++ service/location/endpoints_config_test.go | 139 +++++++++++++ service/location/generated.json | 1 + service/location/go.mod | 19 ++ service/location/go.sum | 18 ++ service/lookoutequipment/api_client.go | 1 + service/lookoutequipment/endpoints.go | 20 ++ .../lookoutequipment/endpoints_config_test.go | 139 +++++++++++++ service/lookoutequipment/generated.json | 1 + service/lookoutequipment/go.mod | 19 ++ service/lookoutequipment/go.sum | 18 ++ service/lookoutmetrics/api_client.go | 1 + service/lookoutmetrics/endpoints.go | 20 ++ .../lookoutmetrics/endpoints_config_test.go | 139 +++++++++++++ service/lookoutmetrics/generated.json | 1 + service/lookoutmetrics/go.mod | 19 ++ service/lookoutmetrics/go.sum | 18 ++ service/lookoutvision/api_client.go | 1 + service/lookoutvision/endpoints.go | 20 ++ .../lookoutvision/endpoints_config_test.go | 139 +++++++++++++ service/lookoutvision/generated.json | 1 + service/lookoutvision/go.mod | 19 ++ service/lookoutvision/go.sum | 18 ++ service/m2/api_client.go | 1 + service/m2/endpoints.go | 20 ++ service/m2/endpoints_config_test.go | 139 +++++++++++++ service/m2/generated.json | 1 + service/m2/go.mod | 19 ++ service/m2/go.sum | 18 ++ service/machinelearning/api_client.go | 1 + service/machinelearning/endpoints.go | 20 ++ .../machinelearning/endpoints_config_test.go | 139 +++++++++++++ service/machinelearning/generated.json | 1 + service/machinelearning/go.mod | 19 ++ service/machinelearning/go.sum | 18 ++ service/macie/api_client.go | 1 + service/macie/endpoints.go | 20 ++ service/macie/endpoints_config_test.go | 139 +++++++++++++ service/macie/generated.json | 1 + service/macie/go.mod | 19 ++ service/macie/go.sum | 18 ++ service/macie2/api_client.go | 1 + service/macie2/endpoints.go | 20 ++ service/macie2/endpoints_config_test.go | 139 +++++++++++++ service/macie2/generated.json | 1 + service/macie2/go.mod | 19 ++ service/macie2/go.sum | 18 ++ service/managedblockchain/api_client.go | 1 + service/managedblockchain/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/managedblockchain/generated.json | 1 + service/managedblockchain/go.mod | 19 ++ service/managedblockchain/go.sum | 18 ++ service/managedblockchainquery/api_client.go | 1 + service/managedblockchainquery/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/managedblockchainquery/generated.json | 1 + service/managedblockchainquery/go.mod | 19 ++ service/managedblockchainquery/go.sum | 18 ++ service/marketplacecatalog/api_client.go | 1 + service/marketplacecatalog/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/marketplacecatalog/generated.json | 1 + service/marketplacecatalog/go.mod | 19 ++ service/marketplacecatalog/go.sum | 18 ++ .../api_client.go | 1 + .../marketplacecommerceanalytics/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + service/marketplacecommerceanalytics/go.mod | 19 ++ service/marketplacecommerceanalytics/go.sum | 18 ++ .../api_client.go | 1 + .../endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + service/marketplaceentitlementservice/go.mod | 19 ++ service/marketplaceentitlementservice/go.sum | 18 ++ service/marketplacemetering/api_client.go | 1 + service/marketplacemetering/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/marketplacemetering/generated.json | 1 + service/marketplacemetering/go.mod | 19 ++ service/marketplacemetering/go.sum | 18 ++ service/mediaconnect/api_client.go | 1 + service/mediaconnect/endpoints.go | 20 ++ service/mediaconnect/endpoints_config_test.go | 139 +++++++++++++ service/mediaconnect/generated.json | 1 + service/mediaconnect/go.mod | 19 ++ service/mediaconnect/go.sum | 18 ++ service/mediaconvert/api_client.go | 1 + service/mediaconvert/endpoints.go | 20 ++ service/mediaconvert/endpoints_config_test.go | 139 +++++++++++++ service/mediaconvert/generated.json | 1 + service/mediaconvert/go.mod | 19 ++ service/mediaconvert/go.sum | 18 ++ service/medialive/api_client.go | 1 + service/medialive/endpoints.go | 20 ++ service/medialive/endpoints_config_test.go | 139 +++++++++++++ service/medialive/generated.json | 1 + service/medialive/go.mod | 19 ++ service/medialive/go.sum | 18 ++ service/mediapackage/api_client.go | 1 + service/mediapackage/endpoints.go | 20 ++ service/mediapackage/endpoints_config_test.go | 139 +++++++++++++ service/mediapackage/generated.json | 1 + service/mediapackage/go.mod | 19 ++ service/mediapackage/go.sum | 18 ++ service/mediapackagev2/api_client.go | 1 + service/mediapackagev2/endpoints.go | 20 ++ .../mediapackagev2/endpoints_config_test.go | 139 +++++++++++++ service/mediapackagev2/generated.json | 1 + service/mediapackagev2/go.mod | 19 ++ service/mediapackagev2/go.sum | 18 ++ service/mediapackagevod/api_client.go | 1 + service/mediapackagevod/endpoints.go | 20 ++ .../mediapackagevod/endpoints_config_test.go | 139 +++++++++++++ service/mediapackagevod/generated.json | 1 + service/mediapackagevod/go.mod | 19 ++ service/mediapackagevod/go.sum | 18 ++ service/mediastore/api_client.go | 1 + service/mediastore/endpoints.go | 20 ++ service/mediastore/endpoints_config_test.go | 139 +++++++++++++ service/mediastore/generated.json | 1 + service/mediastore/go.mod | 19 ++ service/mediastore/go.sum | 18 ++ service/mediastoredata/api_client.go | 1 + service/mediastoredata/endpoints.go | 20 ++ .../mediastoredata/endpoints_config_test.go | 139 +++++++++++++ service/mediastoredata/generated.json | 1 + service/mediastoredata/go.mod | 19 ++ service/mediastoredata/go.sum | 18 ++ service/mediatailor/api_client.go | 1 + service/mediatailor/endpoints.go | 20 ++ service/mediatailor/endpoints_config_test.go | 139 +++++++++++++ service/mediatailor/generated.json | 1 + service/mediatailor/go.mod | 19 ++ service/mediatailor/go.sum | 18 ++ service/medicalimaging/api_client.go | 1 + service/medicalimaging/endpoints.go | 20 ++ .../medicalimaging/endpoints_config_test.go | 139 +++++++++++++ service/medicalimaging/generated.json | 1 + service/medicalimaging/go.mod | 19 ++ service/medicalimaging/go.sum | 18 ++ service/memorydb/api_client.go | 1 + service/memorydb/endpoints.go | 20 ++ service/memorydb/endpoints_config_test.go | 139 +++++++++++++ service/memorydb/generated.json | 1 + service/memorydb/go.mod | 19 ++ service/memorydb/go.sum | 18 ++ service/mgn/api_client.go | 1 + service/mgn/endpoints.go | 20 ++ service/mgn/endpoints_config_test.go | 139 +++++++++++++ service/mgn/generated.json | 1 + service/mgn/go.mod | 19 ++ service/mgn/go.sum | 18 ++ service/migrationhub/api_client.go | 1 + service/migrationhub/endpoints.go | 20 ++ service/migrationhub/endpoints_config_test.go | 139 +++++++++++++ service/migrationhub/generated.json | 1 + service/migrationhub/go.mod | 19 ++ service/migrationhub/go.sum | 18 ++ service/migrationhubconfig/api_client.go | 1 + service/migrationhubconfig/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/migrationhubconfig/generated.json | 1 + service/migrationhubconfig/go.mod | 19 ++ service/migrationhubconfig/go.sum | 18 ++ .../migrationhuborchestrator/api_client.go | 1 + service/migrationhuborchestrator/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../migrationhuborchestrator/generated.json | 1 + service/migrationhuborchestrator/go.mod | 19 ++ service/migrationhuborchestrator/go.sum | 18 ++ .../migrationhubrefactorspaces/api_client.go | 1 + .../migrationhubrefactorspaces/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../migrationhubrefactorspaces/generated.json | 1 + service/migrationhubrefactorspaces/go.mod | 19 ++ service/migrationhubrefactorspaces/go.sum | 18 ++ service/migrationhubstrategy/api_client.go | 1 + service/migrationhubstrategy/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/migrationhubstrategy/generated.json | 1 + service/migrationhubstrategy/go.mod | 19 ++ service/migrationhubstrategy/go.sum | 18 ++ service/mobile/api_client.go | 1 + service/mobile/endpoints.go | 20 ++ service/mobile/endpoints_config_test.go | 139 +++++++++++++ service/mobile/generated.json | 1 + service/mobile/go.mod | 19 ++ service/mobile/go.sum | 18 ++ service/mq/api_client.go | 1 + service/mq/endpoints.go | 20 ++ service/mq/endpoints_config_test.go | 139 +++++++++++++ service/mq/generated.json | 1 + service/mq/go.mod | 19 ++ service/mq/go.sum | 18 ++ service/mturk/api_client.go | 1 + service/mturk/endpoints.go | 20 ++ service/mturk/endpoints_config_test.go | 139 +++++++++++++ service/mturk/generated.json | 1 + service/mturk/go.mod | 19 ++ service/mturk/go.sum | 18 ++ service/mwaa/api_client.go | 1 + service/mwaa/endpoints.go | 20 ++ service/mwaa/endpoints_config_test.go | 139 +++++++++++++ service/mwaa/generated.json | 1 + service/mwaa/go.mod | 19 ++ service/mwaa/go.sum | 18 ++ service/neptune/api_client.go | 1 + service/neptune/endpoints.go | 20 ++ service/neptune/endpoints_config_test.go | 139 +++++++++++++ service/neptune/generated.json | 1 + service/neptune/go.mod | 17 ++ service/neptune/go.sum | 16 ++ service/neptunedata/api_client.go | 1 + service/neptunedata/endpoints.go | 20 ++ service/neptunedata/endpoints_config_test.go | 139 +++++++++++++ service/neptunedata/generated.json | 1 + service/neptunedata/go.mod | 19 ++ service/neptunedata/go.sum | 18 ++ service/networkfirewall/api_client.go | 1 + service/networkfirewall/endpoints.go | 20 ++ .../networkfirewall/endpoints_config_test.go | 139 +++++++++++++ service/networkfirewall/generated.json | 1 + service/networkfirewall/go.mod | 19 ++ service/networkfirewall/go.sum | 18 ++ service/networkmanager/api_client.go | 1 + service/networkmanager/endpoints.go | 20 ++ .../networkmanager/endpoints_config_test.go | 139 +++++++++++++ service/networkmanager/generated.json | 1 + service/networkmanager/go.mod | 19 ++ service/networkmanager/go.sum | 18 ++ service/nimble/api_client.go | 1 + service/nimble/endpoints.go | 20 ++ service/nimble/endpoints_config_test.go | 139 +++++++++++++ service/nimble/generated.json | 1 + service/nimble/go.mod | 19 ++ service/nimble/go.sum | 18 ++ service/oam/api_client.go | 1 + service/oam/endpoints.go | 20 ++ service/oam/endpoints_config_test.go | 139 +++++++++++++ service/oam/generated.json | 1 + service/oam/go.mod | 19 ++ service/oam/go.sum | 18 ++ service/omics/api_client.go | 1 + service/omics/endpoints.go | 20 ++ service/omics/endpoints_config_test.go | 139 +++++++++++++ service/omics/generated.json | 1 + service/omics/go.mod | 19 ++ service/omics/go.sum | 18 ++ service/opensearch/api_client.go | 1 + service/opensearch/endpoints.go | 20 ++ service/opensearch/endpoints_config_test.go | 139 +++++++++++++ service/opensearch/generated.json | 1 + service/opensearch/go.mod | 19 ++ service/opensearch/go.sum | 18 ++ service/opensearchserverless/api_client.go | 1 + service/opensearchserverless/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/opensearchserverless/generated.json | 1 + service/opensearchserverless/go.mod | 19 ++ service/opensearchserverless/go.sum | 18 ++ service/opsworks/api_client.go | 1 + service/opsworks/endpoints.go | 20 ++ service/opsworks/endpoints_config_test.go | 139 +++++++++++++ service/opsworks/generated.json | 1 + service/opsworks/go.mod | 19 ++ service/opsworks/go.sum | 18 ++ service/opsworkscm/api_client.go | 1 + service/opsworkscm/endpoints.go | 20 ++ service/opsworkscm/endpoints_config_test.go | 139 +++++++++++++ service/opsworkscm/generated.json | 1 + service/opsworkscm/go.mod | 19 ++ service/opsworkscm/go.sum | 18 ++ service/organizations/api_client.go | 1 + service/organizations/endpoints.go | 20 ++ .../organizations/endpoints_config_test.go | 139 +++++++++++++ service/organizations/generated.json | 1 + service/organizations/go.mod | 19 ++ service/organizations/go.sum | 18 ++ service/osis/api_client.go | 1 + service/osis/endpoints.go | 20 ++ service/osis/endpoints_config_test.go | 139 +++++++++++++ service/osis/generated.json | 1 + service/osis/go.mod | 19 ++ service/osis/go.sum | 18 ++ service/outposts/api_client.go | 1 + service/outposts/endpoints.go | 20 ++ service/outposts/endpoints_config_test.go | 139 +++++++++++++ service/outposts/generated.json | 1 + service/outposts/go.mod | 19 ++ service/outposts/go.sum | 18 ++ service/panorama/api_client.go | 1 + service/panorama/endpoints.go | 20 ++ service/panorama/endpoints_config_test.go | 139 +++++++++++++ service/panorama/generated.json | 1 + service/panorama/go.mod | 19 ++ service/panorama/go.sum | 18 ++ service/paymentcryptography/api_client.go | 1 + service/paymentcryptography/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/paymentcryptography/generated.json | 1 + service/paymentcryptography/go.mod | 19 ++ service/paymentcryptography/go.sum | 18 ++ service/paymentcryptographydata/api_client.go | 1 + service/paymentcryptographydata/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../paymentcryptographydata/generated.json | 1 + service/paymentcryptographydata/go.mod | 19 ++ service/paymentcryptographydata/go.sum | 18 ++ service/pcaconnectorad/api_client.go | 1 + service/pcaconnectorad/endpoints.go | 20 ++ .../pcaconnectorad/endpoints_config_test.go | 139 +++++++++++++ service/pcaconnectorad/generated.json | 1 + service/pcaconnectorad/go.mod | 19 ++ service/pcaconnectorad/go.sum | 18 ++ service/personalize/api_client.go | 1 + service/personalize/endpoints.go | 20 ++ service/personalize/endpoints_config_test.go | 139 +++++++++++++ service/personalize/generated.json | 1 + service/personalize/go.mod | 19 ++ service/personalize/go.sum | 18 ++ service/personalizeevents/api_client.go | 1 + service/personalizeevents/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/personalizeevents/generated.json | 1 + service/personalizeevents/go.mod | 19 ++ service/personalizeevents/go.sum | 18 ++ service/personalizeruntime/api_client.go | 1 + service/personalizeruntime/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/personalizeruntime/generated.json | 1 + service/personalizeruntime/go.mod | 19 ++ service/personalizeruntime/go.sum | 18 ++ service/pi/api_client.go | 1 + service/pi/endpoints.go | 20 ++ service/pi/endpoints_config_test.go | 139 +++++++++++++ service/pi/generated.json | 1 + service/pi/go.mod | 19 ++ service/pi/go.sum | 18 ++ service/pinpoint/api_client.go | 1 + service/pinpoint/endpoints.go | 20 ++ service/pinpoint/endpoints_config_test.go | 139 +++++++++++++ service/pinpoint/generated.json | 1 + service/pinpoint/go.mod | 19 ++ service/pinpoint/go.sum | 18 ++ service/pinpointemail/api_client.go | 1 + service/pinpointemail/endpoints.go | 20 ++ .../pinpointemail/endpoints_config_test.go | 139 +++++++++++++ service/pinpointemail/generated.json | 1 + service/pinpointemail/go.mod | 19 ++ service/pinpointemail/go.sum | 18 ++ service/pinpointsmsvoice/api_client.go | 1 + service/pinpointsmsvoice/endpoints.go | 20 ++ .../pinpointsmsvoice/endpoints_config_test.go | 139 +++++++++++++ service/pinpointsmsvoice/generated.json | 1 + service/pinpointsmsvoice/go.mod | 19 ++ service/pinpointsmsvoice/go.sum | 18 ++ service/pinpointsmsvoicev2/api_client.go | 1 + service/pinpointsmsvoicev2/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/pinpointsmsvoicev2/generated.json | 1 + service/pinpointsmsvoicev2/go.mod | 19 ++ service/pinpointsmsvoicev2/go.sum | 18 ++ service/pipes/api_client.go | 1 + service/pipes/endpoints.go | 20 ++ service/pipes/endpoints_config_test.go | 139 +++++++++++++ service/pipes/generated.json | 1 + service/pipes/go.mod | 19 ++ service/pipes/go.sum | 18 ++ service/polly/api_client.go | 1 + service/polly/endpoints.go | 20 ++ service/polly/endpoints_config_test.go | 139 +++++++++++++ service/polly/generated.json | 1 + service/polly/go.mod | 17 ++ service/polly/go.sum | 16 ++ service/pricing/api_client.go | 1 + service/pricing/endpoints.go | 20 ++ service/pricing/endpoints_config_test.go | 139 +++++++++++++ service/pricing/generated.json | 1 + service/pricing/go.mod | 19 ++ service/pricing/go.sum | 18 ++ service/privatenetworks/api_client.go | 1 + service/privatenetworks/endpoints.go | 20 ++ .../privatenetworks/endpoints_config_test.go | 139 +++++++++++++ service/privatenetworks/generated.json | 1 + service/privatenetworks/go.mod | 19 ++ service/privatenetworks/go.sum | 18 ++ service/proton/api_client.go | 1 + service/proton/endpoints.go | 20 ++ service/proton/endpoints_config_test.go | 139 +++++++++++++ service/proton/generated.json | 1 + service/proton/go.mod | 19 ++ service/proton/go.sum | 18 ++ service/qldb/api_client.go | 1 + service/qldb/endpoints.go | 20 ++ service/qldb/endpoints_config_test.go | 139 +++++++++++++ service/qldb/generated.json | 1 + service/qldb/go.mod | 19 ++ service/qldb/go.sum | 18 ++ service/qldbsession/api_client.go | 1 + service/qldbsession/endpoints.go | 20 ++ service/qldbsession/endpoints_config_test.go | 139 +++++++++++++ service/qldbsession/generated.json | 1 + service/qldbsession/go.mod | 19 ++ service/qldbsession/go.sum | 18 ++ service/quicksight/api_client.go | 1 + service/quicksight/endpoints.go | 20 ++ service/quicksight/endpoints_config_test.go | 139 +++++++++++++ service/quicksight/generated.json | 1 + service/quicksight/go.mod | 19 ++ service/quicksight/go.sum | 18 ++ service/ram/api_client.go | 1 + service/ram/endpoints.go | 20 ++ service/ram/endpoints_config_test.go | 139 +++++++++++++ service/ram/generated.json | 1 + service/ram/go.mod | 19 ++ service/ram/go.sum | 18 ++ service/rbin/api_client.go | 1 + service/rbin/endpoints.go | 20 ++ service/rbin/endpoints_config_test.go | 139 +++++++++++++ service/rbin/generated.json | 1 + service/rbin/go.mod | 19 ++ service/rbin/go.sum | 18 ++ service/rds/api_client.go | 1 + service/rds/endpoints.go | 20 ++ service/rds/endpoints_config_test.go | 139 +++++++++++++ service/rds/generated.json | 1 + service/rds/go.mod | 17 ++ service/rds/go.sum | 16 ++ service/rdsdata/api_client.go | 1 + service/rdsdata/endpoints.go | 20 ++ service/rdsdata/endpoints_config_test.go | 139 +++++++++++++ service/rdsdata/generated.json | 1 + service/rdsdata/go.mod | 19 ++ service/rdsdata/go.sum | 18 ++ service/redshift/api_client.go | 1 + service/redshift/endpoints.go | 20 ++ service/redshift/endpoints_config_test.go | 139 +++++++++++++ service/redshift/generated.json | 1 + service/redshift/go.mod | 19 ++ service/redshift/go.sum | 18 ++ service/redshiftdata/api_client.go | 1 + service/redshiftdata/endpoints.go | 20 ++ service/redshiftdata/endpoints_config_test.go | 139 +++++++++++++ service/redshiftdata/generated.json | 1 + service/redshiftdata/go.mod | 19 ++ service/redshiftdata/go.sum | 18 ++ service/redshiftserverless/api_client.go | 1 + service/redshiftserverless/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/redshiftserverless/generated.json | 1 + service/redshiftserverless/go.mod | 19 ++ service/redshiftserverless/go.sum | 18 ++ service/rekognition/api_client.go | 1 + service/rekognition/endpoints.go | 20 ++ service/rekognition/endpoints_config_test.go | 139 +++++++++++++ service/rekognition/generated.json | 1 + service/rekognition/go.mod | 19 ++ service/rekognition/go.sum | 18 ++ service/resiliencehub/api_client.go | 1 + service/resiliencehub/endpoints.go | 20 ++ .../resiliencehub/endpoints_config_test.go | 139 +++++++++++++ service/resiliencehub/generated.json | 1 + service/resiliencehub/go.mod | 19 ++ service/resiliencehub/go.sum | 18 ++ service/resourceexplorer2/api_client.go | 1 + service/resourceexplorer2/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/resourceexplorer2/generated.json | 1 + service/resourceexplorer2/go.mod | 19 ++ service/resourceexplorer2/go.sum | 18 ++ service/resourcegroups/api_client.go | 1 + service/resourcegroups/endpoints.go | 20 ++ .../resourcegroups/endpoints_config_test.go | 139 +++++++++++++ service/resourcegroups/generated.json | 1 + service/resourcegroups/go.mod | 19 ++ service/resourcegroups/go.sum | 18 ++ .../resourcegroupstaggingapi/api_client.go | 1 + service/resourcegroupstaggingapi/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../resourcegroupstaggingapi/generated.json | 1 + service/resourcegroupstaggingapi/go.mod | 19 ++ service/resourcegroupstaggingapi/go.sum | 18 ++ service/robomaker/api_client.go | 1 + service/robomaker/endpoints.go | 20 ++ service/robomaker/endpoints_config_test.go | 139 +++++++++++++ service/robomaker/generated.json | 1 + service/robomaker/go.mod | 19 ++ service/robomaker/go.sum | 18 ++ service/rolesanywhere/api_client.go | 1 + service/rolesanywhere/endpoints.go | 20 ++ .../rolesanywhere/endpoints_config_test.go | 139 +++++++++++++ service/rolesanywhere/generated.json | 1 + service/rolesanywhere/go.mod | 19 ++ service/rolesanywhere/go.sum | 18 ++ service/route53/api_client.go | 1 + service/route53/endpoints.go | 20 ++ service/route53/endpoints_config_test.go | 139 +++++++++++++ service/route53/generated.json | 1 + service/route53/go.mod | 19 ++ service/route53/go.sum | 18 ++ service/route53domains/api_client.go | 1 + service/route53domains/endpoints.go | 20 ++ .../route53domains/endpoints_config_test.go | 139 +++++++++++++ service/route53domains/generated.json | 1 + service/route53domains/go.mod | 19 ++ service/route53domains/go.sum | 18 ++ service/route53recoverycluster/api_client.go | 1 + service/route53recoverycluster/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/route53recoverycluster/generated.json | 1 + service/route53recoverycluster/go.mod | 19 ++ service/route53recoverycluster/go.sum | 18 ++ .../api_client.go | 1 + .../route53recoverycontrolconfig/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + service/route53recoverycontrolconfig/go.mod | 19 ++ service/route53recoverycontrolconfig/go.sum | 18 ++ .../route53recoveryreadiness/api_client.go | 1 + service/route53recoveryreadiness/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../route53recoveryreadiness/generated.json | 1 + service/route53recoveryreadiness/go.mod | 19 ++ service/route53recoveryreadiness/go.sum | 18 ++ service/route53resolver/api_client.go | 1 + service/route53resolver/endpoints.go | 20 ++ .../route53resolver/endpoints_config_test.go | 139 +++++++++++++ service/route53resolver/generated.json | 1 + service/route53resolver/go.mod | 19 ++ service/route53resolver/go.sum | 18 ++ service/rum/api_client.go | 1 + service/rum/endpoints.go | 20 ++ service/rum/endpoints_config_test.go | 139 +++++++++++++ service/rum/generated.json | 1 + service/rum/go.mod | 19 ++ service/rum/go.sum | 18 ++ service/s3/endpoints.go | 16 +- service/s3/endpoints_config_test.go | 192 +++++++++--------- service/s3/go.mod | 19 +- service/s3/internal/configtesting/go.mod | 2 + service/s3/internal/configtesting/go.sum | 2 + service/s3control/endpoints.go | 16 +- service/s3control/endpoints_config_test.go | 192 +++++++++--------- service/s3control/go.mod | 19 +- service/s3outposts/endpoints.go | 16 +- service/s3outposts/endpoints_config_test.go | 192 +++++++++--------- service/s3outposts/go.mod | 19 +- service/sagemaker/api_client.go | 1 + service/sagemaker/endpoints.go | 20 ++ service/sagemaker/endpoints_config_test.go | 139 +++++++++++++ service/sagemaker/generated.json | 1 + service/sagemaker/go.mod | 19 ++ service/sagemaker/go.sum | 18 ++ service/sagemakera2iruntime/api_client.go | 1 + service/sagemakera2iruntime/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/sagemakera2iruntime/generated.json | 1 + service/sagemakera2iruntime/go.mod | 19 ++ service/sagemakera2iruntime/go.sum | 18 ++ service/sagemakeredge/api_client.go | 1 + service/sagemakeredge/endpoints.go | 20 ++ .../sagemakeredge/endpoints_config_test.go | 139 +++++++++++++ service/sagemakeredge/generated.json | 1 + service/sagemakeredge/go.mod | 19 ++ service/sagemakeredge/go.sum | 18 ++ .../api_client.go | 1 + .../sagemakerfeaturestoreruntime/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + service/sagemakerfeaturestoreruntime/go.mod | 19 ++ service/sagemakerfeaturestoreruntime/go.sum | 18 ++ service/sagemakergeospatial/api_client.go | 1 + service/sagemakergeospatial/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/sagemakergeospatial/generated.json | 1 + service/sagemakergeospatial/go.mod | 19 ++ service/sagemakergeospatial/go.sum | 18 ++ service/sagemakermetrics/api_client.go | 1 + service/sagemakermetrics/endpoints.go | 20 ++ .../sagemakermetrics/endpoints_config_test.go | 139 +++++++++++++ service/sagemakermetrics/generated.json | 1 + service/sagemakermetrics/go.mod | 19 ++ service/sagemakermetrics/go.sum | 18 ++ service/sagemakerruntime/api_client.go | 1 + service/sagemakerruntime/endpoints.go | 20 ++ .../sagemakerruntime/endpoints_config_test.go | 139 +++++++++++++ service/sagemakerruntime/generated.json | 1 + service/sagemakerruntime/go.mod | 19 ++ service/sagemakerruntime/go.sum | 18 ++ service/savingsplans/api_client.go | 1 + service/savingsplans/endpoints.go | 20 ++ service/savingsplans/endpoints_config_test.go | 139 +++++++++++++ service/savingsplans/generated.json | 1 + service/savingsplans/go.mod | 19 ++ service/savingsplans/go.sum | 18 ++ service/scheduler/api_client.go | 1 + service/scheduler/endpoints.go | 20 ++ service/scheduler/endpoints_config_test.go | 139 +++++++++++++ service/scheduler/generated.json | 1 + service/scheduler/go.mod | 19 ++ service/scheduler/go.sum | 18 ++ service/schemas/api_client.go | 1 + service/schemas/endpoints.go | 20 ++ service/schemas/endpoints_config_test.go | 139 +++++++++++++ service/schemas/generated.json | 1 + service/schemas/go.mod | 19 ++ service/schemas/go.sum | 18 ++ service/secretsmanager/api_client.go | 1 + service/secretsmanager/endpoints.go | 20 ++ .../secretsmanager/endpoints_config_test.go | 139 +++++++++++++ service/secretsmanager/generated.json | 1 + service/secretsmanager/go.mod | 19 ++ service/secretsmanager/go.sum | 18 ++ service/securityhub/api_client.go | 1 + service/securityhub/endpoints.go | 20 ++ service/securityhub/endpoints_config_test.go | 139 +++++++++++++ service/securityhub/generated.json | 1 + service/securityhub/go.mod | 19 ++ service/securityhub/go.sum | 18 ++ service/securitylake/api_client.go | 1 + service/securitylake/endpoints.go | 20 ++ service/securitylake/endpoints_config_test.go | 139 +++++++++++++ service/securitylake/generated.json | 1 + service/securitylake/go.mod | 19 ++ service/securitylake/go.sum | 18 ++ .../api_client.go | 1 + .../endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../generated.json | 1 + .../serverlessapplicationrepository/go.mod | 19 ++ .../serverlessapplicationrepository/go.sum | 18 ++ service/servicecatalog/api_client.go | 1 + service/servicecatalog/endpoints.go | 20 ++ .../servicecatalog/endpoints_config_test.go | 139 +++++++++++++ service/servicecatalog/generated.json | 1 + service/servicecatalog/go.mod | 19 ++ service/servicecatalog/go.sum | 18 ++ .../servicecatalogappregistry/api_client.go | 1 + .../servicecatalogappregistry/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ .../servicecatalogappregistry/generated.json | 1 + service/servicecatalogappregistry/go.mod | 19 ++ service/servicecatalogappregistry/go.sum | 18 ++ service/servicediscovery/api_client.go | 1 + service/servicediscovery/endpoints.go | 20 ++ .../servicediscovery/endpoints_config_test.go | 139 +++++++++++++ service/servicediscovery/generated.json | 1 + service/servicediscovery/go.mod | 19 ++ service/servicediscovery/go.sum | 18 ++ service/servicequotas/api_client.go | 1 + service/servicequotas/endpoints.go | 20 ++ .../servicequotas/endpoints_config_test.go | 139 +++++++++++++ service/servicequotas/generated.json | 1 + service/servicequotas/go.mod | 19 ++ service/servicequotas/go.sum | 18 ++ service/ses/api_client.go | 1 + service/ses/endpoints.go | 20 ++ service/ses/endpoints_config_test.go | 139 +++++++++++++ service/ses/generated.json | 1 + service/ses/go.mod | 19 ++ service/ses/go.sum | 18 ++ service/sesv2/api_client.go | 1 + service/sesv2/endpoints.go | 20 ++ service/sesv2/endpoints_config_test.go | 139 +++++++++++++ service/sesv2/generated.json | 1 + service/sesv2/go.mod | 19 ++ service/sesv2/go.sum | 18 ++ service/sfn/api_client.go | 1 + service/sfn/endpoints.go | 20 ++ service/sfn/endpoints_config_test.go | 139 +++++++++++++ service/sfn/generated.json | 1 + service/sfn/go.mod | 19 ++ service/sfn/go.sum | 18 ++ service/shield/api_client.go | 1 + service/shield/endpoints.go | 20 ++ service/shield/endpoints_config_test.go | 139 +++++++++++++ service/shield/generated.json | 1 + service/shield/go.mod | 19 ++ service/shield/go.sum | 18 ++ service/signer/api_client.go | 1 + service/signer/endpoints.go | 20 ++ service/signer/endpoints_config_test.go | 139 +++++++++++++ service/signer/generated.json | 1 + service/signer/go.mod | 19 ++ service/signer/go.sum | 18 ++ service/simspaceweaver/api_client.go | 1 + service/simspaceweaver/endpoints.go | 20 ++ .../simspaceweaver/endpoints_config_test.go | 139 +++++++++++++ service/simspaceweaver/generated.json | 1 + service/simspaceweaver/go.mod | 19 ++ service/simspaceweaver/go.sum | 18 ++ service/sms/api_client.go | 1 + service/sms/endpoints.go | 20 ++ service/sms/endpoints_config_test.go | 139 +++++++++++++ service/sms/generated.json | 1 + service/sms/go.mod | 19 ++ service/sms/go.sum | 18 ++ service/snowball/api_client.go | 1 + service/snowball/endpoints.go | 20 ++ service/snowball/endpoints_config_test.go | 139 +++++++++++++ service/snowball/generated.json | 1 + service/snowball/go.mod | 19 ++ service/snowball/go.sum | 18 ++ service/snowdevicemanagement/api_client.go | 1 + service/snowdevicemanagement/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/snowdevicemanagement/generated.json | 1 + service/snowdevicemanagement/go.mod | 19 ++ service/snowdevicemanagement/go.sum | 18 ++ service/sns/api_client.go | 1 + service/sns/endpoints.go | 20 ++ service/sns/endpoints_config_test.go | 139 +++++++++++++ service/sns/generated.json | 1 + service/sns/go.mod | 19 ++ service/sns/go.sum | 18 ++ service/sqs/api_client.go | 1 + service/sqs/endpoints.go | 20 ++ service/sqs/endpoints_config_test.go | 139 +++++++++++++ service/sqs/generated.json | 1 + service/sqs/go.mod | 19 ++ service/sqs/go.sum | 18 ++ service/ssm/api_client.go | 1 + service/ssm/endpoints.go | 20 ++ service/ssm/endpoints_config_test.go | 139 +++++++++++++ service/ssm/generated.json | 1 + service/ssm/go.mod | 19 ++ service/ssm/go.sum | 18 ++ service/ssmcontacts/api_client.go | 1 + service/ssmcontacts/endpoints.go | 20 ++ service/ssmcontacts/endpoints_config_test.go | 139 +++++++++++++ service/ssmcontacts/generated.json | 1 + service/ssmcontacts/go.mod | 19 ++ service/ssmcontacts/go.sum | 18 ++ service/ssmincidents/api_client.go | 1 + service/ssmincidents/endpoints.go | 20 ++ service/ssmincidents/endpoints_config_test.go | 139 +++++++++++++ service/ssmincidents/generated.json | 1 + service/ssmincidents/go.mod | 19 ++ service/ssmincidents/go.sum | 18 ++ service/ssmsap/api_client.go | 1 + service/ssmsap/endpoints.go | 20 ++ service/ssmsap/endpoints_config_test.go | 139 +++++++++++++ service/ssmsap/generated.json | 1 + service/ssmsap/go.mod | 19 ++ service/ssmsap/go.sum | 18 ++ service/sso/api_client.go | 1 + service/sso/endpoints.go | 20 ++ service/sso/endpoints_config_test.go | 139 +++++++++++++ service/sso/generated.json | 1 + service/sso/go.mod | 19 ++ service/sso/go.sum | 17 ++ service/ssoadmin/api_client.go | 1 + service/ssoadmin/endpoints.go | 20 ++ service/ssoadmin/endpoints_config_test.go | 139 +++++++++++++ service/ssoadmin/generated.json | 1 + service/ssoadmin/go.mod | 19 ++ service/ssoadmin/go.sum | 18 ++ service/ssooidc/api_client.go | 1 + service/ssooidc/endpoints.go | 20 ++ service/ssooidc/endpoints_config_test.go | 139 +++++++++++++ service/ssooidc/generated.json | 1 + service/ssooidc/go.mod | 19 ++ service/ssooidc/go.sum | 17 ++ service/storagegateway/api_client.go | 1 + service/storagegateway/endpoints.go | 20 ++ .../storagegateway/endpoints_config_test.go | 139 +++++++++++++ service/storagegateway/generated.json | 1 + service/storagegateway/go.mod | 19 ++ service/storagegateway/go.sum | 18 ++ service/sts/api_client.go | 1 + service/sts/endpoints.go | 20 ++ service/sts/endpoints_config_test.go | 139 +++++++++++++ service/sts/generated.json | 1 + service/sts/go.mod | 17 ++ service/sts/go.sum | 15 ++ service/support/api_client.go | 1 + service/support/endpoints.go | 20 ++ service/support/endpoints_config_test.go | 139 +++++++++++++ service/support/generated.json | 1 + service/support/go.mod | 19 ++ service/support/go.sum | 18 ++ service/supportapp/api_client.go | 1 + service/supportapp/endpoints.go | 20 ++ service/supportapp/endpoints_config_test.go | 139 +++++++++++++ service/supportapp/generated.json | 1 + service/supportapp/go.mod | 19 ++ service/supportapp/go.sum | 18 ++ service/swf/api_client.go | 1 + service/swf/endpoints.go | 20 ++ service/swf/endpoints_config_test.go | 139 +++++++++++++ service/swf/generated.json | 1 + service/swf/go.mod | 19 ++ service/swf/go.sum | 18 ++ service/synthetics/api_client.go | 1 + service/synthetics/endpoints.go | 20 ++ service/synthetics/endpoints_config_test.go | 139 +++++++++++++ service/synthetics/generated.json | 1 + service/synthetics/go.mod | 19 ++ service/synthetics/go.sum | 18 ++ service/textract/api_client.go | 1 + service/textract/endpoints.go | 20 ++ service/textract/endpoints_config_test.go | 139 +++++++++++++ service/textract/generated.json | 1 + service/textract/go.mod | 19 ++ service/textract/go.sum | 18 ++ service/timestreamquery/api_client.go | 1 + service/timestreamquery/endpoints.go | 20 ++ .../timestreamquery/endpoints_config_test.go | 139 +++++++++++++ service/timestreamquery/generated.json | 1 + service/timestreamquery/go.mod | 19 ++ service/timestreamquery/go.sum | 18 ++ service/timestreamwrite/api_client.go | 1 + service/timestreamwrite/endpoints.go | 20 ++ .../timestreamwrite/endpoints_config_test.go | 139 +++++++++++++ service/timestreamwrite/generated.json | 1 + service/timestreamwrite/go.mod | 19 ++ service/timestreamwrite/go.sum | 18 ++ service/tnb/api_client.go | 1 + service/tnb/endpoints.go | 20 ++ service/tnb/endpoints_config_test.go | 139 +++++++++++++ service/tnb/generated.json | 1 + service/tnb/go.mod | 19 ++ service/tnb/go.sum | 18 ++ service/transcribe/api_client.go | 1 + service/transcribe/endpoints.go | 20 ++ service/transcribe/endpoints_config_test.go | 139 +++++++++++++ service/transcribe/generated.json | 1 + service/transcribe/go.mod | 19 ++ service/transcribe/go.sum | 18 ++ service/transcribestreaming/api_client.go | 1 + service/transcribestreaming/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/transcribestreaming/generated.json | 1 + service/transcribestreaming/go.mod | 19 ++ service/transcribestreaming/go.sum | 18 ++ .../internal/testing/go.mod | 6 + .../internal/testing/go.sum | 6 + service/transfer/api_client.go | 1 + service/transfer/endpoints.go | 20 ++ service/transfer/endpoints_config_test.go | 139 +++++++++++++ service/transfer/generated.json | 1 + service/transfer/go.mod | 19 ++ service/transfer/go.sum | 18 ++ service/translate/api_client.go | 1 + service/translate/endpoints.go | 20 ++ service/translate/endpoints_config_test.go | 139 +++++++++++++ service/translate/generated.json | 1 + service/translate/go.mod | 19 ++ service/translate/go.sum | 18 ++ service/verifiedpermissions/api_client.go | 1 + service/verifiedpermissions/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/verifiedpermissions/generated.json | 1 + service/verifiedpermissions/go.mod | 19 ++ service/verifiedpermissions/go.sum | 18 ++ service/voiceid/api_client.go | 1 + service/voiceid/endpoints.go | 20 ++ service/voiceid/endpoints_config_test.go | 139 +++++++++++++ service/voiceid/generated.json | 1 + service/voiceid/go.mod | 19 ++ service/voiceid/go.sum | 18 ++ service/vpclattice/api_client.go | 1 + service/vpclattice/endpoints.go | 20 ++ service/vpclattice/endpoints_config_test.go | 139 +++++++++++++ service/vpclattice/generated.json | 1 + service/vpclattice/go.mod | 19 ++ service/vpclattice/go.sum | 18 ++ service/waf/api_client.go | 1 + service/waf/endpoints.go | 20 ++ service/waf/endpoints_config_test.go | 139 +++++++++++++ service/waf/generated.json | 1 + service/waf/go.mod | 19 ++ service/waf/go.sum | 18 ++ service/wafregional/api_client.go | 1 + service/wafregional/endpoints.go | 20 ++ service/wafregional/endpoints_config_test.go | 139 +++++++++++++ service/wafregional/generated.json | 1 + service/wafregional/go.mod | 19 ++ service/wafregional/go.sum | 18 ++ service/wafv2/api_client.go | 1 + service/wafv2/endpoints.go | 20 ++ service/wafv2/endpoints_config_test.go | 139 +++++++++++++ service/wafv2/generated.json | 1 + service/wafv2/go.mod | 19 ++ service/wafv2/go.sum | 18 ++ service/wellarchitected/api_client.go | 1 + service/wellarchitected/endpoints.go | 20 ++ .../wellarchitected/endpoints_config_test.go | 139 +++++++++++++ service/wellarchitected/generated.json | 1 + service/wellarchitected/go.mod | 19 ++ service/wellarchitected/go.sum | 18 ++ service/wisdom/api_client.go | 1 + service/wisdom/endpoints.go | 20 ++ service/wisdom/endpoints_config_test.go | 139 +++++++++++++ service/wisdom/generated.json | 1 + service/wisdom/go.mod | 19 ++ service/wisdom/go.sum | 18 ++ service/workdocs/api_client.go | 1 + service/workdocs/endpoints.go | 20 ++ service/workdocs/endpoints_config_test.go | 139 +++++++++++++ service/workdocs/generated.json | 1 + service/workdocs/go.mod | 19 ++ service/workdocs/go.sum | 18 ++ service/worklink/api_client.go | 1 + service/worklink/endpoints.go | 20 ++ service/worklink/endpoints_config_test.go | 139 +++++++++++++ service/worklink/generated.json | 1 + service/worklink/go.mod | 19 ++ service/worklink/go.sum | 18 ++ service/workmail/api_client.go | 1 + service/workmail/endpoints.go | 20 ++ service/workmail/endpoints_config_test.go | 139 +++++++++++++ service/workmail/generated.json | 1 + service/workmail/go.mod | 19 ++ service/workmail/go.sum | 18 ++ service/workmailmessageflow/api_client.go | 1 + service/workmailmessageflow/endpoints.go | 20 ++ .../endpoints_config_test.go | 139 +++++++++++++ service/workmailmessageflow/generated.json | 1 + service/workmailmessageflow/go.mod | 19 ++ service/workmailmessageflow/go.sum | 18 ++ service/workspaces/api_client.go | 1 + service/workspaces/endpoints.go | 20 ++ service/workspaces/endpoints_config_test.go | 139 +++++++++++++ service/workspaces/generated.json | 1 + service/workspaces/go.mod | 19 ++ service/workspaces/go.sum | 18 ++ service/workspacesweb/api_client.go | 1 + service/workspacesweb/endpoints.go | 20 ++ .../workspacesweb/endpoints_config_test.go | 139 +++++++++++++ service/workspacesweb/generated.json | 1 + service/workspacesweb/go.mod | 19 ++ service/workspacesweb/go.sum | 18 ++ service/xray/api_client.go | 1 + service/xray/endpoints.go | 20 ++ service/xray/endpoints_config_test.go | 139 +++++++++++++ service/xray/generated.json | 1 + service/xray/go.mod | 19 ++ service/xray/go.sum | 18 ++ 2192 files changed, 71531 insertions(+), 446 deletions(-) create mode 100644 internal/protocoltest/awsrestjson/endpoints_config_test.go create mode 100644 internal/protocoltest/ec2query/endpoints_config_test.go create mode 100644 internal/protocoltest/jsonrpc/endpoints_config_test.go create mode 100644 internal/protocoltest/jsonrpc10/endpoints_config_test.go create mode 100644 internal/protocoltest/query/endpoints_config_test.go create mode 100644 internal/protocoltest/restxml/endpoints_config_test.go create mode 100644 internal/protocoltest/restxmlwithnamespace/endpoints_config_test.go create mode 100644 service/accessanalyzer/endpoints_config_test.go create mode 100644 service/account/endpoints_config_test.go create mode 100644 service/acm/endpoints_config_test.go create mode 100644 service/acmpca/endpoints_config_test.go create mode 100644 service/alexaforbusiness/endpoints_config_test.go create mode 100644 service/amp/endpoints_config_test.go create mode 100644 service/amplify/endpoints_config_test.go create mode 100644 service/amplifybackend/endpoints_config_test.go create mode 100644 service/amplifyuibuilder/endpoints_config_test.go create mode 100644 service/apigateway/endpoints_config_test.go create mode 100644 service/apigatewaymanagementapi/endpoints_config_test.go create mode 100644 service/apigatewayv2/endpoints_config_test.go create mode 100644 service/appconfig/endpoints_config_test.go create mode 100644 service/appconfigdata/endpoints_config_test.go create mode 100644 service/appfabric/endpoints_config_test.go create mode 100644 service/appflow/endpoints_config_test.go create mode 100644 service/appintegrations/endpoints_config_test.go create mode 100644 service/applicationautoscaling/endpoints_config_test.go create mode 100644 service/applicationcostprofiler/endpoints_config_test.go create mode 100644 service/applicationdiscoveryservice/endpoints_config_test.go create mode 100644 service/applicationinsights/endpoints_config_test.go create mode 100644 service/appmesh/endpoints_config_test.go create mode 100644 service/apprunner/endpoints_config_test.go create mode 100644 service/appstream/endpoints_config_test.go create mode 100644 service/appsync/endpoints_config_test.go create mode 100644 service/arczonalshift/endpoints_config_test.go create mode 100644 service/athena/endpoints_config_test.go create mode 100644 service/auditmanager/endpoints_config_test.go create mode 100644 service/autoscaling/endpoints_config_test.go create mode 100644 service/autoscalingplans/endpoints_config_test.go create mode 100644 service/backup/endpoints_config_test.go create mode 100644 service/backupgateway/endpoints_config_test.go create mode 100644 service/backupstorage/endpoints_config_test.go create mode 100644 service/batch/endpoints_config_test.go create mode 100644 service/bedrock/endpoints_config_test.go create mode 100644 service/bedrockruntime/endpoints_config_test.go create mode 100644 service/billingconductor/endpoints_config_test.go create mode 100644 service/braket/endpoints_config_test.go create mode 100644 service/budgets/endpoints_config_test.go create mode 100644 service/chime/endpoints_config_test.go create mode 100644 service/chimesdkidentity/endpoints_config_test.go create mode 100644 service/chimesdkmediapipelines/endpoints_config_test.go create mode 100644 service/chimesdkmeetings/endpoints_config_test.go create mode 100644 service/chimesdkmessaging/endpoints_config_test.go create mode 100644 service/chimesdkvoice/endpoints_config_test.go create mode 100644 service/cleanrooms/endpoints_config_test.go create mode 100644 service/cloud9/endpoints_config_test.go create mode 100644 service/cloudcontrol/endpoints_config_test.go create mode 100644 service/clouddirectory/endpoints_config_test.go create mode 100644 service/cloudformation/endpoints_config_test.go create mode 100644 service/cloudfront/endpoints_config_test.go create mode 100644 service/cloudhsm/endpoints_config_test.go create mode 100644 service/cloudhsmv2/endpoints_config_test.go create mode 100644 service/cloudsearch/endpoints_config_test.go create mode 100644 service/cloudsearchdomain/endpoints_config_test.go create mode 100644 service/cloudtrail/endpoints_config_test.go create mode 100644 service/cloudtraildata/endpoints_config_test.go create mode 100644 service/cloudwatch/endpoints_config_test.go create mode 100644 service/cloudwatchevents/endpoints_config_test.go create mode 100644 service/cloudwatchlogs/endpoints_config_test.go create mode 100644 service/codeartifact/endpoints_config_test.go create mode 100644 service/codebuild/endpoints_config_test.go create mode 100644 service/codecatalyst/endpoints_config_test.go create mode 100644 service/codecommit/endpoints_config_test.go create mode 100644 service/codedeploy/endpoints_config_test.go create mode 100644 service/codeguruprofiler/endpoints_config_test.go create mode 100644 service/codegurureviewer/endpoints_config_test.go create mode 100644 service/codegurusecurity/endpoints_config_test.go create mode 100644 service/codepipeline/endpoints_config_test.go create mode 100644 service/codestar/endpoints_config_test.go create mode 100644 service/codestarconnections/endpoints_config_test.go create mode 100644 service/codestarnotifications/endpoints_config_test.go create mode 100644 service/cognitoidentity/endpoints_config_test.go create mode 100644 service/cognitoidentityprovider/endpoints_config_test.go create mode 100644 service/cognitosync/endpoints_config_test.go create mode 100644 service/comprehend/endpoints_config_test.go create mode 100644 service/comprehendmedical/endpoints_config_test.go create mode 100644 service/computeoptimizer/endpoints_config_test.go create mode 100644 service/configservice/endpoints_config_test.go create mode 100644 service/connect/endpoints_config_test.go create mode 100644 service/connectcampaigns/endpoints_config_test.go create mode 100644 service/connectcases/endpoints_config_test.go create mode 100644 service/connectcontactlens/endpoints_config_test.go create mode 100644 service/connectparticipant/endpoints_config_test.go create mode 100644 service/controltower/endpoints_config_test.go create mode 100644 service/costandusagereportservice/endpoints_config_test.go create mode 100644 service/costexplorer/endpoints_config_test.go create mode 100644 service/customerprofiles/endpoints_config_test.go create mode 100644 service/databasemigrationservice/endpoints_config_test.go create mode 100644 service/databrew/endpoints_config_test.go create mode 100644 service/dataexchange/endpoints_config_test.go create mode 100644 service/datapipeline/endpoints_config_test.go create mode 100644 service/datasync/endpoints_config_test.go create mode 100644 service/datazone/endpoints_config_test.go create mode 100644 service/dax/endpoints_config_test.go create mode 100644 service/detective/endpoints_config_test.go create mode 100644 service/devicefarm/endpoints_config_test.go create mode 100644 service/devopsguru/endpoints_config_test.go create mode 100644 service/directconnect/endpoints_config_test.go create mode 100644 service/directoryservice/endpoints_config_test.go create mode 100644 service/dlm/endpoints_config_test.go create mode 100644 service/docdb/endpoints_config_test.go create mode 100644 service/docdbelastic/endpoints_config_test.go create mode 100644 service/drs/endpoints_config_test.go create mode 100644 service/dynamodb/endpoints_config_test.go create mode 100644 service/dynamodbstreams/endpoints_config_test.go create mode 100644 service/ebs/endpoints_config_test.go create mode 100644 service/ec2/endpoints_config_test.go create mode 100644 service/ec2instanceconnect/endpoints_config_test.go create mode 100644 service/ecr/endpoints_config_test.go create mode 100644 service/ecrpublic/endpoints_config_test.go create mode 100644 service/ecs/endpoints_config_test.go create mode 100644 service/efs/endpoints_config_test.go create mode 100644 service/eks/endpoints_config_test.go create mode 100644 service/elasticache/endpoints_config_test.go create mode 100644 service/elasticinference/endpoints_config_test.go create mode 100644 service/elasticloadbalancing/endpoints_config_test.go create mode 100644 service/elasticloadbalancingv2/endpoints_config_test.go create mode 100644 service/elasticsearchservice/endpoints_config_test.go create mode 100644 service/elastictranscoder/endpoints_config_test.go create mode 100644 service/emr/endpoints_config_test.go create mode 100644 service/emrcontainers/endpoints_config_test.go create mode 100644 service/emrserverless/endpoints_config_test.go create mode 100644 service/entityresolution/endpoints_config_test.go create mode 100644 service/evidently/endpoints_config_test.go create mode 100644 service/finspace/endpoints_config_test.go create mode 100644 service/finspacedata/endpoints_config_test.go create mode 100644 service/firehose/endpoints_config_test.go create mode 100644 service/fis/endpoints_config_test.go create mode 100644 service/fms/endpoints_config_test.go create mode 100644 service/forecast/endpoints_config_test.go create mode 100644 service/forecastquery/endpoints_config_test.go create mode 100644 service/frauddetector/endpoints_config_test.go create mode 100644 service/fsx/endpoints_config_test.go create mode 100644 service/gamelift/endpoints_config_test.go create mode 100644 service/glacier/endpoints_config_test.go create mode 100644 service/globalaccelerator/endpoints_config_test.go create mode 100644 service/glue/endpoints_config_test.go create mode 100644 service/grafana/endpoints_config_test.go create mode 100644 service/greengrass/endpoints_config_test.go create mode 100644 service/greengrassv2/endpoints_config_test.go create mode 100644 service/groundstation/endpoints_config_test.go create mode 100644 service/guardduty/endpoints_config_test.go create mode 100644 service/health/endpoints_config_test.go create mode 100644 service/healthlake/endpoints_config_test.go create mode 100644 service/honeycode/endpoints_config_test.go create mode 100644 service/iam/endpoints_config_test.go create mode 100644 service/identitystore/endpoints_config_test.go create mode 100644 service/imagebuilder/endpoints_config_test.go create mode 100644 service/inspector/endpoints_config_test.go create mode 100644 service/inspector2/endpoints_config_test.go create mode 100644 service/internetmonitor/endpoints_config_test.go create mode 100644 service/iot/endpoints_config_test.go create mode 100644 service/iot1clickdevicesservice/endpoints_config_test.go create mode 100644 service/iot1clickprojects/endpoints_config_test.go create mode 100644 service/iotanalytics/endpoints_config_test.go create mode 100644 service/iotdataplane/endpoints_config_test.go create mode 100644 service/iotdeviceadvisor/endpoints_config_test.go create mode 100644 service/iotevents/endpoints_config_test.go create mode 100644 service/ioteventsdata/endpoints_config_test.go create mode 100644 service/iotfleethub/endpoints_config_test.go create mode 100644 service/iotfleetwise/endpoints_config_test.go create mode 100644 service/iotjobsdataplane/endpoints_config_test.go create mode 100644 service/iotroborunner/endpoints_config_test.go create mode 100644 service/iotsecuretunneling/endpoints_config_test.go create mode 100644 service/iotsitewise/endpoints_config_test.go create mode 100644 service/iotthingsgraph/endpoints_config_test.go create mode 100644 service/iottwinmaker/endpoints_config_test.go create mode 100644 service/iotwireless/endpoints_config_test.go create mode 100644 service/ivs/endpoints_config_test.go create mode 100644 service/ivschat/endpoints_config_test.go create mode 100644 service/ivsrealtime/endpoints_config_test.go create mode 100644 service/kafka/endpoints_config_test.go create mode 100644 service/kafkaconnect/endpoints_config_test.go create mode 100644 service/kendra/endpoints_config_test.go create mode 100644 service/kendraranking/endpoints_config_test.go create mode 100644 service/keyspaces/endpoints_config_test.go create mode 100644 service/kinesis/endpoints_config_test.go create mode 100644 service/kinesisanalytics/endpoints_config_test.go create mode 100644 service/kinesisanalyticsv2/endpoints_config_test.go create mode 100644 service/kinesisvideo/endpoints_config_test.go create mode 100644 service/kinesisvideoarchivedmedia/endpoints_config_test.go create mode 100644 service/kinesisvideomedia/endpoints_config_test.go create mode 100644 service/kinesisvideosignaling/endpoints_config_test.go create mode 100644 service/kinesisvideowebrtcstorage/endpoints_config_test.go create mode 100644 service/kms/endpoints_config_test.go create mode 100644 service/lakeformation/endpoints_config_test.go create mode 100644 service/lambda/endpoints_config_test.go create mode 100644 service/lexmodelbuildingservice/endpoints_config_test.go create mode 100644 service/lexmodelsv2/endpoints_config_test.go create mode 100644 service/lexruntimeservice/endpoints_config_test.go create mode 100644 service/lexruntimev2/endpoints_config_test.go create mode 100644 service/licensemanager/endpoints_config_test.go create mode 100644 service/licensemanagerlinuxsubscriptions/endpoints_config_test.go create mode 100644 service/licensemanagerusersubscriptions/endpoints_config_test.go create mode 100644 service/lightsail/endpoints_config_test.go create mode 100644 service/location/endpoints_config_test.go create mode 100644 service/lookoutequipment/endpoints_config_test.go create mode 100644 service/lookoutmetrics/endpoints_config_test.go create mode 100644 service/lookoutvision/endpoints_config_test.go create mode 100644 service/m2/endpoints_config_test.go create mode 100644 service/machinelearning/endpoints_config_test.go create mode 100644 service/macie/endpoints_config_test.go create mode 100644 service/macie2/endpoints_config_test.go create mode 100644 service/managedblockchain/endpoints_config_test.go create mode 100644 service/managedblockchainquery/endpoints_config_test.go create mode 100644 service/marketplacecatalog/endpoints_config_test.go create mode 100644 service/marketplacecommerceanalytics/endpoints_config_test.go create mode 100644 service/marketplaceentitlementservice/endpoints_config_test.go create mode 100644 service/marketplacemetering/endpoints_config_test.go create mode 100644 service/mediaconnect/endpoints_config_test.go create mode 100644 service/mediaconvert/endpoints_config_test.go create mode 100644 service/medialive/endpoints_config_test.go create mode 100644 service/mediapackage/endpoints_config_test.go create mode 100644 service/mediapackagev2/endpoints_config_test.go create mode 100644 service/mediapackagevod/endpoints_config_test.go create mode 100644 service/mediastore/endpoints_config_test.go create mode 100644 service/mediastoredata/endpoints_config_test.go create mode 100644 service/mediatailor/endpoints_config_test.go create mode 100644 service/medicalimaging/endpoints_config_test.go create mode 100644 service/memorydb/endpoints_config_test.go create mode 100644 service/mgn/endpoints_config_test.go create mode 100644 service/migrationhub/endpoints_config_test.go create mode 100644 service/migrationhubconfig/endpoints_config_test.go create mode 100644 service/migrationhuborchestrator/endpoints_config_test.go create mode 100644 service/migrationhubrefactorspaces/endpoints_config_test.go create mode 100644 service/migrationhubstrategy/endpoints_config_test.go create mode 100644 service/mobile/endpoints_config_test.go create mode 100644 service/mq/endpoints_config_test.go create mode 100644 service/mturk/endpoints_config_test.go create mode 100644 service/mwaa/endpoints_config_test.go create mode 100644 service/neptune/endpoints_config_test.go create mode 100644 service/neptunedata/endpoints_config_test.go create mode 100644 service/networkfirewall/endpoints_config_test.go create mode 100644 service/networkmanager/endpoints_config_test.go create mode 100644 service/nimble/endpoints_config_test.go create mode 100644 service/oam/endpoints_config_test.go create mode 100644 service/omics/endpoints_config_test.go create mode 100644 service/opensearch/endpoints_config_test.go create mode 100644 service/opensearchserverless/endpoints_config_test.go create mode 100644 service/opsworks/endpoints_config_test.go create mode 100644 service/opsworkscm/endpoints_config_test.go create mode 100644 service/organizations/endpoints_config_test.go create mode 100644 service/osis/endpoints_config_test.go create mode 100644 service/outposts/endpoints_config_test.go create mode 100644 service/panorama/endpoints_config_test.go create mode 100644 service/paymentcryptography/endpoints_config_test.go create mode 100644 service/paymentcryptographydata/endpoints_config_test.go create mode 100644 service/pcaconnectorad/endpoints_config_test.go create mode 100644 service/personalize/endpoints_config_test.go create mode 100644 service/personalizeevents/endpoints_config_test.go create mode 100644 service/personalizeruntime/endpoints_config_test.go create mode 100644 service/pi/endpoints_config_test.go create mode 100644 service/pinpoint/endpoints_config_test.go create mode 100644 service/pinpointemail/endpoints_config_test.go create mode 100644 service/pinpointsmsvoice/endpoints_config_test.go create mode 100644 service/pinpointsmsvoicev2/endpoints_config_test.go create mode 100644 service/pipes/endpoints_config_test.go create mode 100644 service/polly/endpoints_config_test.go create mode 100644 service/pricing/endpoints_config_test.go create mode 100644 service/privatenetworks/endpoints_config_test.go create mode 100644 service/proton/endpoints_config_test.go create mode 100644 service/qldb/endpoints_config_test.go create mode 100644 service/qldbsession/endpoints_config_test.go create mode 100644 service/quicksight/endpoints_config_test.go create mode 100644 service/ram/endpoints_config_test.go create mode 100644 service/rbin/endpoints_config_test.go create mode 100644 service/rds/endpoints_config_test.go create mode 100644 service/rdsdata/endpoints_config_test.go create mode 100644 service/redshift/endpoints_config_test.go create mode 100644 service/redshiftdata/endpoints_config_test.go create mode 100644 service/redshiftserverless/endpoints_config_test.go create mode 100644 service/rekognition/endpoints_config_test.go create mode 100644 service/resiliencehub/endpoints_config_test.go create mode 100644 service/resourceexplorer2/endpoints_config_test.go create mode 100644 service/resourcegroups/endpoints_config_test.go create mode 100644 service/resourcegroupstaggingapi/endpoints_config_test.go create mode 100644 service/robomaker/endpoints_config_test.go create mode 100644 service/rolesanywhere/endpoints_config_test.go create mode 100644 service/route53/endpoints_config_test.go create mode 100644 service/route53domains/endpoints_config_test.go create mode 100644 service/route53recoverycluster/endpoints_config_test.go create mode 100644 service/route53recoverycontrolconfig/endpoints_config_test.go create mode 100644 service/route53recoveryreadiness/endpoints_config_test.go create mode 100644 service/route53resolver/endpoints_config_test.go create mode 100644 service/rum/endpoints_config_test.go create mode 100644 service/sagemaker/endpoints_config_test.go create mode 100644 service/sagemakera2iruntime/endpoints_config_test.go create mode 100644 service/sagemakeredge/endpoints_config_test.go create mode 100644 service/sagemakerfeaturestoreruntime/endpoints_config_test.go create mode 100644 service/sagemakergeospatial/endpoints_config_test.go create mode 100644 service/sagemakermetrics/endpoints_config_test.go create mode 100644 service/sagemakerruntime/endpoints_config_test.go create mode 100644 service/savingsplans/endpoints_config_test.go create mode 100644 service/scheduler/endpoints_config_test.go create mode 100644 service/schemas/endpoints_config_test.go create mode 100644 service/secretsmanager/endpoints_config_test.go create mode 100644 service/securityhub/endpoints_config_test.go create mode 100644 service/securitylake/endpoints_config_test.go create mode 100644 service/serverlessapplicationrepository/endpoints_config_test.go create mode 100644 service/servicecatalog/endpoints_config_test.go create mode 100644 service/servicecatalogappregistry/endpoints_config_test.go create mode 100644 service/servicediscovery/endpoints_config_test.go create mode 100644 service/servicequotas/endpoints_config_test.go create mode 100644 service/ses/endpoints_config_test.go create mode 100644 service/sesv2/endpoints_config_test.go create mode 100644 service/sfn/endpoints_config_test.go create mode 100644 service/shield/endpoints_config_test.go create mode 100644 service/signer/endpoints_config_test.go create mode 100644 service/simspaceweaver/endpoints_config_test.go create mode 100644 service/sms/endpoints_config_test.go create mode 100644 service/snowball/endpoints_config_test.go create mode 100644 service/snowdevicemanagement/endpoints_config_test.go create mode 100644 service/sns/endpoints_config_test.go create mode 100644 service/sqs/endpoints_config_test.go create mode 100644 service/ssm/endpoints_config_test.go create mode 100644 service/ssmcontacts/endpoints_config_test.go create mode 100644 service/ssmincidents/endpoints_config_test.go create mode 100644 service/ssmsap/endpoints_config_test.go create mode 100644 service/sso/endpoints_config_test.go create mode 100644 service/ssoadmin/endpoints_config_test.go create mode 100644 service/ssooidc/endpoints_config_test.go create mode 100644 service/storagegateway/endpoints_config_test.go create mode 100644 service/sts/endpoints_config_test.go create mode 100644 service/support/endpoints_config_test.go create mode 100644 service/supportapp/endpoints_config_test.go create mode 100644 service/swf/endpoints_config_test.go create mode 100644 service/synthetics/endpoints_config_test.go create mode 100644 service/textract/endpoints_config_test.go create mode 100644 service/timestreamquery/endpoints_config_test.go create mode 100644 service/timestreamwrite/endpoints_config_test.go create mode 100644 service/tnb/endpoints_config_test.go create mode 100644 service/transcribe/endpoints_config_test.go create mode 100644 service/transcribestreaming/endpoints_config_test.go create mode 100644 service/transfer/endpoints_config_test.go create mode 100644 service/translate/endpoints_config_test.go create mode 100644 service/verifiedpermissions/endpoints_config_test.go create mode 100644 service/voiceid/endpoints_config_test.go create mode 100644 service/vpclattice/endpoints_config_test.go create mode 100644 service/waf/endpoints_config_test.go create mode 100644 service/wafregional/endpoints_config_test.go create mode 100644 service/wafv2/endpoints_config_test.go create mode 100644 service/wellarchitected/endpoints_config_test.go create mode 100644 service/wisdom/endpoints_config_test.go create mode 100644 service/workdocs/endpoints_config_test.go create mode 100644 service/worklink/endpoints_config_test.go create mode 100644 service/workmail/endpoints_config_test.go create mode 100644 service/workmailmessageflow/endpoints_config_test.go create mode 100644 service/workspaces/endpoints_config_test.go create mode 100644 service/workspacesweb/endpoints_config_test.go create mode 100644 service/xray/endpoints_config_test.go diff --git a/config/go.mod b/config/go.mod index a0eaa108ca6..c308e9687e3 100644 --- a/config/go.mod +++ b/config/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/credentials v1.13.43 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 @@ -16,12 +17,16 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../ +replace github.com/aws/aws-sdk-go-v2/config => ../config/ + replace github.com/aws/aws-sdk-go-v2/credentials => ../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../internal/ini/ diff --git a/config/go.sum b/config/go.sum index a646f1d3099..bba4e0fe95b 100644 --- a/config/go.sum +++ b/config/go.sum @@ -1,3 +1,6 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/credentials/go.mod b/credentials/go.mod index 3c362562f4e..c86c52ca6a2 100644 --- a/credentials/go.mod +++ b/credentials/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 @@ -14,12 +15,20 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../ +replace github.com/aws/aws-sdk-go-v2/config => ../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../credentials/ + replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/sso => ../service/sso/ diff --git a/credentials/go.sum b/credentials/go.sum index a646f1d3099..7244dc234f8 100644 --- a/credentials/go.sum +++ b/credentials/go.sum @@ -1,3 +1,10 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/example/service/dynamodb/createTable/go.mod b/example/service/dynamodb/createTable/go.mod index d7042918fc2..dfda0d690b9 100644 --- a/example/service/dynamodb/createTable/go.mod +++ b/example/service/dynamodb/createTable/go.mod @@ -18,6 +18,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2 replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ diff --git a/example/service/dynamodb/createTable/go.sum b/example/service/dynamodb/createTable/go.sum index ef5982af332..9ffbde23b19 100644 --- a/example/service/dynamodb/createTable/go.sum +++ b/example/service/dynamodb/createTable/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/example/service/dynamodb/scanItems/go.mod b/example/service/dynamodb/scanItems/go.mod index ebef412db66..290f7fdf1d7 100644 --- a/example/service/dynamodb/scanItems/go.mod +++ b/example/service/dynamodb/scanItems/go.mod @@ -21,6 +21,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2 replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ diff --git a/example/service/dynamodb/scanItems/go.sum b/example/service/dynamodb/scanItems/go.sum index ef5982af332..9ffbde23b19 100644 --- a/example/service/dynamodb/scanItems/go.sum +++ b/example/service/dynamodb/scanItems/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/example/service/s3/listObjects/go.mod b/example/service/s3/listObjects/go.mod index df6e5355d9b..f2c13deb0f6 100644 --- a/example/service/s3/listObjects/go.mod +++ b/example/service/s3/listObjects/go.mod @@ -19,6 +19,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2 replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ diff --git a/example/service/s3/usingPrivateLink/go.mod b/example/service/s3/usingPrivateLink/go.mod index f33c4e2776d..5f0e7b3b2e7 100644 --- a/example/service/s3/usingPrivateLink/go.mod +++ b/example/service/s3/usingPrivateLink/go.mod @@ -21,6 +21,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2 replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ diff --git a/feature/dynamodb/attributevalue/go.mod b/feature/dynamodb/attributevalue/go.mod index 0d62181f45f..fe4747c9b70 100644 --- a/feature/dynamodb/attributevalue/go.mod +++ b/feature/dynamodb/attributevalue/go.mod @@ -12,10 +12,20 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ @@ -23,3 +33,11 @@ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/feature/dynamodb/expression/go.mod b/feature/dynamodb/expression/go.mod index 16aaa84973b..e3e1c3c6098 100644 --- a/feature/dynamodb/expression/go.mod +++ b/feature/dynamodb/expression/go.mod @@ -5,18 +5,29 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview // indirect github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0 github.com/google/go-cmp v0.5.8 ) replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + replace github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue => ../../../feature/dynamodb/attributevalue/ +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ @@ -24,3 +35,11 @@ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/feature/dynamodb/expression/go.sum b/feature/dynamodb/expression/go.sum index ef5982af332..bb80e8891d8 100644 --- a/feature/dynamodb/expression/go.sum +++ b/feature/dynamodb/expression/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/feature/dynamodbstreams/attributevalue/go.mod b/feature/dynamodbstreams/attributevalue/go.mod index 35ac51b6429..bf99bd079c2 100644 --- a/feature/dynamodbstreams/attributevalue/go.mod +++ b/feature/dynamodbstreams/attributevalue/go.mod @@ -12,10 +12,20 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service/dynamodbstreams/ @@ -23,3 +33,11 @@ replace github.com/aws/aws-sdk-go-v2/service/dynamodbstreams => ../../../service replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/feature/ec2/imds/internal/configtesting/go.mod b/feature/ec2/imds/internal/configtesting/go.mod index 07b946c9c96..c26c8b5ccad 100644 --- a/feature/ec2/imds/internal/configtesting/go.mod +++ b/feature/ec2/imds/internal/configtesting/go.mod @@ -17,6 +17,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../../feature/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../../internal/ini/ diff --git a/feature/ec2/imds/internal/configtesting/go.sum b/feature/ec2/imds/internal/configtesting/go.sum index a646f1d3099..bd5e12334b7 100644 --- a/feature/ec2/imds/internal/configtesting/go.sum +++ b/feature/ec2/imds/internal/configtesting/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/feature/s3/manager/go.mod b/feature/s3/manager/go.mod index 172275279ca..d2d8310f0c2 100644 --- a/feature/s3/manager/go.mod +++ b/feature/s3/manager/go.mod @@ -22,6 +22,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/im replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ diff --git a/internal/configsources/configtesting/go.mod b/internal/configsources/configtesting/go.mod index e0ea46bf832..0352016f01b 100644 --- a/internal/configsources/configtesting/go.mod +++ b/internal/configsources/configtesting/go.mod @@ -17,6 +17,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/im replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ diff --git a/internal/configsources/configtesting/go.sum b/internal/configsources/configtesting/go.sum index a646f1d3099..bd5e12334b7 100644 --- a/internal/configsources/configtesting/go.sum +++ b/internal/configsources/configtesting/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/endpoints/config/go.mod b/internal/endpoints/config/go.mod index 95390c3648b..959ca512045 100644 --- a/internal/endpoints/config/go.mod +++ b/internal/endpoints/config/go.mod @@ -14,6 +14,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/im replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ diff --git a/internal/endpoints/config/go.sum b/internal/endpoints/config/go.sum index a646f1d3099..4ad6d15cf52 100644 --- a/internal/endpoints/config/go.sum +++ b/internal/endpoints/config/go.sum @@ -1,3 +1,4 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/awsrestjson/api_client.go b/internal/protocoltest/awsrestjson/api_client.go index 3b2a94740b2..de4c9c6eea2 100644 --- a/internal/protocoltest/awsrestjson/api_client.go +++ b/internal/protocoltest/awsrestjson/api_client.go @@ -292,6 +292,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/awsrestjson/endpoints.go b/internal/protocoltest/awsrestjson/endpoints.go index 180060308a7..ce1e8f878fb 100644 --- a/internal/protocoltest/awsrestjson/endpoints.go +++ b/internal/protocoltest/awsrestjson/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REST_JSON_PROTOCOL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Rest Json Protocol", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/awsrestjson/endpoints_config_test.go b/internal/protocoltest/awsrestjson/endpoints_config_test.go new file mode 100644 index 00000000000..0ec6842b669 --- /dev/null +++ b/internal/protocoltest/awsrestjson/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awsrestjson + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-json-protocol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + expectURL: aws.String("https://env-rest-json-protocol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + expectURL: aws.String("http://config-rest-json-protocol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-json-protocol.dev", + clientEndpoint: aws.String("https://client-rest-json-protocol.dev"), + expectURL: aws.String("https://client-rest-json-protocol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REST_JSON_PROTOCOL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/awsrestjson/generated.json b/internal/protocoltest/awsrestjson/generated.json index f5c9af25d33..870655eb968 100644 --- a/internal/protocoltest/awsrestjson/generated.json +++ b/internal/protocoltest/awsrestjson/generated.json @@ -165,6 +165,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/internal/protocoltest/awsrestjson/go.mod b/internal/protocoltest/awsrestjson/go.mod index 9978cbe1d81..e9f111d9f2f 100644 --- a/internal/protocoltest/awsrestjson/go.mod +++ b/internal/protocoltest/awsrestjson/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/awsrestjson/go.sum b/internal/protocoltest/awsrestjson/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/awsrestjson/go.sum +++ b/internal/protocoltest/awsrestjson/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/ec2query/api_client.go b/internal/protocoltest/ec2query/api_client.go index c5a205e5e16..2f55ad086ee 100644 --- a/internal/protocoltest/ec2query/api_client.go +++ b/internal/protocoltest/ec2query/api_client.go @@ -292,6 +292,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/ec2query/endpoints.go b/internal/protocoltest/ec2query/endpoints.go index c3f2ec547ec..3a7eda49c9b 100644 --- a/internal/protocoltest/ec2query/endpoints.go +++ b/internal/protocoltest/ec2query/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EC2_PROTOCOL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EC2 Protocol", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/ec2query/endpoints_config_test.go b/internal/protocoltest/ec2query/endpoints_config_test.go new file mode 100644 index 00000000000..4c6bd14b1c5 --- /dev/null +++ b/internal/protocoltest/ec2query/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ec2query + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-protocol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + expectURL: aws.String("https://env-ec2-protocol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + expectURL: aws.String("http://config-ec2-protocol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-protocol.dev", + clientEndpoint: aws.String("https://client-ec2-protocol.dev"), + expectURL: aws.String("https://client-ec2-protocol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EC2_PROTOCOL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/ec2query/generated.json b/internal/protocoltest/ec2query/generated.json index bc595f01115..a7567ed940a 100644 --- a/internal/protocoltest/ec2query/generated.json +++ b/internal/protocoltest/ec2query/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/internal/protocoltest/ec2query/go.mod b/internal/protocoltest/ec2query/go.mod index 5ad8179ca3a..95051f580e1 100644 --- a/internal/protocoltest/ec2query/go.mod +++ b/internal/protocoltest/ec2query/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/ec2query/go.sum b/internal/protocoltest/ec2query/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/ec2query/go.sum +++ b/internal/protocoltest/ec2query/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/jsonrpc/api_client.go b/internal/protocoltest/jsonrpc/api_client.go index cd5464515d9..ceba23ef68c 100644 --- a/internal/protocoltest/jsonrpc/api_client.go +++ b/internal/protocoltest/jsonrpc/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/jsonrpc/endpoints.go b/internal/protocoltest/jsonrpc/endpoints.go index 2efe96b7d09..89ad1692c21 100644 --- a/internal/protocoltest/jsonrpc/endpoints.go +++ b/internal/protocoltest/jsonrpc/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_JSON_PROTOCOL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Json Protocol", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/jsonrpc/endpoints_config_test.go b/internal/protocoltest/jsonrpc/endpoints_config_test.go new file mode 100644 index 00000000000..d20033438ff --- /dev/null +++ b/internal/protocoltest/jsonrpc/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package jsonrpc + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-protocol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + expectURL: aws.String("https://env-json-protocol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + expectURL: aws.String("http://config-json-protocol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-protocol.dev", + clientEndpoint: aws.String("https://client-json-protocol.dev"), + expectURL: aws.String("https://client-json-protocol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_JSON_PROTOCOL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/jsonrpc/generated.json b/internal/protocoltest/jsonrpc/generated.json index 7afc769320c..53674597231 100644 --- a/internal/protocoltest/jsonrpc/generated.json +++ b/internal/protocoltest/jsonrpc/generated.json @@ -44,6 +44,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/internal/protocoltest/jsonrpc/go.mod b/internal/protocoltest/jsonrpc/go.mod index ab511e28b14..f405042396a 100644 --- a/internal/protocoltest/jsonrpc/go.mod +++ b/internal/protocoltest/jsonrpc/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/jsonrpc/go.sum b/internal/protocoltest/jsonrpc/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/jsonrpc/go.sum +++ b/internal/protocoltest/jsonrpc/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/jsonrpc10/api_client.go b/internal/protocoltest/jsonrpc10/api_client.go index 31226ee7139..b3db126a679 100644 --- a/internal/protocoltest/jsonrpc10/api_client.go +++ b/internal/protocoltest/jsonrpc10/api_client.go @@ -284,6 +284,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/jsonrpc10/endpoints.go b/internal/protocoltest/jsonrpc10/endpoints.go index 249ac2e97d4..4b3138566b2 100644 --- a/internal/protocoltest/jsonrpc10/endpoints.go +++ b/internal/protocoltest/jsonrpc10/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc10/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_JSON_RPC_10") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "JSON RPC 10", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/jsonrpc10/endpoints_config_test.go b/internal/protocoltest/jsonrpc10/endpoints_config_test.go new file mode 100644 index 00000000000..62e8e4a0bdc --- /dev/null +++ b/internal/protocoltest/jsonrpc10/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package jsonrpc10 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-rpc-10.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-rpc-10.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + expectURL: aws.String("https://env-json-rpc-10.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-rpc-10.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + expectURL: aws.String("http://config-json-rpc-10.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-json-rpc-10.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-json-rpc-10.dev", + clientEndpoint: aws.String("https://client-json-rpc-10.dev"), + expectURL: aws.String("https://client-json-rpc-10.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_JSON_RPC_10", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/jsonrpc10/generated.json b/internal/protocoltest/jsonrpc10/generated.json index 246dcad2909..864d55607b0 100644 --- a/internal/protocoltest/jsonrpc10/generated.json +++ b/internal/protocoltest/jsonrpc10/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/internal/protocoltest/jsonrpc10/go.mod b/internal/protocoltest/jsonrpc10/go.mod index a1b49c4a26f..f8a8734b787 100644 --- a/internal/protocoltest/jsonrpc10/go.mod +++ b/internal/protocoltest/jsonrpc10/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/jsonrpc10/go.sum b/internal/protocoltest/jsonrpc10/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/jsonrpc10/go.sum +++ b/internal/protocoltest/jsonrpc10/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/query/api_client.go b/internal/protocoltest/query/api_client.go index d134f618180..e2b6386977c 100644 --- a/internal/protocoltest/query/api_client.go +++ b/internal/protocoltest/query/api_client.go @@ -292,6 +292,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/query/endpoints.go b/internal/protocoltest/query/endpoints.go index a6f5836aeae..45d5d5809ee 100644 --- a/internal/protocoltest/query/endpoints.go +++ b/internal/protocoltest/query/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_QUERY_PROTOCOL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Query Protocol", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/query/endpoints_config_test.go b/internal/protocoltest/query/endpoints_config_test.go new file mode 100644 index 00000000000..d12f6df0823 --- /dev/null +++ b/internal/protocoltest/query/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package query + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-query-protocol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-query-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + expectURL: aws.String("https://env-query-protocol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-query-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + expectURL: aws.String("http://config-query-protocol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-query-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-query-protocol.dev", + clientEndpoint: aws.String("https://client-query-protocol.dev"), + expectURL: aws.String("https://client-query-protocol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_QUERY_PROTOCOL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/query/generated.json b/internal/protocoltest/query/generated.json index 3dcff8497f9..36492aca633 100644 --- a/internal/protocoltest/query/generated.json +++ b/internal/protocoltest/query/generated.json @@ -78,6 +78,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/internal/protocoltest/query/go.mod b/internal/protocoltest/query/go.mod index 8afadf87fbd..f1a37d9ee96 100644 --- a/internal/protocoltest/query/go.mod +++ b/internal/protocoltest/query/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/query/go.sum b/internal/protocoltest/query/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/query/go.sum +++ b/internal/protocoltest/query/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/restxml/api_client.go b/internal/protocoltest/restxml/api_client.go index e5d86bfb91a..dffbcc3ef0a 100644 --- a/internal/protocoltest/restxml/api_client.go +++ b/internal/protocoltest/restxml/api_client.go @@ -292,6 +292,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/restxml/endpoints.go b/internal/protocoltest/restxml/endpoints.go index 1af8330ec56..4c0ef93533d 100644 --- a/internal/protocoltest/restxml/endpoints.go +++ b/internal/protocoltest/restxml/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REST_XML_PROTOCOL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Rest Xml Protocol", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/restxml/endpoints_config_test.go b/internal/protocoltest/restxml/endpoints_config_test.go new file mode 100644 index 00000000000..8522c85dc67 --- /dev/null +++ b/internal/protocoltest/restxml/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package restxml + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + expectURL: aws.String("https://env-rest-xml-protocol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + expectURL: aws.String("http://config-rest-xml-protocol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol.dev", + clientEndpoint: aws.String("https://client-rest-xml-protocol.dev"), + expectURL: aws.String("https://client-rest-xml-protocol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REST_XML_PROTOCOL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/restxml/generated.json b/internal/protocoltest/restxml/generated.json index 981e34d59d1..ca5c046a600 100644 --- a/internal/protocoltest/restxml/generated.json +++ b/internal/protocoltest/restxml/generated.json @@ -129,6 +129,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/internal/protocoltest/restxml/go.mod b/internal/protocoltest/restxml/go.mod index 207f6823228..93d99619e99 100644 --- a/internal/protocoltest/restxml/go.mod +++ b/internal/protocoltest/restxml/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/restxml/go.sum b/internal/protocoltest/restxml/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/restxml/go.sum +++ b/internal/protocoltest/restxml/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/protocoltest/restxmlwithnamespace/api_client.go b/internal/protocoltest/restxmlwithnamespace/api_client.go index 03b2e8a1c84..7f6ac31a008 100644 --- a/internal/protocoltest/restxmlwithnamespace/api_client.go +++ b/internal/protocoltest/restxmlwithnamespace/api_client.go @@ -284,6 +284,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/internal/protocoltest/restxmlwithnamespace/endpoints.go b/internal/protocoltest/restxmlwithnamespace/endpoints.go index 6bd0daaffa1..a91f9d1c365 100644 --- a/internal/protocoltest/restxmlwithnamespace/endpoints.go +++ b/internal/protocoltest/restxmlwithnamespace/endpoints.go @@ -8,11 +8,13 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "net/url" + "os" "strings" ) @@ -191,6 +193,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REST_XML_PROTOCOL_NAMESPACE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Rest Xml Protocol Namespace", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // EndpointParameters provides the parameters that influence how endpoints are // resolved. type EndpointParameters struct { diff --git a/internal/protocoltest/restxmlwithnamespace/endpoints_config_test.go b/internal/protocoltest/restxmlwithnamespace/endpoints_config_test.go new file mode 100644 index 00000000000..ed65fbc04b3 --- /dev/null +++ b/internal/protocoltest/restxmlwithnamespace/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package restxmlwithnamespace + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol-namespace.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol-namespace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + expectURL: aws.String("https://env-rest-xml-protocol-namespace.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol-namespace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + expectURL: aws.String("http://config-rest-xml-protocol-namespace.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rest-xml-protocol-namespace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rest-xml-protocol-namespace.dev", + clientEndpoint: aws.String("https://client-rest-xml-protocol-namespace.dev"), + expectURL: aws.String("https://client-rest-xml-protocol-namespace.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REST_XML_PROTOCOL_NAMESPACE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/internal/protocoltest/restxmlwithnamespace/generated.json b/internal/protocoltest/restxmlwithnamespace/generated.json index d70fcf1f282..cf0cb42464a 100644 --- a/internal/protocoltest/restxmlwithnamespace/generated.json +++ b/internal/protocoltest/restxmlwithnamespace/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/internal/protocoltest/restxmlwithnamespace/go.mod b/internal/protocoltest/restxmlwithnamespace/go.mod index 4b9701f570c..8b97916f8fc 100644 --- a/internal/protocoltest/restxmlwithnamespace/go.mod +++ b/internal/protocoltest/restxmlwithnamespace/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/internal/protocoltest/restxmlwithnamespace/go.sum b/internal/protocoltest/restxmlwithnamespace/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/internal/protocoltest/restxmlwithnamespace/go.sum +++ b/internal/protocoltest/restxmlwithnamespace/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/accessanalyzer/api_client.go b/service/accessanalyzer/api_client.go index b8678d1414c..991e33bf5e4 100644 --- a/service/accessanalyzer/api_client.go +++ b/service/accessanalyzer/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/accessanalyzer/endpoints.go b/service/accessanalyzer/endpoints.go index 5ad02e775fa..eaffb1fdde9 100644 --- a/service/accessanalyzer/endpoints.go +++ b/service/accessanalyzer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/accessanalyzer/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ACCESSANALYZER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AccessAnalyzer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/accessanalyzer/endpoints_config_test.go b/service/accessanalyzer/endpoints_config_test.go new file mode 100644 index 00000000000..dbc8bb742d6 --- /dev/null +++ b/service/accessanalyzer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package accessanalyzer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-accessanalyzer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-accessanalyzer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + expectURL: aws.String("https://env-accessanalyzer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-accessanalyzer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + expectURL: aws.String("http://config-accessanalyzer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-accessanalyzer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-accessanalyzer.dev", + clientEndpoint: aws.String("https://client-accessanalyzer.dev"), + expectURL: aws.String("https://client-accessanalyzer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ACCESSANALYZER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/accessanalyzer/generated.json b/service/accessanalyzer/generated.json index 7e77b5106ce..e3ea08c0eb0 100644 --- a/service/accessanalyzer/generated.json +++ b/service/accessanalyzer/generated.json @@ -40,6 +40,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/accessanalyzer/go.mod b/service/accessanalyzer/go.mod index d96b448bcfd..b0ebdbbfc69 100644 --- a/service/accessanalyzer/go.mod +++ b/service/accessanalyzer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/accessanalyzer/go.sum b/service/accessanalyzer/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/accessanalyzer/go.sum +++ b/service/accessanalyzer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/account/api_client.go b/service/account/api_client.go index 0347ac58232..57ed95737d1 100644 --- a/service/account/api_client.go +++ b/service/account/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/account/endpoints.go b/service/account/endpoints.go index 2cdbdd1531c..b7fc8bf3460 100644 --- a/service/account/endpoints.go +++ b/service/account/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/account/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ACCOUNT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Account", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/account/endpoints_config_test.go b/service/account/endpoints_config_test.go new file mode 100644 index 00000000000..744902e9ed4 --- /dev/null +++ b/service/account/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package account + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-account.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-account.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + expectURL: aws.String("https://env-account.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-account.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + expectURL: aws.String("http://config-account.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-account.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-account.dev", + clientEndpoint: aws.String("https://client-account.dev"), + expectURL: aws.String("https://client-account.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ACCOUNT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/account/generated.json b/service/account/generated.json index 5ad4576d528..446e64d1fb5 100644 --- a/service/account/generated.json +++ b/service/account/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/account/go.mod b/service/account/go.mod index 7c6026da8e0..b04ac34b159 100644 --- a/service/account/go.mod +++ b/service/account/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/account/go.sum b/service/account/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/account/go.sum +++ b/service/account/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/acm/api_client.go b/service/acm/api_client.go index 6db625c5b96..0bec2ed26af 100644 --- a/service/acm/api_client.go +++ b/service/acm/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/acm/endpoints.go b/service/acm/endpoints.go index dd9d6b29f25..dc4c52448e0 100644 --- a/service/acm/endpoints.go +++ b/service/acm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/acm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ACM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ACM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/acm/endpoints_config_test.go b/service/acm/endpoints_config_test.go new file mode 100644 index 00000000000..bfc7082bffb --- /dev/null +++ b/service/acm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package acm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + expectURL: aws.String("https://env-acm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + expectURL: aws.String("http://config-acm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm.dev", + clientEndpoint: aws.String("https://client-acm.dev"), + expectURL: aws.String("https://client-acm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ACM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/acm/generated.json b/service/acm/generated.json index 97c7f2d0bfe..bff9984c8c2 100644 --- a/service/acm/generated.json +++ b/service/acm/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/acm/go.mod b/service/acm/go.mod index 97e7510fd14..0450ca8355e 100644 --- a/service/acm/go.mod +++ b/service/acm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/acm/go.sum b/service/acm/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/acm/go.sum +++ b/service/acm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/acmpca/api_client.go b/service/acmpca/api_client.go index b0126150f20..9989986011f 100644 --- a/service/acmpca/api_client.go +++ b/service/acmpca/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/acmpca/endpoints.go b/service/acmpca/endpoints.go index 336957c5dc6..57b42b0a720 100644 --- a/service/acmpca/endpoints.go +++ b/service/acmpca/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/acmpca/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ACM_PCA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ACM PCA", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/acmpca/endpoints_config_test.go b/service/acmpca/endpoints_config_test.go new file mode 100644 index 00000000000..e99da9ec66f --- /dev/null +++ b/service/acmpca/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package acmpca + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm-pca.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm-pca.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + expectURL: aws.String("https://env-acm-pca.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm-pca.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + expectURL: aws.String("http://config-acm-pca.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-acm-pca.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-acm-pca.dev", + clientEndpoint: aws.String("https://client-acm-pca.dev"), + expectURL: aws.String("https://client-acm-pca.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ACM_PCA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/acmpca/generated.json b/service/acmpca/generated.json index 61e972de3b3..4458b549bf0 100644 --- a/service/acmpca/generated.json +++ b/service/acmpca/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/acmpca/go.mod b/service/acmpca/go.mod index 428a76c7248..32f7bfbba83 100644 --- a/service/acmpca/go.mod +++ b/service/acmpca/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/acmpca/go.sum b/service/acmpca/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/acmpca/go.sum +++ b/service/acmpca/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/alexaforbusiness/api_client.go b/service/alexaforbusiness/api_client.go index 16b54dac0fe..716a586466b 100644 --- a/service/alexaforbusiness/api_client.go +++ b/service/alexaforbusiness/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/alexaforbusiness/endpoints.go b/service/alexaforbusiness/endpoints.go index 00c8a0bde6c..b7c8264f42a 100644 --- a/service/alexaforbusiness/endpoints.go +++ b/service/alexaforbusiness/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/alexaforbusiness/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ALEXA_FOR_BUSINESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Alexa For Business", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/alexaforbusiness/endpoints_config_test.go b/service/alexaforbusiness/endpoints_config_test.go new file mode 100644 index 00000000000..b49cb384664 --- /dev/null +++ b/service/alexaforbusiness/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package alexaforbusiness + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-alexa-for-business.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-alexa-for-business.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + expectURL: aws.String("https://env-alexa-for-business.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-alexa-for-business.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + expectURL: aws.String("http://config-alexa-for-business.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-alexa-for-business.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-alexa-for-business.dev", + clientEndpoint: aws.String("https://client-alexa-for-business.dev"), + expectURL: aws.String("https://client-alexa-for-business.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ALEXA_FOR_BUSINESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/alexaforbusiness/generated.json b/service/alexaforbusiness/generated.json index 7492bb3523c..57697608670 100644 --- a/service/alexaforbusiness/generated.json +++ b/service/alexaforbusiness/generated.json @@ -105,6 +105,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/alexaforbusiness/go.mod b/service/alexaforbusiness/go.mod index 60e1f3daf2b..7aa0a3ab63e 100644 --- a/service/alexaforbusiness/go.mod +++ b/service/alexaforbusiness/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/alexaforbusiness/go.sum b/service/alexaforbusiness/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/alexaforbusiness/go.sum +++ b/service/alexaforbusiness/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/amp/api_client.go b/service/amp/api_client.go index dd9012bf226..056cb4e96b6 100644 --- a/service/amp/api_client.go +++ b/service/amp/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/amp/endpoints.go b/service/amp/endpoints.go index 72e4cadb4bb..3d66c419ea1 100644 --- a/service/amp/endpoints.go +++ b/service/amp/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/amp/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AMP") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "amp", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/amp/endpoints_config_test.go b/service/amp/endpoints_config_test.go new file mode 100644 index 00000000000..8d53adaa38f --- /dev/null +++ b/service/amp/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package amp + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amp.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-amp.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + expectURL: aws.String("https://env-amp.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amp.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + expectURL: aws.String("http://config-amp.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-amp.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amp.dev", + clientEndpoint: aws.String("https://client-amp.dev"), + expectURL: aws.String("https://client-amp.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AMP", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/amp/generated.json b/service/amp/generated.json index 07cb3695dfd..8528cc2b657 100644 --- a/service/amp/generated.json +++ b/service/amp/generated.json @@ -34,6 +34,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/amp/go.mod b/service/amp/go.mod index b0f1089e875..320a4bb60d1 100644 --- a/service/amp/go.mod +++ b/service/amp/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/amp/go.sum b/service/amp/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/amp/go.sum +++ b/service/amp/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/amplify/api_client.go b/service/amplify/api_client.go index edc34826c7d..d426e75cb92 100644 --- a/service/amplify/api_client.go +++ b/service/amplify/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/amplify/endpoints.go b/service/amplify/endpoints.go index b532bf69c36..42910bd7e6b 100644 --- a/service/amplify/endpoints.go +++ b/service/amplify/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/amplify/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AMPLIFY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Amplify", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/amplify/endpoints_config_test.go b/service/amplify/endpoints_config_test.go new file mode 100644 index 00000000000..07b64059b41 --- /dev/null +++ b/service/amplify/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package amplify + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplify.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplify.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + expectURL: aws.String("https://env-amplify.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplify.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + expectURL: aws.String("http://config-amplify.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplify.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplify.dev", + clientEndpoint: aws.String("https://client-amplify.dev"), + expectURL: aws.String("https://client-amplify.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AMPLIFY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/amplify/generated.json b/service/amplify/generated.json index 5328dbdd317..bd2589e9749 100644 --- a/service/amplify/generated.json +++ b/service/amplify/generated.json @@ -49,6 +49,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/amplify/go.mod b/service/amplify/go.mod index c71db4ad445..50cc9018717 100644 --- a/service/amplify/go.mod +++ b/service/amplify/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/amplify/go.sum b/service/amplify/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/amplify/go.sum +++ b/service/amplify/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/amplifybackend/api_client.go b/service/amplifybackend/api_client.go index 271d63dab88..4b4ca2c0d59 100644 --- a/service/amplifybackend/api_client.go +++ b/service/amplifybackend/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/amplifybackend/endpoints.go b/service/amplifybackend/endpoints.go index 0332ae2ed84..c1b0188c2f0 100644 --- a/service/amplifybackend/endpoints.go +++ b/service/amplifybackend/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/amplifybackend/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AMPLIFYBACKEND") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AmplifyBackend", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/amplifybackend/endpoints_config_test.go b/service/amplifybackend/endpoints_config_test.go new file mode 100644 index 00000000000..c4a86b5ea78 --- /dev/null +++ b/service/amplifybackend/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package amplifybackend + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifybackend.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifybackend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + expectURL: aws.String("https://env-amplifybackend.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifybackend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + expectURL: aws.String("http://config-amplifybackend.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifybackend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifybackend.dev", + clientEndpoint: aws.String("https://client-amplifybackend.dev"), + expectURL: aws.String("https://client-amplifybackend.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AMPLIFYBACKEND", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/amplifybackend/generated.json b/service/amplifybackend/generated.json index 1ef67e68b7f..4f0a140bf81 100644 --- a/service/amplifybackend/generated.json +++ b/service/amplifybackend/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/amplifybackend/go.mod b/service/amplifybackend/go.mod index 63f4f0b07b4..b2ce5b64138 100644 --- a/service/amplifybackend/go.mod +++ b/service/amplifybackend/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/amplifybackend/go.sum b/service/amplifybackend/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/amplifybackend/go.sum +++ b/service/amplifybackend/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/amplifyuibuilder/api_client.go b/service/amplifyuibuilder/api_client.go index 66d06d4c75f..4e368111a60 100644 --- a/service/amplifyuibuilder/api_client.go +++ b/service/amplifyuibuilder/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/amplifyuibuilder/endpoints.go b/service/amplifyuibuilder/endpoints.go index 8fb2c736112..b2a34c4841e 100644 --- a/service/amplifyuibuilder/endpoints.go +++ b/service/amplifyuibuilder/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/amplifyuibuilder/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AMPLIFYUIBUILDER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AmplifyUIBuilder", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/amplifyuibuilder/endpoints_config_test.go b/service/amplifyuibuilder/endpoints_config_test.go new file mode 100644 index 00000000000..212da3b03db --- /dev/null +++ b/service/amplifyuibuilder/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package amplifyuibuilder + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifyuibuilder.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifyuibuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + expectURL: aws.String("https://env-amplifyuibuilder.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifyuibuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + expectURL: aws.String("http://config-amplifyuibuilder.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-amplifyuibuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-amplifyuibuilder.dev", + clientEndpoint: aws.String("https://client-amplifyuibuilder.dev"), + expectURL: aws.String("https://client-amplifyuibuilder.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AMPLIFYUIBUILDER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/amplifyuibuilder/generated.json b/service/amplifyuibuilder/generated.json index 1ee8eedb350..88af7a02469 100644 --- a/service/amplifyuibuilder/generated.json +++ b/service/amplifyuibuilder/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/amplifyuibuilder/go.mod b/service/amplifyuibuilder/go.mod index 7c95f2d1cbe..278b1ab8012 100644 --- a/service/amplifyuibuilder/go.mod +++ b/service/amplifyuibuilder/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/amplifyuibuilder/go.sum b/service/amplifyuibuilder/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/amplifyuibuilder/go.sum +++ b/service/amplifyuibuilder/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/apigateway/api_client.go b/service/apigateway/api_client.go index abbffc3eba3..bcc3bec9c48 100644 --- a/service/apigateway/api_client.go +++ b/service/apigateway/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/apigateway/endpoints.go b/service/apigateway/endpoints.go index e85c956c11c..1fcf5160cac 100644 --- a/service/apigateway/endpoints.go +++ b/service/apigateway/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/apigateway/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_API_GATEWAY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "API Gateway", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/apigateway/endpoints_config_test.go b/service/apigateway/endpoints_config_test.go new file mode 100644 index 00000000000..3e82ab0a7dc --- /dev/null +++ b/service/apigateway/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package apigateway + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-api-gateway.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-api-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + expectURL: aws.String("https://env-api-gateway.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-api-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + expectURL: aws.String("http://config-api-gateway.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-api-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-api-gateway.dev", + clientEndpoint: aws.String("https://client-api-gateway.dev"), + expectURL: aws.String("https://client-api-gateway.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_API_GATEWAY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/apigateway/generated.json b/service/apigateway/generated.json index 0cbfcdf1e2a..82166021411 100644 --- a/service/apigateway/generated.json +++ b/service/apigateway/generated.json @@ -132,6 +132,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/apigateway/go.mod b/service/apigateway/go.mod index a9d6d239ddf..004d6abf0bc 100644 --- a/service/apigateway/go.mod +++ b/service/apigateway/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/apigateway/go.sum b/service/apigateway/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/apigateway/go.sum +++ b/service/apigateway/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/apigatewaymanagementapi/api_client.go b/service/apigatewaymanagementapi/api_client.go index 571507ecdf3..f7559892f20 100644 --- a/service/apigatewaymanagementapi/api_client.go +++ b/service/apigatewaymanagementapi/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/apigatewaymanagementapi/endpoints.go b/service/apigatewaymanagementapi/endpoints.go index 8233f70ee28..f4486b6049e 100644 --- a/service/apigatewaymanagementapi/endpoints.go +++ b/service/apigatewaymanagementapi/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APIGATEWAYMANAGEMENTAPI") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ApiGatewayManagementApi", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/apigatewaymanagementapi/endpoints_config_test.go b/service/apigatewaymanagementapi/endpoints_config_test.go new file mode 100644 index 00000000000..864260a37f9 --- /dev/null +++ b/service/apigatewaymanagementapi/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package apigatewaymanagementapi + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewaymanagementapi.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewaymanagementapi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + expectURL: aws.String("https://env-apigatewaymanagementapi.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewaymanagementapi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + expectURL: aws.String("http://config-apigatewaymanagementapi.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewaymanagementapi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewaymanagementapi.dev", + clientEndpoint: aws.String("https://client-apigatewaymanagementapi.dev"), + expectURL: aws.String("https://client-apigatewaymanagementapi.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APIGATEWAYMANAGEMENTAPI", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/apigatewaymanagementapi/generated.json b/service/apigatewaymanagementapi/generated.json index 619014bc361..e8cac46afa0 100644 --- a/service/apigatewaymanagementapi/generated.json +++ b/service/apigatewaymanagementapi/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/apigatewaymanagementapi/go.mod b/service/apigatewaymanagementapi/go.mod index a187acee219..bb0459b549a 100644 --- a/service/apigatewaymanagementapi/go.mod +++ b/service/apigatewaymanagementapi/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/apigatewaymanagementapi/go.sum b/service/apigatewaymanagementapi/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/apigatewaymanagementapi/go.sum +++ b/service/apigatewaymanagementapi/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/apigatewayv2/api_client.go b/service/apigatewayv2/api_client.go index b00624df593..6265ab16944 100644 --- a/service/apigatewayv2/api_client.go +++ b/service/apigatewayv2/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/apigatewayv2/endpoints.go b/service/apigatewayv2/endpoints.go index 96d8752bc22..63e20d80110 100644 --- a/service/apigatewayv2/endpoints.go +++ b/service/apigatewayv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/apigatewayv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APIGATEWAYV2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ApiGatewayV2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/apigatewayv2/endpoints_config_test.go b/service/apigatewayv2/endpoints_config_test.go new file mode 100644 index 00000000000..be5397acbb0 --- /dev/null +++ b/service/apigatewayv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package apigatewayv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewayv2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewayv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + expectURL: aws.String("https://env-apigatewayv2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewayv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + expectURL: aws.String("http://config-apigatewayv2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-apigatewayv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apigatewayv2.dev", + clientEndpoint: aws.String("https://client-apigatewayv2.dev"), + expectURL: aws.String("https://client-apigatewayv2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APIGATEWAYV2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/apigatewayv2/generated.json b/service/apigatewayv2/generated.json index 4c68cfbd466..410b0547ce9 100644 --- a/service/apigatewayv2/generated.json +++ b/service/apigatewayv2/generated.json @@ -84,6 +84,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/apigatewayv2/go.mod b/service/apigatewayv2/go.mod index 14da481babf..4ab5df22f96 100644 --- a/service/apigatewayv2/go.mod +++ b/service/apigatewayv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/apigatewayv2/go.sum b/service/apigatewayv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/apigatewayv2/go.sum +++ b/service/apigatewayv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appconfig/api_client.go b/service/appconfig/api_client.go index 3cc8481a94a..f758d160712 100644 --- a/service/appconfig/api_client.go +++ b/service/appconfig/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appconfig/endpoints.go b/service/appconfig/endpoints.go index 13787f241a2..af625aca7ac 100644 --- a/service/appconfig/endpoints.go +++ b/service/appconfig/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appconfig/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPCONFIG") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppConfig", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appconfig/endpoints_config_test.go b/service/appconfig/endpoints_config_test.go new file mode 100644 index 00000000000..4add4b536b9 --- /dev/null +++ b/service/appconfig/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appconfig + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfig.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfig.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + expectURL: aws.String("https://env-appconfig.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfig.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + expectURL: aws.String("http://config-appconfig.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfig.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfig.dev", + clientEndpoint: aws.String("https://client-appconfig.dev"), + expectURL: aws.String("https://client-appconfig.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPCONFIG", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appconfig/generated.json b/service/appconfig/generated.json index 7df725815f2..fc7d5897a06 100644 --- a/service/appconfig/generated.json +++ b/service/appconfig/generated.json @@ -55,6 +55,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appconfig/go.mod b/service/appconfig/go.mod index af706eb57ea..b9759b29a62 100644 --- a/service/appconfig/go.mod +++ b/service/appconfig/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appconfig/go.sum b/service/appconfig/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appconfig/go.sum +++ b/service/appconfig/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appconfigdata/api_client.go b/service/appconfigdata/api_client.go index b16109b9bb4..55bf093417e 100644 --- a/service/appconfigdata/api_client.go +++ b/service/appconfigdata/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appconfigdata/endpoints.go b/service/appconfigdata/endpoints.go index a18c0c6be36..655dd8aa644 100644 --- a/service/appconfigdata/endpoints.go +++ b/service/appconfigdata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appconfigdata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPCONFIGDATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppConfigData", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appconfigdata/endpoints_config_test.go b/service/appconfigdata/endpoints_config_test.go new file mode 100644 index 00000000000..a6e8964ccfa --- /dev/null +++ b/service/appconfigdata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appconfigdata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfigdata.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfigdata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + expectURL: aws.String("https://env-appconfigdata.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfigdata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + expectURL: aws.String("http://config-appconfigdata.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appconfigdata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appconfigdata.dev", + clientEndpoint: aws.String("https://client-appconfigdata.dev"), + expectURL: aws.String("https://client-appconfigdata.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPCONFIGDATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appconfigdata/generated.json b/service/appconfigdata/generated.json index 8b43796c5de..b35fad50c28 100644 --- a/service/appconfigdata/generated.json +++ b/service/appconfigdata/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appconfigdata/go.mod b/service/appconfigdata/go.mod index 472a46c6174..febec37329f 100644 --- a/service/appconfigdata/go.mod +++ b/service/appconfigdata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appconfigdata/go.sum b/service/appconfigdata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appconfigdata/go.sum +++ b/service/appconfigdata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appfabric/api_client.go b/service/appfabric/api_client.go index dfe1ecc5083..12329998f51 100644 --- a/service/appfabric/api_client.go +++ b/service/appfabric/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appfabric/endpoints.go b/service/appfabric/endpoints.go index b38b93b9af3..b16ef830ab3 100644 --- a/service/appfabric/endpoints.go +++ b/service/appfabric/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appfabric/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPFABRIC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppFabric", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appfabric/endpoints_config_test.go b/service/appfabric/endpoints_config_test.go new file mode 100644 index 00000000000..a2c18e2d5b3 --- /dev/null +++ b/service/appfabric/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appfabric + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appfabric.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appfabric.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + expectURL: aws.String("https://env-appfabric.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appfabric.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + expectURL: aws.String("http://config-appfabric.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appfabric.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appfabric.dev", + clientEndpoint: aws.String("https://client-appfabric.dev"), + expectURL: aws.String("https://client-appfabric.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPFABRIC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appfabric/generated.json b/service/appfabric/generated.json index db045d31cd0..d768127d2a5 100644 --- a/service/appfabric/generated.json +++ b/service/appfabric/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appfabric/go.mod b/service/appfabric/go.mod index d64e4839edb..edbd610b7c2 100644 --- a/service/appfabric/go.mod +++ b/service/appfabric/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appfabric/go.sum b/service/appfabric/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appfabric/go.sum +++ b/service/appfabric/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appflow/api_client.go b/service/appflow/api_client.go index 29fe78605f8..3ef887b33b0 100644 --- a/service/appflow/api_client.go +++ b/service/appflow/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appflow/endpoints.go b/service/appflow/endpoints.go index 140494d77db..714d13d41c4 100644 --- a/service/appflow/endpoints.go +++ b/service/appflow/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appflow/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPFLOW") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Appflow", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appflow/endpoints_config_test.go b/service/appflow/endpoints_config_test.go new file mode 100644 index 00000000000..4f682957e71 --- /dev/null +++ b/service/appflow/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appflow + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appflow.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + expectURL: aws.String("https://env-appflow.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + expectURL: aws.String("http://config-appflow.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appflow.dev", + clientEndpoint: aws.String("https://client-appflow.dev"), + expectURL: aws.String("https://client-appflow.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPFLOW", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appflow/generated.json b/service/appflow/generated.json index c0323ec29a0..ff47114f0fb 100644 --- a/service/appflow/generated.json +++ b/service/appflow/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appflow/go.mod b/service/appflow/go.mod index 774bfb25a79..631721728a6 100644 --- a/service/appflow/go.mod +++ b/service/appflow/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appflow/go.sum b/service/appflow/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appflow/go.sum +++ b/service/appflow/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appintegrations/api_client.go b/service/appintegrations/api_client.go index 332aaff5b79..bd81463ff34 100644 --- a/service/appintegrations/api_client.go +++ b/service/appintegrations/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appintegrations/endpoints.go b/service/appintegrations/endpoints.go index 982527d5432..4054438df5e 100644 --- a/service/appintegrations/endpoints.go +++ b/service/appintegrations/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appintegrations/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPINTEGRATIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppIntegrations", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appintegrations/endpoints_config_test.go b/service/appintegrations/endpoints_config_test.go new file mode 100644 index 00000000000..48871703fc2 --- /dev/null +++ b/service/appintegrations/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appintegrations + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appintegrations.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appintegrations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + expectURL: aws.String("https://env-appintegrations.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appintegrations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + expectURL: aws.String("http://config-appintegrations.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appintegrations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appintegrations.dev", + clientEndpoint: aws.String("https://client-appintegrations.dev"), + expectURL: aws.String("https://client-appintegrations.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPINTEGRATIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appintegrations/generated.json b/service/appintegrations/generated.json index bb001523086..4b4267aacf2 100644 --- a/service/appintegrations/generated.json +++ b/service/appintegrations/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appintegrations/go.mod b/service/appintegrations/go.mod index 1f0d309ff45..9a20ac918e2 100644 --- a/service/appintegrations/go.mod +++ b/service/appintegrations/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appintegrations/go.sum b/service/appintegrations/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appintegrations/go.sum +++ b/service/appintegrations/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/applicationautoscaling/api_client.go b/service/applicationautoscaling/api_client.go index c4352161f34..0cf3bdc6db5 100644 --- a/service/applicationautoscaling/api_client.go +++ b/service/applicationautoscaling/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/applicationautoscaling/endpoints.go b/service/applicationautoscaling/endpoints.go index f3374069380..af26122befe 100644 --- a/service/applicationautoscaling/endpoints.go +++ b/service/applicationautoscaling/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/applicationautoscaling/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPLICATION_AUTO_SCALING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Application Auto Scaling", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/applicationautoscaling/endpoints_config_test.go b/service/applicationautoscaling/endpoints_config_test.go new file mode 100644 index 00000000000..60d8486c754 --- /dev/null +++ b/service/applicationautoscaling/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package applicationautoscaling + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-auto-scaling.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + expectURL: aws.String("https://env-application-auto-scaling.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + expectURL: aws.String("http://config-application-auto-scaling.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-auto-scaling.dev", + clientEndpoint: aws.String("https://client-application-auto-scaling.dev"), + expectURL: aws.String("https://client-application-auto-scaling.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPLICATION_AUTO_SCALING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/applicationautoscaling/generated.json b/service/applicationautoscaling/generated.json index 0d2d015432c..a6c547637b4 100644 --- a/service/applicationautoscaling/generated.json +++ b/service/applicationautoscaling/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/applicationautoscaling/go.mod b/service/applicationautoscaling/go.mod index 34c50a6ec05..7c0348fdf26 100644 --- a/service/applicationautoscaling/go.mod +++ b/service/applicationautoscaling/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/applicationautoscaling/go.sum b/service/applicationautoscaling/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/applicationautoscaling/go.sum +++ b/service/applicationautoscaling/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/applicationcostprofiler/api_client.go b/service/applicationcostprofiler/api_client.go index 397294321b5..f4f54f8eac9 100644 --- a/service/applicationcostprofiler/api_client.go +++ b/service/applicationcostprofiler/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/applicationcostprofiler/endpoints.go b/service/applicationcostprofiler/endpoints.go index 86085a82ade..9889e82c3ab 100644 --- a/service/applicationcostprofiler/endpoints.go +++ b/service/applicationcostprofiler/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/applicationcostprofiler/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPLICATIONCOSTPROFILER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ApplicationCostProfiler", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/applicationcostprofiler/endpoints_config_test.go b/service/applicationcostprofiler/endpoints_config_test.go new file mode 100644 index 00000000000..d4b047f642b --- /dev/null +++ b/service/applicationcostprofiler/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package applicationcostprofiler + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-applicationcostprofiler.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-applicationcostprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + expectURL: aws.String("https://env-applicationcostprofiler.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-applicationcostprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + expectURL: aws.String("http://config-applicationcostprofiler.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-applicationcostprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-applicationcostprofiler.dev", + clientEndpoint: aws.String("https://client-applicationcostprofiler.dev"), + expectURL: aws.String("https://client-applicationcostprofiler.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPLICATIONCOSTPROFILER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/applicationcostprofiler/generated.json b/service/applicationcostprofiler/generated.json index 97a2ffdb936..8391ee4b859 100644 --- a/service/applicationcostprofiler/generated.json +++ b/service/applicationcostprofiler/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/applicationcostprofiler/go.mod b/service/applicationcostprofiler/go.mod index a46f7e1e92c..e7780ca5e13 100644 --- a/service/applicationcostprofiler/go.mod +++ b/service/applicationcostprofiler/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/applicationcostprofiler/go.sum b/service/applicationcostprofiler/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/applicationcostprofiler/go.sum +++ b/service/applicationcostprofiler/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/applicationdiscoveryservice/api_client.go b/service/applicationdiscoveryservice/api_client.go index 26e61c2d66f..e3fcd094643 100644 --- a/service/applicationdiscoveryservice/api_client.go +++ b/service/applicationdiscoveryservice/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/applicationdiscoveryservice/endpoints.go b/service/applicationdiscoveryservice/endpoints.go index 2611744cc35..20bf06501f5 100644 --- a/service/applicationdiscoveryservice/endpoints.go +++ b/service/applicationdiscoveryservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/applicationdiscoveryservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPLICATION_DISCOVERY_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Application Discovery Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/applicationdiscoveryservice/endpoints_config_test.go b/service/applicationdiscoveryservice/endpoints_config_test.go new file mode 100644 index 00000000000..3536649ae0f --- /dev/null +++ b/service/applicationdiscoveryservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package applicationdiscoveryservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-discovery-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-discovery-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + expectURL: aws.String("https://env-application-discovery-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-discovery-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + expectURL: aws.String("http://config-application-discovery-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-discovery-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-discovery-service.dev", + clientEndpoint: aws.String("https://client-application-discovery-service.dev"), + expectURL: aws.String("https://client-application-discovery-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPLICATION_DISCOVERY_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/applicationdiscoveryservice/generated.json b/service/applicationdiscoveryservice/generated.json index b009d81aeb7..7ab60b5f2e7 100644 --- a/service/applicationdiscoveryservice/generated.json +++ b/service/applicationdiscoveryservice/generated.json @@ -40,6 +40,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/applicationdiscoveryservice/go.mod b/service/applicationdiscoveryservice/go.mod index 1ea239f0ee9..79d77448b40 100644 --- a/service/applicationdiscoveryservice/go.mod +++ b/service/applicationdiscoveryservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/applicationdiscoveryservice/go.sum b/service/applicationdiscoveryservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/applicationdiscoveryservice/go.sum +++ b/service/applicationdiscoveryservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/applicationinsights/api_client.go b/service/applicationinsights/api_client.go index c14337af71a..6826930b46e 100644 --- a/service/applicationinsights/api_client.go +++ b/service/applicationinsights/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/applicationinsights/endpoints.go b/service/applicationinsights/endpoints.go index fd07ab9e377..f283256df35 100644 --- a/service/applicationinsights/endpoints.go +++ b/service/applicationinsights/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/applicationinsights/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPLICATION_INSIGHTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Application Insights", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/applicationinsights/endpoints_config_test.go b/service/applicationinsights/endpoints_config_test.go new file mode 100644 index 00000000000..ceea145be8b --- /dev/null +++ b/service/applicationinsights/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package applicationinsights + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-insights.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-insights.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + expectURL: aws.String("https://env-application-insights.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-insights.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + expectURL: aws.String("http://config-application-insights.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-application-insights.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-application-insights.dev", + clientEndpoint: aws.String("https://client-application-insights.dev"), + expectURL: aws.String("https://client-application-insights.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPLICATION_INSIGHTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/applicationinsights/generated.json b/service/applicationinsights/generated.json index 13ed632249c..e40a8446da0 100644 --- a/service/applicationinsights/generated.json +++ b/service/applicationinsights/generated.json @@ -45,6 +45,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/applicationinsights/go.mod b/service/applicationinsights/go.mod index b59d67a6df9..544fe82dec8 100644 --- a/service/applicationinsights/go.mod +++ b/service/applicationinsights/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/applicationinsights/go.sum b/service/applicationinsights/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/applicationinsights/go.sum +++ b/service/applicationinsights/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appmesh/api_client.go b/service/appmesh/api_client.go index f70af36bc3c..bab8026d432 100644 --- a/service/appmesh/api_client.go +++ b/service/appmesh/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appmesh/endpoints.go b/service/appmesh/endpoints.go index 532e40530cb..41ce232f4ba 100644 --- a/service/appmesh/endpoints.go +++ b/service/appmesh/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appmesh/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APP_MESH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "App Mesh", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appmesh/endpoints_config_test.go b/service/appmesh/endpoints_config_test.go new file mode 100644 index 00000000000..8da3c161c1b --- /dev/null +++ b/service/appmesh/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appmesh + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-app-mesh.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-app-mesh.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + expectURL: aws.String("https://env-app-mesh.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-app-mesh.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + expectURL: aws.String("http://config-app-mesh.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-app-mesh.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-app-mesh.dev", + clientEndpoint: aws.String("https://client-app-mesh.dev"), + expectURL: aws.String("https://client-app-mesh.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APP_MESH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appmesh/generated.json b/service/appmesh/generated.json index 7f047f0da5e..2efcf7f07a3 100644 --- a/service/appmesh/generated.json +++ b/service/appmesh/generated.json @@ -50,6 +50,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appmesh/go.mod b/service/appmesh/go.mod index 035f66a6eb2..dbd466cf74a 100644 --- a/service/appmesh/go.mod +++ b/service/appmesh/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appmesh/go.sum b/service/appmesh/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appmesh/go.sum +++ b/service/appmesh/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/apprunner/api_client.go b/service/apprunner/api_client.go index 7ed429d94b3..0f288b06539 100644 --- a/service/apprunner/api_client.go +++ b/service/apprunner/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/apprunner/endpoints.go b/service/apprunner/endpoints.go index e6b285e7b91..149092f276d 100644 --- a/service/apprunner/endpoints.go +++ b/service/apprunner/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/apprunner/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPRUNNER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppRunner", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/apprunner/endpoints_config_test.go b/service/apprunner/endpoints_config_test.go new file mode 100644 index 00000000000..66db1452c34 --- /dev/null +++ b/service/apprunner/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package apprunner + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apprunner.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-apprunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + expectURL: aws.String("https://env-apprunner.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-apprunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + expectURL: aws.String("http://config-apprunner.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-apprunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-apprunner.dev", + clientEndpoint: aws.String("https://client-apprunner.dev"), + expectURL: aws.String("https://client-apprunner.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPRUNNER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/apprunner/generated.json b/service/apprunner/generated.json index 62c9fdf1a22..a5701ae7f10 100644 --- a/service/apprunner/generated.json +++ b/service/apprunner/generated.json @@ -49,6 +49,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/apprunner/go.mod b/service/apprunner/go.mod index 9d55b1e0395..325b6760d28 100644 --- a/service/apprunner/go.mod +++ b/service/apprunner/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/apprunner/go.sum b/service/apprunner/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/apprunner/go.sum +++ b/service/apprunner/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/appstream/api_client.go b/service/appstream/api_client.go index 3a200fc5810..5878cb4b57b 100644 --- a/service/appstream/api_client.go +++ b/service/appstream/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appstream/endpoints.go b/service/appstream/endpoints.go index ff87a05fb14..111c1e572ed 100644 --- a/service/appstream/endpoints.go +++ b/service/appstream/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appstream/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPSTREAM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppStream", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appstream/endpoints_config_test.go b/service/appstream/endpoints_config_test.go new file mode 100644 index 00000000000..6c3c6d92245 --- /dev/null +++ b/service/appstream/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appstream + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appstream.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appstream.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + expectURL: aws.String("https://env-appstream.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appstream.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + expectURL: aws.String("http://config-appstream.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appstream.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appstream.dev", + clientEndpoint: aws.String("https://client-appstream.dev"), + expectURL: aws.String("https://client-appstream.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPSTREAM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appstream/generated.json b/service/appstream/generated.json index b3742a4c297..98924673e7d 100644 --- a/service/appstream/generated.json +++ b/service/appstream/generated.json @@ -88,6 +88,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appstream/go.mod b/service/appstream/go.mod index 9a67fce8fa8..c4d0a12dd31 100644 --- a/service/appstream/go.mod +++ b/service/appstream/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appstream/go.sum b/service/appstream/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/appstream/go.sum +++ b/service/appstream/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/appsync/api_client.go b/service/appsync/api_client.go index ea8a31e2bf3..1cb2d0d2940 100644 --- a/service/appsync/api_client.go +++ b/service/appsync/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/appsync/endpoints.go b/service/appsync/endpoints.go index 08793f276d7..a136a87b687 100644 --- a/service/appsync/endpoints.go +++ b/service/appsync/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/appsync/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_APPSYNC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AppSync", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/appsync/endpoints_config_test.go b/service/appsync/endpoints_config_test.go new file mode 100644 index 00000000000..e2cd724d818 --- /dev/null +++ b/service/appsync/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package appsync + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appsync.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-appsync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + expectURL: aws.String("https://env-appsync.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-appsync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + expectURL: aws.String("http://config-appsync.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-appsync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-appsync.dev", + clientEndpoint: aws.String("https://client-appsync.dev"), + expectURL: aws.String("https://client-appsync.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_APPSYNC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/appsync/generated.json b/service/appsync/generated.json index 8075078be21..da0e8239536 100644 --- a/service/appsync/generated.json +++ b/service/appsync/generated.json @@ -72,6 +72,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/appsync/go.mod b/service/appsync/go.mod index d57e367f357..6c10b096c5a 100644 --- a/service/appsync/go.mod +++ b/service/appsync/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/appsync/go.sum b/service/appsync/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/appsync/go.sum +++ b/service/appsync/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/arczonalshift/api_client.go b/service/arczonalshift/api_client.go index d68742db9a6..6e00b4abe5f 100644 --- a/service/arczonalshift/api_client.go +++ b/service/arczonalshift/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/arczonalshift/endpoints.go b/service/arczonalshift/endpoints.go index 6c9d4157c71..2d32ee244f4 100644 --- a/service/arczonalshift/endpoints.go +++ b/service/arczonalshift/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/arczonalshift/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ARC_ZONAL_SHIFT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ARC Zonal Shift", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/arczonalshift/endpoints_config_test.go b/service/arczonalshift/endpoints_config_test.go new file mode 100644 index 00000000000..a0a1dde8c38 --- /dev/null +++ b/service/arczonalshift/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package arczonalshift + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-arc-zonal-shift.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-arc-zonal-shift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + expectURL: aws.String("https://env-arc-zonal-shift.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-arc-zonal-shift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + expectURL: aws.String("http://config-arc-zonal-shift.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-arc-zonal-shift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-arc-zonal-shift.dev", + clientEndpoint: aws.String("https://client-arc-zonal-shift.dev"), + expectURL: aws.String("https://client-arc-zonal-shift.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ARC_ZONAL_SHIFT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/arczonalshift/generated.json b/service/arczonalshift/generated.json index 690ff32ed01..a2ebff71f5b 100644 --- a/service/arczonalshift/generated.json +++ b/service/arczonalshift/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/arczonalshift/go.mod b/service/arczonalshift/go.mod index 9b087093de2..c074ea27925 100644 --- a/service/arczonalshift/go.mod +++ b/service/arczonalshift/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/arczonalshift/go.sum b/service/arczonalshift/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/arczonalshift/go.sum +++ b/service/arczonalshift/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/athena/api_client.go b/service/athena/api_client.go index abd1ca46620..640e2438073 100644 --- a/service/athena/api_client.go +++ b/service/athena/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/athena/endpoints.go b/service/athena/endpoints.go index 04fbd409050..c73e70525c8 100644 --- a/service/athena/endpoints.go +++ b/service/athena/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/athena/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ATHENA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Athena", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/athena/endpoints_config_test.go b/service/athena/endpoints_config_test.go new file mode 100644 index 00000000000..e461670379f --- /dev/null +++ b/service/athena/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package athena + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-athena.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-athena.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + expectURL: aws.String("https://env-athena.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-athena.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + expectURL: aws.String("http://config-athena.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-athena.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-athena.dev", + clientEndpoint: aws.String("https://client-athena.dev"), + expectURL: aws.String("https://client-athena.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ATHENA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/athena/generated.json b/service/athena/generated.json index 2021e13cb1d..7134499d452 100644 --- a/service/athena/generated.json +++ b/service/athena/generated.json @@ -80,6 +80,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/athena/go.mod b/service/athena/go.mod index 62f70fec7cb..7139c94f6aa 100644 --- a/service/athena/go.mod +++ b/service/athena/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/athena/go.sum b/service/athena/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/athena/go.sum +++ b/service/athena/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/auditmanager/api_client.go b/service/auditmanager/api_client.go index f6071437bb8..a1c7776b263 100644 --- a/service/auditmanager/api_client.go +++ b/service/auditmanager/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/auditmanager/endpoints.go b/service/auditmanager/endpoints.go index 4799aa7a15b..c73e5ed24f8 100644 --- a/service/auditmanager/endpoints.go +++ b/service/auditmanager/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/auditmanager/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AUDITMANAGER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "AuditManager", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/auditmanager/endpoints_config_test.go b/service/auditmanager/endpoints_config_test.go new file mode 100644 index 00000000000..b0e139ef85b --- /dev/null +++ b/service/auditmanager/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package auditmanager + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auditmanager.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-auditmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + expectURL: aws.String("https://env-auditmanager.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auditmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + expectURL: aws.String("http://config-auditmanager.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-auditmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auditmanager.dev", + clientEndpoint: aws.String("https://client-auditmanager.dev"), + expectURL: aws.String("https://client-auditmanager.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AUDITMANAGER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/auditmanager/generated.json b/service/auditmanager/generated.json index 805ef98cd44..d64c0d14fa2 100644 --- a/service/auditmanager/generated.json +++ b/service/auditmanager/generated.json @@ -74,6 +74,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/auditmanager/go.mod b/service/auditmanager/go.mod index b5fdafb2410..83383e26f53 100644 --- a/service/auditmanager/go.mod +++ b/service/auditmanager/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/auditmanager/go.sum b/service/auditmanager/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/auditmanager/go.sum +++ b/service/auditmanager/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/autoscaling/api_client.go b/service/autoscaling/api_client.go index d600f227754..097042bda24 100644 --- a/service/autoscaling/api_client.go +++ b/service/autoscaling/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/autoscaling/endpoints.go b/service/autoscaling/endpoints.go index 5bbc9e24c72..2bb33e0525d 100644 --- a/service/autoscaling/endpoints.go +++ b/service/autoscaling/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/autoscaling/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AUTO_SCALING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Auto Scaling", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/autoscaling/endpoints_config_test.go b/service/autoscaling/endpoints_config_test.go new file mode 100644 index 00000000000..1733b22a6ba --- /dev/null +++ b/service/autoscaling/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package autoscaling + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + expectURL: aws.String("https://env-auto-scaling.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + expectURL: aws.String("http://config-auto-scaling.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling.dev", + clientEndpoint: aws.String("https://client-auto-scaling.dev"), + expectURL: aws.String("https://client-auto-scaling.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AUTO_SCALING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/autoscaling/generated.json b/service/autoscaling/generated.json index ac01a1e17fa..7358f17b504 100644 --- a/service/autoscaling/generated.json +++ b/service/autoscaling/generated.json @@ -78,6 +78,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/autoscaling/go.mod b/service/autoscaling/go.mod index ec7f3dda973..a12120f0c2a 100644 --- a/service/autoscaling/go.mod +++ b/service/autoscaling/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/autoscaling/go.sum b/service/autoscaling/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/autoscaling/go.sum +++ b/service/autoscaling/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/autoscalingplans/api_client.go b/service/autoscalingplans/api_client.go index 2d475a546be..96416feb6b2 100644 --- a/service/autoscalingplans/api_client.go +++ b/service/autoscalingplans/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/autoscalingplans/endpoints.go b/service/autoscalingplans/endpoints.go index 1c89f825d36..08cb7fb69a7 100644 --- a/service/autoscalingplans/endpoints.go +++ b/service/autoscalingplans/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/autoscalingplans/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_AUTO_SCALING_PLANS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Auto Scaling Plans", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/autoscalingplans/endpoints_config_test.go b/service/autoscalingplans/endpoints_config_test.go new file mode 100644 index 00000000000..db9895ffd96 --- /dev/null +++ b/service/autoscalingplans/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package autoscalingplans + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling-plans.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling-plans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + expectURL: aws.String("https://env-auto-scaling-plans.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling-plans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + expectURL: aws.String("http://config-auto-scaling-plans.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-auto-scaling-plans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-auto-scaling-plans.dev", + clientEndpoint: aws.String("https://client-auto-scaling-plans.dev"), + expectURL: aws.String("https://client-auto-scaling-plans.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_AUTO_SCALING_PLANS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/autoscalingplans/generated.json b/service/autoscalingplans/generated.json index 8072836130f..8561a8b1811 100644 --- a/service/autoscalingplans/generated.json +++ b/service/autoscalingplans/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/autoscalingplans/go.mod b/service/autoscalingplans/go.mod index 594c007c099..88e37ed0c38 100644 --- a/service/autoscalingplans/go.mod +++ b/service/autoscalingplans/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/autoscalingplans/go.sum b/service/autoscalingplans/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/autoscalingplans/go.sum +++ b/service/autoscalingplans/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/backup/api_client.go b/service/backup/api_client.go index 1716ab2915f..a7601935e6f 100644 --- a/service/backup/api_client.go +++ b/service/backup/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/backup/endpoints.go b/service/backup/endpoints.go index 2dde0dada8f..9e00559c140 100644 --- a/service/backup/endpoints.go +++ b/service/backup/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/backup/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BACKUP") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Backup", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/backup/endpoints_config_test.go b/service/backup/endpoints_config_test.go new file mode 100644 index 00000000000..466fb62afd1 --- /dev/null +++ b/service/backup/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package backup + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + expectURL: aws.String("https://env-backup.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + expectURL: aws.String("http://config-backup.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup.dev", + clientEndpoint: aws.String("https://client-backup.dev"), + expectURL: aws.String("https://client-backup.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BACKUP", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/backup/generated.json b/service/backup/generated.json index 783c4d83c82..9057aa25f0f 100644 --- a/service/backup/generated.json +++ b/service/backup/generated.json @@ -86,6 +86,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/backup/go.mod b/service/backup/go.mod index bd961eef73e..68eaa373ea1 100644 --- a/service/backup/go.mod +++ b/service/backup/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/backup/go.sum b/service/backup/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/backup/go.sum +++ b/service/backup/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/backupgateway/api_client.go b/service/backupgateway/api_client.go index 58c2b346ef5..0e5fc887cf0 100644 --- a/service/backupgateway/api_client.go +++ b/service/backupgateway/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/backupgateway/endpoints.go b/service/backupgateway/endpoints.go index eeb735be54d..8ac29422d7e 100644 --- a/service/backupgateway/endpoints.go +++ b/service/backupgateway/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/backupgateway/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BACKUP_GATEWAY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Backup Gateway", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/backupgateway/endpoints_config_test.go b/service/backupgateway/endpoints_config_test.go new file mode 100644 index 00000000000..e93eaa35691 --- /dev/null +++ b/service/backupgateway/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package backupgateway + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup-gateway.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + expectURL: aws.String("https://env-backup-gateway.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + expectURL: aws.String("http://config-backup-gateway.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-backup-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backup-gateway.dev", + clientEndpoint: aws.String("https://client-backup-gateway.dev"), + expectURL: aws.String("https://client-backup-gateway.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BACKUP_GATEWAY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/backupgateway/generated.json b/service/backupgateway/generated.json index 898bada9a9c..5eff1171669 100644 --- a/service/backupgateway/generated.json +++ b/service/backupgateway/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/backupgateway/go.mod b/service/backupgateway/go.mod index 1960f00de22..a82ef21e1ab 100644 --- a/service/backupgateway/go.mod +++ b/service/backupgateway/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/backupgateway/go.sum b/service/backupgateway/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/backupgateway/go.sum +++ b/service/backupgateway/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/backupstorage/api_client.go b/service/backupstorage/api_client.go index 5358462f2ef..81a26d5ae40 100644 --- a/service/backupstorage/api_client.go +++ b/service/backupstorage/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/backupstorage/endpoints.go b/service/backupstorage/endpoints.go index c611ae26ca3..95ac7bdfa3f 100644 --- a/service/backupstorage/endpoints.go +++ b/service/backupstorage/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/backupstorage/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BACKUPSTORAGE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "BackupStorage", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/backupstorage/endpoints_config_test.go b/service/backupstorage/endpoints_config_test.go new file mode 100644 index 00000000000..9438ebe3b52 --- /dev/null +++ b/service/backupstorage/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package backupstorage + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backupstorage.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-backupstorage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + expectURL: aws.String("https://env-backupstorage.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-backupstorage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + expectURL: aws.String("http://config-backupstorage.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-backupstorage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-backupstorage.dev", + clientEndpoint: aws.String("https://client-backupstorage.dev"), + expectURL: aws.String("https://client-backupstorage.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BACKUPSTORAGE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/backupstorage/generated.json b/service/backupstorage/generated.json index ce838431d7f..cd190535fd2 100644 --- a/service/backupstorage/generated.json +++ b/service/backupstorage/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/backupstorage/go.mod b/service/backupstorage/go.mod index 466b71f9308..e5a457d4afa 100644 --- a/service/backupstorage/go.mod +++ b/service/backupstorage/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/backupstorage/go.sum b/service/backupstorage/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/backupstorage/go.sum +++ b/service/backupstorage/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/batch/api_client.go b/service/batch/api_client.go index f0aa91b5fa9..cd5d2b77d4a 100644 --- a/service/batch/api_client.go +++ b/service/batch/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/batch/endpoints.go b/service/batch/endpoints.go index 4f462a3318c..b3ab2060f3c 100644 --- a/service/batch/endpoints.go +++ b/service/batch/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/batch/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BATCH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Batch", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/batch/endpoints_config_test.go b/service/batch/endpoints_config_test.go new file mode 100644 index 00000000000..0909d6c0ede --- /dev/null +++ b/service/batch/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package batch + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-batch.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-batch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + expectURL: aws.String("https://env-batch.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-batch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + expectURL: aws.String("http://config-batch.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-batch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-batch.dev", + clientEndpoint: aws.String("https://client-batch.dev"), + expectURL: aws.String("https://client-batch.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BATCH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/batch/generated.json b/service/batch/generated.json index 41923ff7ebb..46eb0ea53d1 100644 --- a/service/batch/generated.json +++ b/service/batch/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/batch/go.mod b/service/batch/go.mod index 0a26bef41b7..89dd7d02b53 100644 --- a/service/batch/go.mod +++ b/service/batch/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/batch/go.sum b/service/batch/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/batch/go.sum +++ b/service/batch/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/bedrock/api_client.go b/service/bedrock/api_client.go index ba07cbfbb08..ccc71d3e59d 100644 --- a/service/bedrock/api_client.go +++ b/service/bedrock/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/bedrock/endpoints.go b/service/bedrock/endpoints.go index 567cbf1c58a..1ee6fe2ac27 100644 --- a/service/bedrock/endpoints.go +++ b/service/bedrock/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/bedrock/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BEDROCK") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Bedrock", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/bedrock/endpoints_config_test.go b/service/bedrock/endpoints_config_test.go new file mode 100644 index 00000000000..812ae26c467 --- /dev/null +++ b/service/bedrock/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package bedrock + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + expectURL: aws.String("https://env-bedrock.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + expectURL: aws.String("http://config-bedrock.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock.dev", + clientEndpoint: aws.String("https://client-bedrock.dev"), + expectURL: aws.String("https://client-bedrock.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BEDROCK", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/bedrock/generated.json b/service/bedrock/generated.json index 1fe7bbc7dec..90b640a8782 100644 --- a/service/bedrock/generated.json +++ b/service/bedrock/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/bedrock/go.mod b/service/bedrock/go.mod index 603132e17ff..005edbafcd0 100644 --- a/service/bedrock/go.mod +++ b/service/bedrock/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/bedrock/go.sum b/service/bedrock/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/bedrock/go.sum +++ b/service/bedrock/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/bedrockruntime/api_client.go b/service/bedrockruntime/api_client.go index 82fbeb36b47..b714e0bb394 100644 --- a/service/bedrockruntime/api_client.go +++ b/service/bedrockruntime/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/bedrockruntime/endpoints.go b/service/bedrockruntime/endpoints.go index cb4d4c54e17..a74f83944d3 100644 --- a/service/bedrockruntime/endpoints.go +++ b/service/bedrockruntime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/bedrockruntime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BEDROCK_RUNTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Bedrock Runtime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/bedrockruntime/endpoints_config_test.go b/service/bedrockruntime/endpoints_config_test.go new file mode 100644 index 00000000000..6ee960e3dad --- /dev/null +++ b/service/bedrockruntime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package bedrockruntime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock-runtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + expectURL: aws.String("https://env-bedrock-runtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + expectURL: aws.String("http://config-bedrock-runtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-bedrock-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-bedrock-runtime.dev", + clientEndpoint: aws.String("https://client-bedrock-runtime.dev"), + expectURL: aws.String("https://client-bedrock-runtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/bedrockruntime/generated.json b/service/bedrockruntime/generated.json index e30c1f7d676..529344077b8 100644 --- a/service/bedrockruntime/generated.json +++ b/service/bedrockruntime/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/bedrockruntime/go.mod b/service/bedrockruntime/go.mod index 9d501c3499d..8e71885291d 100644 --- a/service/bedrockruntime/go.mod +++ b/service/bedrockruntime/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -15,6 +16,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/bedrockruntime/go.sum b/service/bedrockruntime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/bedrockruntime/go.sum +++ b/service/bedrockruntime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/billingconductor/api_client.go b/service/billingconductor/api_client.go index 04c663bacb8..9a794689717 100644 --- a/service/billingconductor/api_client.go +++ b/service/billingconductor/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/billingconductor/endpoints.go b/service/billingconductor/endpoints.go index eddfc4f005f..955f09f3a92 100644 --- a/service/billingconductor/endpoints.go +++ b/service/billingconductor/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/billingconductor/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BILLINGCONDUCTOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "billingconductor", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/billingconductor/endpoints_config_test.go b/service/billingconductor/endpoints_config_test.go new file mode 100644 index 00000000000..01908432520 --- /dev/null +++ b/service/billingconductor/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package billingconductor + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-billingconductor.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-billingconductor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + expectURL: aws.String("https://env-billingconductor.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-billingconductor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + expectURL: aws.String("http://config-billingconductor.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-billingconductor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-billingconductor.dev", + clientEndpoint: aws.String("https://client-billingconductor.dev"), + expectURL: aws.String("https://client-billingconductor.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BILLINGCONDUCTOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/billingconductor/generated.json b/service/billingconductor/generated.json index 858dfd8c3ba..d77c0ab1aeb 100644 --- a/service/billingconductor/generated.json +++ b/service/billingconductor/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/billingconductor/go.mod b/service/billingconductor/go.mod index 7cfe345a802..8e1d85d6d3f 100644 --- a/service/billingconductor/go.mod +++ b/service/billingconductor/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/billingconductor/go.sum b/service/billingconductor/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/billingconductor/go.sum +++ b/service/billingconductor/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/braket/api_client.go b/service/braket/api_client.go index 61660f03f61..49186a8747a 100644 --- a/service/braket/api_client.go +++ b/service/braket/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/braket/endpoints.go b/service/braket/endpoints.go index 75cf9b6a86f..6882cb98149 100644 --- a/service/braket/endpoints.go +++ b/service/braket/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/braket/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BRAKET") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Braket", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/braket/endpoints_config_test.go b/service/braket/endpoints_config_test.go new file mode 100644 index 00000000000..947db547d17 --- /dev/null +++ b/service/braket/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package braket + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-braket.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-braket.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + expectURL: aws.String("https://env-braket.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-braket.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + expectURL: aws.String("http://config-braket.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-braket.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-braket.dev", + clientEndpoint: aws.String("https://client-braket.dev"), + expectURL: aws.String("https://client-braket.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BRAKET", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/braket/generated.json b/service/braket/generated.json index 5d85a004861..fdd0ddcd2f5 100644 --- a/service/braket/generated.json +++ b/service/braket/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/braket/go.mod b/service/braket/go.mod index c97008257a8..c1a1485435d 100644 --- a/service/braket/go.mod +++ b/service/braket/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/braket/go.sum b/service/braket/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/braket/go.sum +++ b/service/braket/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/budgets/api_client.go b/service/budgets/api_client.go index 96ae820ffda..ee11d63e3d6 100644 --- a/service/budgets/api_client.go +++ b/service/budgets/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/budgets/endpoints.go b/service/budgets/endpoints.go index f6a5430885d..ec3d3ec0ac2 100644 --- a/service/budgets/endpoints.go +++ b/service/budgets/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/budgets/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_BUDGETS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Budgets", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/budgets/endpoints_config_test.go b/service/budgets/endpoints_config_test.go new file mode 100644 index 00000000000..9b4c9916697 --- /dev/null +++ b/service/budgets/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package budgets + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-budgets.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-budgets.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + expectURL: aws.String("https://env-budgets.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-budgets.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + expectURL: aws.String("http://config-budgets.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-budgets.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-budgets.dev", + clientEndpoint: aws.String("https://client-budgets.dev"), + expectURL: aws.String("https://client-budgets.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_BUDGETS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/budgets/generated.json b/service/budgets/generated.json index 51374d75942..aa1c7ee2842 100644 --- a/service/budgets/generated.json +++ b/service/budgets/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/budgets/go.mod b/service/budgets/go.mod index b5e42e64982..18959e5924a 100644 --- a/service/budgets/go.mod +++ b/service/budgets/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/budgets/go.sum b/service/budgets/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/budgets/go.sum +++ b/service/budgets/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chime/api_client.go b/service/chime/api_client.go index 6beecc0e94a..69a197e22a8 100644 --- a/service/chime/api_client.go +++ b/service/chime/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chime/endpoints.go b/service/chime/endpoints.go index a039abe633a..35d0f590688 100644 --- a/service/chime/endpoints.go +++ b/service/chime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chime/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chime/endpoints_config_test.go b/service/chime/endpoints_config_test.go new file mode 100644 index 00000000000..3c9194be814 --- /dev/null +++ b/service/chime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + expectURL: aws.String("https://env-chime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + expectURL: aws.String("http://config-chime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime.dev", + clientEndpoint: aws.String("https://client-chime.dev"), + expectURL: aws.String("https://client-chime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chime/generated.json b/service/chime/generated.json index 559a6b0ccd3..41d8b4d31ec 100644 --- a/service/chime/generated.json +++ b/service/chime/generated.json @@ -203,6 +203,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chime/go.mod b/service/chime/go.mod index 1c639c65856..8c4938f1724 100644 --- a/service/chime/go.mod +++ b/service/chime/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chime/go.sum b/service/chime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chime/go.sum +++ b/service/chime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chimesdkidentity/api_client.go b/service/chimesdkidentity/api_client.go index 083be9646d4..a4a7411a4ca 100644 --- a/service/chimesdkidentity/api_client.go +++ b/service/chimesdkidentity/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chimesdkidentity/endpoints.go b/service/chimesdkidentity/endpoints.go index 8abe6332dca..b008d30a59f 100644 --- a/service/chimesdkidentity/endpoints.go +++ b/service/chimesdkidentity/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chimesdkidentity/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME_SDK_IDENTITY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime SDK Identity", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chimesdkidentity/endpoints_config_test.go b/service/chimesdkidentity/endpoints_config_test.go new file mode 100644 index 00000000000..536c29a964f --- /dev/null +++ b/service/chimesdkidentity/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chimesdkidentity + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-identity.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + expectURL: aws.String("https://env-chime-sdk-identity.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + expectURL: aws.String("http://config-chime-sdk-identity.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-identity.dev", + clientEndpoint: aws.String("https://client-chime-sdk-identity.dev"), + expectURL: aws.String("https://client-chime-sdk-identity.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME_SDK_IDENTITY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chimesdkidentity/generated.json b/service/chimesdkidentity/generated.json index 89ad04152df..c5546d779ba 100644 --- a/service/chimesdkidentity/generated.json +++ b/service/chimesdkidentity/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chimesdkidentity/go.mod b/service/chimesdkidentity/go.mod index f400da9145b..ba58622bbef 100644 --- a/service/chimesdkidentity/go.mod +++ b/service/chimesdkidentity/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chimesdkidentity/go.sum b/service/chimesdkidentity/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chimesdkidentity/go.sum +++ b/service/chimesdkidentity/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chimesdkmediapipelines/api_client.go b/service/chimesdkmediapipelines/api_client.go index 21e18307e54..bec63e1812d 100644 --- a/service/chimesdkmediapipelines/api_client.go +++ b/service/chimesdkmediapipelines/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chimesdkmediapipelines/endpoints.go b/service/chimesdkmediapipelines/endpoints.go index 8f4c244a47f..834822dc9d5 100644 --- a/service/chimesdkmediapipelines/endpoints.go +++ b/service/chimesdkmediapipelines/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME_SDK_MEDIA_PIPELINES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime SDK Media Pipelines", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chimesdkmediapipelines/endpoints_config_test.go b/service/chimesdkmediapipelines/endpoints_config_test.go new file mode 100644 index 00000000000..6fc7cd51101 --- /dev/null +++ b/service/chimesdkmediapipelines/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chimesdkmediapipelines + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-media-pipelines.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-media-pipelines.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + expectURL: aws.String("https://env-chime-sdk-media-pipelines.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-media-pipelines.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + expectURL: aws.String("http://config-chime-sdk-media-pipelines.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-media-pipelines.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-media-pipelines.dev", + clientEndpoint: aws.String("https://client-chime-sdk-media-pipelines.dev"), + expectURL: aws.String("https://client-chime-sdk-media-pipelines.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME_SDK_MEDIA_PIPELINES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chimesdkmediapipelines/generated.json b/service/chimesdkmediapipelines/generated.json index 40e789f0161..9c960a2b0f6 100644 --- a/service/chimesdkmediapipelines/generated.json +++ b/service/chimesdkmediapipelines/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chimesdkmediapipelines/go.mod b/service/chimesdkmediapipelines/go.mod index 69d7e767f73..f556c76afbd 100644 --- a/service/chimesdkmediapipelines/go.mod +++ b/service/chimesdkmediapipelines/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chimesdkmediapipelines/go.sum b/service/chimesdkmediapipelines/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chimesdkmediapipelines/go.sum +++ b/service/chimesdkmediapipelines/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chimesdkmeetings/api_client.go b/service/chimesdkmeetings/api_client.go index 7bc533bbd5a..75d61fbfde1 100644 --- a/service/chimesdkmeetings/api_client.go +++ b/service/chimesdkmeetings/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chimesdkmeetings/endpoints.go b/service/chimesdkmeetings/endpoints.go index d389a8cdd84..4f2d830f1fb 100644 --- a/service/chimesdkmeetings/endpoints.go +++ b/service/chimesdkmeetings/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chimesdkmeetings/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME_SDK_MEETINGS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime SDK Meetings", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chimesdkmeetings/endpoints_config_test.go b/service/chimesdkmeetings/endpoints_config_test.go new file mode 100644 index 00000000000..d2e942adb50 --- /dev/null +++ b/service/chimesdkmeetings/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chimesdkmeetings + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-meetings.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-meetings.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + expectURL: aws.String("https://env-chime-sdk-meetings.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-meetings.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + expectURL: aws.String("http://config-chime-sdk-meetings.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-meetings.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-meetings.dev", + clientEndpoint: aws.String("https://client-chime-sdk-meetings.dev"), + expectURL: aws.String("https://client-chime-sdk-meetings.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME_SDK_MEETINGS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chimesdkmeetings/generated.json b/service/chimesdkmeetings/generated.json index 4563b40c793..bd6678af572 100644 --- a/service/chimesdkmeetings/generated.json +++ b/service/chimesdkmeetings/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chimesdkmeetings/go.mod b/service/chimesdkmeetings/go.mod index ee11e2a3345..6056e57e309 100644 --- a/service/chimesdkmeetings/go.mod +++ b/service/chimesdkmeetings/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chimesdkmeetings/go.sum b/service/chimesdkmeetings/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chimesdkmeetings/go.sum +++ b/service/chimesdkmeetings/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chimesdkmessaging/api_client.go b/service/chimesdkmessaging/api_client.go index 6b1c8f70b06..780ed8ac5fa 100644 --- a/service/chimesdkmessaging/api_client.go +++ b/service/chimesdkmessaging/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chimesdkmessaging/endpoints.go b/service/chimesdkmessaging/endpoints.go index 2132c2a225d..6de7fbbfecc 100644 --- a/service/chimesdkmessaging/endpoints.go +++ b/service/chimesdkmessaging/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chimesdkmessaging/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME_SDK_MESSAGING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime SDK Messaging", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chimesdkmessaging/endpoints_config_test.go b/service/chimesdkmessaging/endpoints_config_test.go new file mode 100644 index 00000000000..177aff7663a --- /dev/null +++ b/service/chimesdkmessaging/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chimesdkmessaging + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-messaging.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-messaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + expectURL: aws.String("https://env-chime-sdk-messaging.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-messaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + expectURL: aws.String("http://config-chime-sdk-messaging.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-messaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-messaging.dev", + clientEndpoint: aws.String("https://client-chime-sdk-messaging.dev"), + expectURL: aws.String("https://client-chime-sdk-messaging.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME_SDK_MESSAGING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chimesdkmessaging/generated.json b/service/chimesdkmessaging/generated.json index 9181f7e4eeb..ddaef6860b0 100644 --- a/service/chimesdkmessaging/generated.json +++ b/service/chimesdkmessaging/generated.json @@ -63,6 +63,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chimesdkmessaging/go.mod b/service/chimesdkmessaging/go.mod index 28dc5d02883..183cb7a1123 100644 --- a/service/chimesdkmessaging/go.mod +++ b/service/chimesdkmessaging/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chimesdkmessaging/go.sum b/service/chimesdkmessaging/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chimesdkmessaging/go.sum +++ b/service/chimesdkmessaging/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/chimesdkvoice/api_client.go b/service/chimesdkvoice/api_client.go index 0c464645bf8..e720d34baba 100644 --- a/service/chimesdkvoice/api_client.go +++ b/service/chimesdkvoice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/chimesdkvoice/endpoints.go b/service/chimesdkvoice/endpoints.go index caff88b0bc0..03045c783d6 100644 --- a/service/chimesdkvoice/endpoints.go +++ b/service/chimesdkvoice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/chimesdkvoice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CHIME_SDK_VOICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Chime SDK Voice", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/chimesdkvoice/endpoints_config_test.go b/service/chimesdkvoice/endpoints_config_test.go new file mode 100644 index 00000000000..ef799a38ff0 --- /dev/null +++ b/service/chimesdkvoice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package chimesdkvoice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-voice.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + expectURL: aws.String("https://env-chime-sdk-voice.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + expectURL: aws.String("http://config-chime-sdk-voice.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-chime-sdk-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-chime-sdk-voice.dev", + clientEndpoint: aws.String("https://client-chime-sdk-voice.dev"), + expectURL: aws.String("https://client-chime-sdk-voice.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CHIME_SDK_VOICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/chimesdkvoice/generated.json b/service/chimesdkvoice/generated.json index f62eded7e82..97ce01e7759 100644 --- a/service/chimesdkvoice/generated.json +++ b/service/chimesdkvoice/generated.json @@ -105,6 +105,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/chimesdkvoice/go.mod b/service/chimesdkvoice/go.mod index ead4b39e030..f6336d97f85 100644 --- a/service/chimesdkvoice/go.mod +++ b/service/chimesdkvoice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/chimesdkvoice/go.sum b/service/chimesdkvoice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/chimesdkvoice/go.sum +++ b/service/chimesdkvoice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cleanrooms/api_client.go b/service/cleanrooms/api_client.go index 7beb3d39b47..73e1a244b00 100644 --- a/service/cleanrooms/api_client.go +++ b/service/cleanrooms/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cleanrooms/endpoints.go b/service/cleanrooms/endpoints.go index c838db910d4..dd43b44fb5e 100644 --- a/service/cleanrooms/endpoints.go +++ b/service/cleanrooms/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cleanrooms/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLEANROOMS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CleanRooms", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cleanrooms/endpoints_config_test.go b/service/cleanrooms/endpoints_config_test.go new file mode 100644 index 00000000000..bfa43d415e1 --- /dev/null +++ b/service/cleanrooms/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cleanrooms + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cleanrooms.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cleanrooms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + expectURL: aws.String("https://env-cleanrooms.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cleanrooms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + expectURL: aws.String("http://config-cleanrooms.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cleanrooms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cleanrooms.dev", + clientEndpoint: aws.String("https://client-cleanrooms.dev"), + expectURL: aws.String("https://client-cleanrooms.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLEANROOMS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cleanrooms/generated.json b/service/cleanrooms/generated.json index f078eb3667d..1fc841cf1a7 100644 --- a/service/cleanrooms/generated.json +++ b/service/cleanrooms/generated.json @@ -57,6 +57,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cleanrooms/go.mod b/service/cleanrooms/go.mod index ff9726ddccb..52a7698e263 100644 --- a/service/cleanrooms/go.mod +++ b/service/cleanrooms/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cleanrooms/go.sum b/service/cleanrooms/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cleanrooms/go.sum +++ b/service/cleanrooms/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloud9/api_client.go b/service/cloud9/api_client.go index deffa86cacf..ed0156df0ce 100644 --- a/service/cloud9/api_client.go +++ b/service/cloud9/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloud9/endpoints.go b/service/cloud9/endpoints.go index 86e9956bb07..268c7998bdb 100644 --- a/service/cloud9/endpoints.go +++ b/service/cloud9/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloud9/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUD9") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cloud9", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloud9/endpoints_config_test.go b/service/cloud9/endpoints_config_test.go new file mode 100644 index 00000000000..1f8947ff08a --- /dev/null +++ b/service/cloud9/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloud9 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloud9.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloud9.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + expectURL: aws.String("https://env-cloud9.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloud9.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + expectURL: aws.String("http://config-cloud9.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloud9.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloud9.dev", + clientEndpoint: aws.String("https://client-cloud9.dev"), + expectURL: aws.String("https://client-cloud9.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUD9", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloud9/generated.json b/service/cloud9/generated.json index 3a087976fe6..cdec603c0a3 100644 --- a/service/cloud9/generated.json +++ b/service/cloud9/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloud9/go.mod b/service/cloud9/go.mod index b47d640fd57..43f5c23b285 100644 --- a/service/cloud9/go.mod +++ b/service/cloud9/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloud9/go.sum b/service/cloud9/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloud9/go.sum +++ b/service/cloud9/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudcontrol/api_client.go b/service/cloudcontrol/api_client.go index f4688365306..cfcec8c5e72 100644 --- a/service/cloudcontrol/api_client.go +++ b/service/cloudcontrol/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudcontrol/endpoints.go b/service/cloudcontrol/endpoints.go index 50e159795d4..74de6d8f6be 100644 --- a/service/cloudcontrol/endpoints.go +++ b/service/cloudcontrol/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDCONTROL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudControl", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudcontrol/endpoints_config_test.go b/service/cloudcontrol/endpoints_config_test.go new file mode 100644 index 00000000000..c572eeb52bf --- /dev/null +++ b/service/cloudcontrol/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudcontrol + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudcontrol.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudcontrol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + expectURL: aws.String("https://env-cloudcontrol.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudcontrol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + expectURL: aws.String("http://config-cloudcontrol.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudcontrol.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudcontrol.dev", + clientEndpoint: aws.String("https://client-cloudcontrol.dev"), + expectURL: aws.String("https://client-cloudcontrol.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDCONTROL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudcontrol/generated.json b/service/cloudcontrol/generated.json index 7330385e0d3..0667631b1d7 100644 --- a/service/cloudcontrol/generated.json +++ b/service/cloudcontrol/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudcontrol/go.mod b/service/cloudcontrol/go.mod index b586f47ce6b..87481eacd65 100644 --- a/service/cloudcontrol/go.mod +++ b/service/cloudcontrol/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudcontrol/go.sum b/service/cloudcontrol/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/cloudcontrol/go.sum +++ b/service/cloudcontrol/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/clouddirectory/api_client.go b/service/clouddirectory/api_client.go index d2d8475e397..064e6e0b94d 100644 --- a/service/clouddirectory/api_client.go +++ b/service/clouddirectory/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/clouddirectory/endpoints.go b/service/clouddirectory/endpoints.go index 591e4ee6c3c..661657f12bd 100644 --- a/service/clouddirectory/endpoints.go +++ b/service/clouddirectory/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/clouddirectory/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDDIRECTORY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudDirectory", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/clouddirectory/endpoints_config_test.go b/service/clouddirectory/endpoints_config_test.go new file mode 100644 index 00000000000..f922a116be3 --- /dev/null +++ b/service/clouddirectory/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package clouddirectory + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-clouddirectory.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-clouddirectory.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + expectURL: aws.String("https://env-clouddirectory.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-clouddirectory.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + expectURL: aws.String("http://config-clouddirectory.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-clouddirectory.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-clouddirectory.dev", + clientEndpoint: aws.String("https://client-clouddirectory.dev"), + expectURL: aws.String("https://client-clouddirectory.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDDIRECTORY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/clouddirectory/generated.json b/service/clouddirectory/generated.json index 6ae8113136e..77521f28faa 100644 --- a/service/clouddirectory/generated.json +++ b/service/clouddirectory/generated.json @@ -78,6 +78,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/clouddirectory/go.mod b/service/clouddirectory/go.mod index 147fbf8fb76..fe1eff360aa 100644 --- a/service/clouddirectory/go.mod +++ b/service/clouddirectory/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/clouddirectory/go.sum b/service/clouddirectory/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/clouddirectory/go.sum +++ b/service/clouddirectory/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudformation/api_client.go b/service/cloudformation/api_client.go index d8cd5d5dc20..137ac5d0f78 100644 --- a/service/cloudformation/api_client.go +++ b/service/cloudformation/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudformation/endpoints.go b/service/cloudformation/endpoints.go index 16f40e9478b..ae66c819790 100644 --- a/service/cloudformation/endpoints.go +++ b/service/cloudformation/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudformation/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDFORMATION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudFormation", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudformation/endpoints_config_test.go b/service/cloudformation/endpoints_config_test.go new file mode 100644 index 00000000000..669a5a1dd5b --- /dev/null +++ b/service/cloudformation/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudformation + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudformation.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + expectURL: aws.String("https://env-cloudformation.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + expectURL: aws.String("http://config-cloudformation.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudformation.dev", + clientEndpoint: aws.String("https://client-cloudformation.dev"), + expectURL: aws.String("https://client-cloudformation.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDFORMATION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudformation/generated.json b/service/cloudformation/generated.json index 83aaae9c614..f122680d935 100644 --- a/service/cloudformation/generated.json +++ b/service/cloudformation/generated.json @@ -83,6 +83,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudformation/go.mod b/service/cloudformation/go.mod index 366796948a9..922edc87c90 100644 --- a/service/cloudformation/go.mod +++ b/service/cloudformation/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudformation/go.sum b/service/cloudformation/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/cloudformation/go.sum +++ b/service/cloudformation/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/cloudfront/api_client.go b/service/cloudfront/api_client.go index ef395da0712..5c490daf6a6 100644 --- a/service/cloudfront/api_client.go +++ b/service/cloudfront/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudfront/endpoints.go b/service/cloudfront/endpoints.go index 1528d73285e..ea281b4f1a0 100644 --- a/service/cloudfront/endpoints.go +++ b/service/cloudfront/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudfront/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDFRONT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudFront", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudfront/endpoints_config_test.go b/service/cloudfront/endpoints_config_test.go new file mode 100644 index 00000000000..b527ba56121 --- /dev/null +++ b/service/cloudfront/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudfront + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudfront.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudfront.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + expectURL: aws.String("https://env-cloudfront.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudfront.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + expectURL: aws.String("http://config-cloudfront.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudfront.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudfront.dev", + clientEndpoint: aws.String("https://client-cloudfront.dev"), + expectURL: aws.String("https://client-cloudfront.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDFRONT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudfront/generated.json b/service/cloudfront/generated.json index 636857a06ab..a986db7aa57 100644 --- a/service/cloudfront/generated.json +++ b/service/cloudfront/generated.json @@ -119,6 +119,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudfront/go.mod b/service/cloudfront/go.mod index 1ada520838b..14a0477aad9 100644 --- a/service/cloudfront/go.mod +++ b/service/cloudfront/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudfront/go.sum b/service/cloudfront/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/cloudfront/go.sum +++ b/service/cloudfront/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/cloudhsm/api_client.go b/service/cloudhsm/api_client.go index 594bcff00a9..e8cdaac2b86 100644 --- a/service/cloudhsm/api_client.go +++ b/service/cloudhsm/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudhsm/endpoints.go b/service/cloudhsm/endpoints.go index 2dfc7f25824..044408bc34f 100644 --- a/service/cloudhsm/endpoints.go +++ b/service/cloudhsm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudhsm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDHSM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudHSM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudhsm/endpoints_config_test.go b/service/cloudhsm/endpoints_config_test.go new file mode 100644 index 00000000000..d9ddf89ec16 --- /dev/null +++ b/service/cloudhsm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudhsm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + expectURL: aws.String("https://env-cloudhsm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + expectURL: aws.String("http://config-cloudhsm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm.dev", + clientEndpoint: aws.String("https://client-cloudhsm.dev"), + expectURL: aws.String("https://client-cloudhsm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDHSM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudhsm/generated.json b/service/cloudhsm/generated.json index 87340764e0b..bba8b3a1f67 100644 --- a/service/cloudhsm/generated.json +++ b/service/cloudhsm/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudhsm/go.mod b/service/cloudhsm/go.mod index be1d893addc..6c2892a5c9c 100644 --- a/service/cloudhsm/go.mod +++ b/service/cloudhsm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudhsm/go.sum b/service/cloudhsm/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudhsm/go.sum +++ b/service/cloudhsm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudhsmv2/api_client.go b/service/cloudhsmv2/api_client.go index 730b1c0677b..fcb6a6e6903 100644 --- a/service/cloudhsmv2/api_client.go +++ b/service/cloudhsmv2/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudhsmv2/endpoints.go b/service/cloudhsmv2/endpoints.go index 80df5da4b6c..a153b1d0a17 100644 --- a/service/cloudhsmv2/endpoints.go +++ b/service/cloudhsmv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudhsmv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDHSM_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudHSM V2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudhsmv2/endpoints_config_test.go b/service/cloudhsmv2/endpoints_config_test.go new file mode 100644 index 00000000000..3ff6306cd2d --- /dev/null +++ b/service/cloudhsmv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudhsmv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + expectURL: aws.String("https://env-cloudhsm-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + expectURL: aws.String("http://config-cloudhsm-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudhsm-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudhsm-v2.dev", + clientEndpoint: aws.String("https://client-cloudhsm-v2.dev"), + expectURL: aws.String("https://client-cloudhsm-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDHSM_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudhsmv2/generated.json b/service/cloudhsmv2/generated.json index 327374fde0f..e27371fd957 100644 --- a/service/cloudhsmv2/generated.json +++ b/service/cloudhsmv2/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudhsmv2/go.mod b/service/cloudhsmv2/go.mod index ada11c7b183..2a4f361688b 100644 --- a/service/cloudhsmv2/go.mod +++ b/service/cloudhsmv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudhsmv2/go.sum b/service/cloudhsmv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudhsmv2/go.sum +++ b/service/cloudhsmv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudsearch/api_client.go b/service/cloudsearch/api_client.go index 873a17a45f5..1984b687dab 100644 --- a/service/cloudsearch/api_client.go +++ b/service/cloudsearch/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudsearch/endpoints.go b/service/cloudsearch/endpoints.go index 06db8c0afc2..efcdb93fc9a 100644 --- a/service/cloudsearch/endpoints.go +++ b/service/cloudsearch/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudsearch/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDSEARCH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudSearch", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudsearch/endpoints_config_test.go b/service/cloudsearch/endpoints_config_test.go new file mode 100644 index 00000000000..38f38bbe0a6 --- /dev/null +++ b/service/cloudsearch/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudsearch + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + expectURL: aws.String("https://env-cloudsearch.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + expectURL: aws.String("http://config-cloudsearch.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch.dev", + clientEndpoint: aws.String("https://client-cloudsearch.dev"), + expectURL: aws.String("https://client-cloudsearch.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDSEARCH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudsearch/generated.json b/service/cloudsearch/generated.json index 97b8a5a1b19..6ea10f1b2e0 100644 --- a/service/cloudsearch/generated.json +++ b/service/cloudsearch/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudsearch/go.mod b/service/cloudsearch/go.mod index 72fa7878d08..cabbdafd964 100644 --- a/service/cloudsearch/go.mod +++ b/service/cloudsearch/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudsearch/go.sum b/service/cloudsearch/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudsearch/go.sum +++ b/service/cloudsearch/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudsearchdomain/api_client.go b/service/cloudsearchdomain/api_client.go index b9c3029b91a..3792e9328c5 100644 --- a/service/cloudsearchdomain/api_client.go +++ b/service/cloudsearchdomain/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudsearchdomain/endpoints.go b/service/cloudsearchdomain/endpoints.go index 2a66f4bac7b..9f20cf76ba1 100644 --- a/service/cloudsearchdomain/endpoints.go +++ b/service/cloudsearchdomain/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudsearchdomain/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDSEARCH_DOMAIN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudSearch Domain", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudsearchdomain/endpoints_config_test.go b/service/cloudsearchdomain/endpoints_config_test.go new file mode 100644 index 00000000000..778c34afeb7 --- /dev/null +++ b/service/cloudsearchdomain/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudsearchdomain + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch-domain.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch-domain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + expectURL: aws.String("https://env-cloudsearch-domain.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch-domain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + expectURL: aws.String("http://config-cloudsearch-domain.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudsearch-domain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudsearch-domain.dev", + clientEndpoint: aws.String("https://client-cloudsearch-domain.dev"), + expectURL: aws.String("https://client-cloudsearch-domain.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDSEARCH_DOMAIN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudsearchdomain/generated.json b/service/cloudsearchdomain/generated.json index 38a896c974b..b9b9d50a9df 100644 --- a/service/cloudsearchdomain/generated.json +++ b/service/cloudsearchdomain/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudsearchdomain/go.mod b/service/cloudsearchdomain/go.mod index 3b9c16739fe..e9ed78b8c12 100644 --- a/service/cloudsearchdomain/go.mod +++ b/service/cloudsearchdomain/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudsearchdomain/go.sum b/service/cloudsearchdomain/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudsearchdomain/go.sum +++ b/service/cloudsearchdomain/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudtrail/api_client.go b/service/cloudtrail/api_client.go index 0a5696f1298..1905e08a4c0 100644 --- a/service/cloudtrail/api_client.go +++ b/service/cloudtrail/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudtrail/endpoints.go b/service/cloudtrail/endpoints.go index 523a4b29771..31e7f4534d7 100644 --- a/service/cloudtrail/endpoints.go +++ b/service/cloudtrail/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudtrail/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDTRAIL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudTrail", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudtrail/endpoints_config_test.go b/service/cloudtrail/endpoints_config_test.go new file mode 100644 index 00000000000..7f45c31e99e --- /dev/null +++ b/service/cloudtrail/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudtrail + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + expectURL: aws.String("https://env-cloudtrail.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + expectURL: aws.String("http://config-cloudtrail.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail.dev", + clientEndpoint: aws.String("https://client-cloudtrail.dev"), + expectURL: aws.String("https://client-cloudtrail.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDTRAIL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudtrail/generated.json b/service/cloudtrail/generated.json index b97971bfeb4..32f07f1f380 100644 --- a/service/cloudtrail/generated.json +++ b/service/cloudtrail/generated.json @@ -58,6 +58,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudtrail/go.mod b/service/cloudtrail/go.mod index e3b9d964631..2d15f34f912 100644 --- a/service/cloudtrail/go.mod +++ b/service/cloudtrail/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudtrail/go.sum b/service/cloudtrail/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudtrail/go.sum +++ b/service/cloudtrail/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudtraildata/api_client.go b/service/cloudtraildata/api_client.go index 8af6e96fdad..a4f3739dfd8 100644 --- a/service/cloudtraildata/api_client.go +++ b/service/cloudtraildata/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudtraildata/endpoints.go b/service/cloudtraildata/endpoints.go index 82541f83283..96614e55d77 100644 --- a/service/cloudtraildata/endpoints.go +++ b/service/cloudtraildata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudtraildata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDTRAIL_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudTrail Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudtraildata/endpoints_config_test.go b/service/cloudtraildata/endpoints_config_test.go new file mode 100644 index 00000000000..ab5b3d3b6c4 --- /dev/null +++ b/service/cloudtraildata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudtraildata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + expectURL: aws.String("https://env-cloudtrail-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + expectURL: aws.String("http://config-cloudtrail-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudtrail-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudtrail-data.dev", + clientEndpoint: aws.String("https://client-cloudtrail-data.dev"), + expectURL: aws.String("https://client-cloudtrail-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDTRAIL_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudtraildata/generated.json b/service/cloudtraildata/generated.json index e7ead5af137..ef7d2a5214e 100644 --- a/service/cloudtraildata/generated.json +++ b/service/cloudtraildata/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudtraildata/go.mod b/service/cloudtraildata/go.mod index c010296cd8c..8e0ca4a78f3 100644 --- a/service/cloudtraildata/go.mod +++ b/service/cloudtraildata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudtraildata/go.sum b/service/cloudtraildata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudtraildata/go.sum +++ b/service/cloudtraildata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudwatch/api_client.go b/service/cloudwatch/api_client.go index 25177a37aa3..e92ed4061d8 100644 --- a/service/cloudwatch/api_client.go +++ b/service/cloudwatch/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudwatch/endpoints.go b/service/cloudwatch/endpoints.go index 73c237ed52c..d3a717be2cb 100644 --- a/service/cloudwatch/endpoints.go +++ b/service/cloudwatch/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudwatch/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDWATCH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudWatch", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudwatch/endpoints_config_test.go b/service/cloudwatch/endpoints_config_test.go new file mode 100644 index 00000000000..7fb7f0da05c --- /dev/null +++ b/service/cloudwatch/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudwatch + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + expectURL: aws.String("https://env-cloudwatch.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + expectURL: aws.String("http://config-cloudwatch.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch.dev", + clientEndpoint: aws.String("https://client-cloudwatch.dev"), + expectURL: aws.String("https://client-cloudwatch.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDWATCH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudwatch/generated.json b/service/cloudwatch/generated.json index 28a11deffe7..6553b6ae02c 100644 --- a/service/cloudwatch/generated.json +++ b/service/cloudwatch/generated.json @@ -51,6 +51,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudwatch/go.mod b/service/cloudwatch/go.mod index cec51cee155..ac3b601965f 100644 --- a/service/cloudwatch/go.mod +++ b/service/cloudwatch/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudwatch/go.sum b/service/cloudwatch/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/cloudwatch/go.sum +++ b/service/cloudwatch/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/cloudwatchevents/api_client.go b/service/cloudwatchevents/api_client.go index cc4eb9982cf..97524b08e7b 100644 --- a/service/cloudwatchevents/api_client.go +++ b/service/cloudwatchevents/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudwatchevents/endpoints.go b/service/cloudwatchevents/endpoints.go index b59ac2a8258..55847b59c28 100644 --- a/service/cloudwatchevents/endpoints.go +++ b/service/cloudwatchevents/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudwatchevents/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDWATCH_EVENTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudWatch Events", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudwatchevents/endpoints_config_test.go b/service/cloudwatchevents/endpoints_config_test.go new file mode 100644 index 00000000000..6494b37e471 --- /dev/null +++ b/service/cloudwatchevents/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudwatchevents + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-events.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + expectURL: aws.String("https://env-cloudwatch-events.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + expectURL: aws.String("http://config-cloudwatch-events.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-events.dev", + clientEndpoint: aws.String("https://client-cloudwatch-events.dev"), + expectURL: aws.String("https://client-cloudwatch-events.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDWATCH_EVENTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudwatchevents/generated.json b/service/cloudwatchevents/generated.json index c5223f5ee47..dbb8ba65811 100644 --- a/service/cloudwatchevents/generated.json +++ b/service/cloudwatchevents/generated.json @@ -63,6 +63,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudwatchevents/go.mod b/service/cloudwatchevents/go.mod index 889cbe020c9..0836e61f007 100644 --- a/service/cloudwatchevents/go.mod +++ b/service/cloudwatchevents/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudwatchevents/go.sum b/service/cloudwatchevents/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudwatchevents/go.sum +++ b/service/cloudwatchevents/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cloudwatchlogs/api_client.go b/service/cloudwatchlogs/api_client.go index c5665a581c3..c792f393ed7 100644 --- a/service/cloudwatchlogs/api_client.go +++ b/service/cloudwatchlogs/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cloudwatchlogs/endpoints.go b/service/cloudwatchlogs/endpoints.go index 9953488a7ae..01dbf5b7863 100644 --- a/service/cloudwatchlogs/endpoints.go +++ b/service/cloudwatchlogs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CLOUDWATCH_LOGS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CloudWatch Logs", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cloudwatchlogs/endpoints_config_test.go b/service/cloudwatchlogs/endpoints_config_test.go new file mode 100644 index 00000000000..e5785e83795 --- /dev/null +++ b/service/cloudwatchlogs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cloudwatchlogs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-logs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-logs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + expectURL: aws.String("https://env-cloudwatch-logs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-logs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + expectURL: aws.String("http://config-cloudwatch-logs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cloudwatch-logs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cloudwatch-logs.dev", + clientEndpoint: aws.String("https://client-cloudwatch-logs.dev"), + expectURL: aws.String("https://client-cloudwatch-logs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CLOUDWATCH_LOGS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cloudwatchlogs/generated.json b/service/cloudwatchlogs/generated.json index 028f189f529..4ca5b4bf985 100644 --- a/service/cloudwatchlogs/generated.json +++ b/service/cloudwatchlogs/generated.json @@ -63,6 +63,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cloudwatchlogs/go.mod b/service/cloudwatchlogs/go.mod index 423c6f7fd3f..5800b9f1ff1 100644 --- a/service/cloudwatchlogs/go.mod +++ b/service/cloudwatchlogs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cloudwatchlogs/go.sum b/service/cloudwatchlogs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cloudwatchlogs/go.sum +++ b/service/cloudwatchlogs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codeartifact/api_client.go b/service/codeartifact/api_client.go index ce5046a219b..b8f020523e7 100644 --- a/service/codeartifact/api_client.go +++ b/service/codeartifact/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codeartifact/endpoints.go b/service/codeartifact/endpoints.go index c3696275f7b..0135a103fa6 100644 --- a/service/codeartifact/endpoints.go +++ b/service/codeartifact/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codeartifact/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEARTIFACT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "codeartifact", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codeartifact/endpoints_config_test.go b/service/codeartifact/endpoints_config_test.go new file mode 100644 index 00000000000..a9cc742624c --- /dev/null +++ b/service/codeartifact/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codeartifact + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeartifact.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeartifact.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + expectURL: aws.String("https://env-codeartifact.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeartifact.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + expectURL: aws.String("http://config-codeartifact.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeartifact.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeartifact.dev", + clientEndpoint: aws.String("https://client-codeartifact.dev"), + expectURL: aws.String("https://client-codeartifact.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEARTIFACT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codeartifact/generated.json b/service/codeartifact/generated.json index e9a0b31de48..981d8b9e64e 100644 --- a/service/codeartifact/generated.json +++ b/service/codeartifact/generated.json @@ -50,6 +50,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codeartifact/go.mod b/service/codeartifact/go.mod index dec96f5e6d9..a87e1ffe17b 100644 --- a/service/codeartifact/go.mod +++ b/service/codeartifact/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codeartifact/go.sum b/service/codeartifact/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codeartifact/go.sum +++ b/service/codeartifact/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codebuild/api_client.go b/service/codebuild/api_client.go index 1c392b14b56..31285d0a6c8 100644 --- a/service/codebuild/api_client.go +++ b/service/codebuild/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codebuild/endpoints.go b/service/codebuild/endpoints.go index 26d39df9395..348f3bacb41 100644 --- a/service/codebuild/endpoints.go +++ b/service/codebuild/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codebuild/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEBUILD") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeBuild", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codebuild/endpoints_config_test.go b/service/codebuild/endpoints_config_test.go new file mode 100644 index 00000000000..e65fbca771e --- /dev/null +++ b/service/codebuild/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codebuild + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codebuild.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codebuild.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + expectURL: aws.String("https://env-codebuild.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codebuild.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + expectURL: aws.String("http://config-codebuild.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codebuild.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codebuild.dev", + clientEndpoint: aws.String("https://client-codebuild.dev"), + expectURL: aws.String("https://client-codebuild.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEBUILD", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codebuild/generated.json b/service/codebuild/generated.json index 74cdc60ac7b..c0a6c8834b5 100644 --- a/service/codebuild/generated.json +++ b/service/codebuild/generated.json @@ -57,6 +57,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codebuild/go.mod b/service/codebuild/go.mod index 472252d3be5..3214e8ed342 100644 --- a/service/codebuild/go.mod +++ b/service/codebuild/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codebuild/go.sum b/service/codebuild/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codebuild/go.sum +++ b/service/codebuild/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codecatalyst/api_client.go b/service/codecatalyst/api_client.go index 5cbcc04caa8..637c8e4f0d3 100644 --- a/service/codecatalyst/api_client.go +++ b/service/codecatalyst/api_client.go @@ -294,6 +294,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codecatalyst/endpoints.go b/service/codecatalyst/endpoints.go index e0049a2e05e..1d53a367c93 100644 --- a/service/codecatalyst/endpoints.go +++ b/service/codecatalyst/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codecatalyst/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODECATALYST") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeCatalyst", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codecatalyst/endpoints_config_test.go b/service/codecatalyst/endpoints_config_test.go new file mode 100644 index 00000000000..7e371ac7b89 --- /dev/null +++ b/service/codecatalyst/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codecatalyst + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecatalyst.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecatalyst.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + expectURL: aws.String("https://env-codecatalyst.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecatalyst.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + expectURL: aws.String("http://config-codecatalyst.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecatalyst.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecatalyst.dev", + clientEndpoint: aws.String("https://client-codecatalyst.dev"), + expectURL: aws.String("https://client-codecatalyst.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODECATALYST", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codecatalyst/generated.json b/service/codecatalyst/generated.json index 7163c40dff8..c7459c7e522 100644 --- a/service/codecatalyst/generated.json +++ b/service/codecatalyst/generated.json @@ -45,6 +45,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codecatalyst/go.mod b/service/codecatalyst/go.mod index 87d7144c43b..59aaa707354 100644 --- a/service/codecatalyst/go.mod +++ b/service/codecatalyst/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codecatalyst/go.sum b/service/codecatalyst/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codecatalyst/go.sum +++ b/service/codecatalyst/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codecommit/api_client.go b/service/codecommit/api_client.go index c530dd3da2d..712e6b5bc88 100644 --- a/service/codecommit/api_client.go +++ b/service/codecommit/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codecommit/endpoints.go b/service/codecommit/endpoints.go index e7a0dde7f68..9ccaf984d6b 100644 --- a/service/codecommit/endpoints.go +++ b/service/codecommit/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codecommit/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODECOMMIT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeCommit", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codecommit/endpoints_config_test.go b/service/codecommit/endpoints_config_test.go new file mode 100644 index 00000000000..c2e4ecd0780 --- /dev/null +++ b/service/codecommit/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codecommit + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecommit.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecommit.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + expectURL: aws.String("https://env-codecommit.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecommit.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + expectURL: aws.String("http://config-codecommit.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codecommit.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codecommit.dev", + clientEndpoint: aws.String("https://client-codecommit.dev"), + expectURL: aws.String("https://client-codecommit.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODECOMMIT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codecommit/generated.json b/service/codecommit/generated.json index 18a57f5dd88..eac13d66815 100644 --- a/service/codecommit/generated.json +++ b/service/codecommit/generated.json @@ -90,6 +90,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codecommit/go.mod b/service/codecommit/go.mod index efc172d2bea..cca17e7adb4 100644 --- a/service/codecommit/go.mod +++ b/service/codecommit/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codecommit/go.sum b/service/codecommit/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codecommit/go.sum +++ b/service/codecommit/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codedeploy/api_client.go b/service/codedeploy/api_client.go index 59243712c16..2cec76d237a 100644 --- a/service/codedeploy/api_client.go +++ b/service/codedeploy/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codedeploy/endpoints.go b/service/codedeploy/endpoints.go index 168756b3844..b4f00a4e15a 100644 --- a/service/codedeploy/endpoints.go +++ b/service/codedeploy/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codedeploy/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEDEPLOY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeDeploy", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codedeploy/endpoints_config_test.go b/service/codedeploy/endpoints_config_test.go new file mode 100644 index 00000000000..cf09169e1cc --- /dev/null +++ b/service/codedeploy/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codedeploy + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codedeploy.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codedeploy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + expectURL: aws.String("https://env-codedeploy.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codedeploy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + expectURL: aws.String("http://config-codedeploy.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codedeploy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codedeploy.dev", + clientEndpoint: aws.String("https://client-codedeploy.dev"), + expectURL: aws.String("https://client-codedeploy.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEDEPLOY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codedeploy/generated.json b/service/codedeploy/generated.json index 19cf5d4eab2..2cb75028778 100644 --- a/service/codedeploy/generated.json +++ b/service/codedeploy/generated.json @@ -60,6 +60,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codedeploy/go.mod b/service/codedeploy/go.mod index a60a65c4de2..648d80a6304 100644 --- a/service/codedeploy/go.mod +++ b/service/codedeploy/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codedeploy/go.sum b/service/codedeploy/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/codedeploy/go.sum +++ b/service/codedeploy/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/codeguruprofiler/api_client.go b/service/codeguruprofiler/api_client.go index 5e7151035d2..a3e1b7a6962 100644 --- a/service/codeguruprofiler/api_client.go +++ b/service/codeguruprofiler/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codeguruprofiler/endpoints.go b/service/codeguruprofiler/endpoints.go index 1480c896690..f3f2fd937be 100644 --- a/service/codeguruprofiler/endpoints.go +++ b/service/codeguruprofiler/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEGURUPROFILER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeGuruProfiler", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codeguruprofiler/endpoints_config_test.go b/service/codeguruprofiler/endpoints_config_test.go new file mode 100644 index 00000000000..652fd6d6c38 --- /dev/null +++ b/service/codeguruprofiler/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codeguruprofiler + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguruprofiler.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguruprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + expectURL: aws.String("https://env-codeguruprofiler.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguruprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + expectURL: aws.String("http://config-codeguruprofiler.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguruprofiler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguruprofiler.dev", + clientEndpoint: aws.String("https://client-codeguruprofiler.dev"), + expectURL: aws.String("https://client-codeguruprofiler.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEGURUPROFILER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codeguruprofiler/generated.json b/service/codeguruprofiler/generated.json index fc5649e2b69..01bdc3a7e6b 100644 --- a/service/codeguruprofiler/generated.json +++ b/service/codeguruprofiler/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codeguruprofiler/go.mod b/service/codeguruprofiler/go.mod index beb96cf38c7..105f513be78 100644 --- a/service/codeguruprofiler/go.mod +++ b/service/codeguruprofiler/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codeguruprofiler/go.sum b/service/codeguruprofiler/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codeguruprofiler/go.sum +++ b/service/codeguruprofiler/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codegurureviewer/api_client.go b/service/codegurureviewer/api_client.go index 6ddd3f58a59..ee125ff15a7 100644 --- a/service/codegurureviewer/api_client.go +++ b/service/codegurureviewer/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codegurureviewer/endpoints.go b/service/codegurureviewer/endpoints.go index 1836e088274..1e529e9618b 100644 --- a/service/codegurureviewer/endpoints.go +++ b/service/codegurureviewer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codegurureviewer/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEGURU_REVIEWER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeGuru Reviewer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codegurureviewer/endpoints_config_test.go b/service/codegurureviewer/endpoints_config_test.go new file mode 100644 index 00000000000..c2810a9b3f9 --- /dev/null +++ b/service/codegurureviewer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codegurureviewer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-reviewer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-reviewer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + expectURL: aws.String("https://env-codeguru-reviewer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-reviewer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + expectURL: aws.String("http://config-codeguru-reviewer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-reviewer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-reviewer.dev", + clientEndpoint: aws.String("https://client-codeguru-reviewer.dev"), + expectURL: aws.String("https://client-codeguru-reviewer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEGURU_REVIEWER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codegurureviewer/generated.json b/service/codegurureviewer/generated.json index bac6539d730..57a23e4e946 100644 --- a/service/codegurureviewer/generated.json +++ b/service/codegurureviewer/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codegurureviewer/go.mod b/service/codegurureviewer/go.mod index 45c9b28767d..9b333b767fa 100644 --- a/service/codegurureviewer/go.mod +++ b/service/codegurureviewer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codegurureviewer/go.sum b/service/codegurureviewer/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/codegurureviewer/go.sum +++ b/service/codegurureviewer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/codegurusecurity/api_client.go b/service/codegurusecurity/api_client.go index e186036239d..2f8f27d5599 100644 --- a/service/codegurusecurity/api_client.go +++ b/service/codegurusecurity/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codegurusecurity/endpoints.go b/service/codegurusecurity/endpoints.go index 8317831f5d9..592da9581d3 100644 --- a/service/codegurusecurity/endpoints.go +++ b/service/codegurusecurity/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codegurusecurity/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEGURU_SECURITY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeGuru Security", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codegurusecurity/endpoints_config_test.go b/service/codegurusecurity/endpoints_config_test.go new file mode 100644 index 00000000000..488499de530 --- /dev/null +++ b/service/codegurusecurity/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codegurusecurity + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-security.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-security.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + expectURL: aws.String("https://env-codeguru-security.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-security.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + expectURL: aws.String("http://config-codeguru-security.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codeguru-security.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codeguru-security.dev", + clientEndpoint: aws.String("https://client-codeguru-security.dev"), + expectURL: aws.String("https://client-codeguru-security.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEGURU_SECURITY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codegurusecurity/generated.json b/service/codegurusecurity/generated.json index 2883d506ed0..3ef56dd1256 100644 --- a/service/codegurusecurity/generated.json +++ b/service/codegurusecurity/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codegurusecurity/go.mod b/service/codegurusecurity/go.mod index f795438ee28..47d0e44a82b 100644 --- a/service/codegurusecurity/go.mod +++ b/service/codegurusecurity/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codegurusecurity/go.sum b/service/codegurusecurity/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codegurusecurity/go.sum +++ b/service/codegurusecurity/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codepipeline/api_client.go b/service/codepipeline/api_client.go index 63b9dcf8344..47079de140b 100644 --- a/service/codepipeline/api_client.go +++ b/service/codepipeline/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codepipeline/endpoints.go b/service/codepipeline/endpoints.go index e795c5abe13..4ad9ef9aaea 100644 --- a/service/codepipeline/endpoints.go +++ b/service/codepipeline/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codepipeline/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODEPIPELINE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodePipeline", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codepipeline/endpoints_config_test.go b/service/codepipeline/endpoints_config_test.go new file mode 100644 index 00000000000..cb38c111f09 --- /dev/null +++ b/service/codepipeline/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codepipeline + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codepipeline.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codepipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + expectURL: aws.String("https://env-codepipeline.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codepipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + expectURL: aws.String("http://config-codepipeline.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codepipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codepipeline.dev", + clientEndpoint: aws.String("https://client-codepipeline.dev"), + expectURL: aws.String("https://client-codepipeline.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODEPIPELINE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codepipeline/generated.json b/service/codepipeline/generated.json index c685b3497e0..77eb5a8e1f9 100644 --- a/service/codepipeline/generated.json +++ b/service/codepipeline/generated.json @@ -51,6 +51,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codepipeline/go.mod b/service/codepipeline/go.mod index 42573d72360..27bc6942ea8 100644 --- a/service/codepipeline/go.mod +++ b/service/codepipeline/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codepipeline/go.sum b/service/codepipeline/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codepipeline/go.sum +++ b/service/codepipeline/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codestar/api_client.go b/service/codestar/api_client.go index aa6aa95a172..eedb5ca365e 100644 --- a/service/codestar/api_client.go +++ b/service/codestar/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codestar/endpoints.go b/service/codestar/endpoints.go index eac5cd486c4..bd97f73568a 100644 --- a/service/codestar/endpoints.go +++ b/service/codestar/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codestar/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODESTAR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeStar", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codestar/endpoints_config_test.go b/service/codestar/endpoints_config_test.go new file mode 100644 index 00000000000..ae2c83cbccb --- /dev/null +++ b/service/codestar/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codestar + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + expectURL: aws.String("https://env-codestar.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + expectURL: aws.String("http://config-codestar.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar.dev", + clientEndpoint: aws.String("https://client-codestar.dev"), + expectURL: aws.String("https://client-codestar.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODESTAR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codestar/generated.json b/service/codestar/generated.json index 0c4283a8cc8..81b18e7cf96 100644 --- a/service/codestar/generated.json +++ b/service/codestar/generated.json @@ -30,6 +30,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codestar/go.mod b/service/codestar/go.mod index 6c9f28dd6b3..67c51775f82 100644 --- a/service/codestar/go.mod +++ b/service/codestar/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codestar/go.sum b/service/codestar/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codestar/go.sum +++ b/service/codestar/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codestarconnections/api_client.go b/service/codestarconnections/api_client.go index 4c00c1ccd4a..dfce0bc9388 100644 --- a/service/codestarconnections/api_client.go +++ b/service/codestarconnections/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codestarconnections/endpoints.go b/service/codestarconnections/endpoints.go index 07689247ee2..36ba5589a8d 100644 --- a/service/codestarconnections/endpoints.go +++ b/service/codestarconnections/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codestarconnections/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODESTAR_CONNECTIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "CodeStar connections", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codestarconnections/endpoints_config_test.go b/service/codestarconnections/endpoints_config_test.go new file mode 100644 index 00000000000..0e974510737 --- /dev/null +++ b/service/codestarconnections/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codestarconnections + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-connections.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-connections.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + expectURL: aws.String("https://env-codestar-connections.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-connections.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + expectURL: aws.String("http://config-codestar-connections.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-connections.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-connections.dev", + clientEndpoint: aws.String("https://client-codestar-connections.dev"), + expectURL: aws.String("https://client-codestar-connections.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODESTAR_CONNECTIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codestarconnections/generated.json b/service/codestarconnections/generated.json index 3a22d038754..e1b6050dd20 100644 --- a/service/codestarconnections/generated.json +++ b/service/codestarconnections/generated.json @@ -24,6 +24,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codestarconnections/go.mod b/service/codestarconnections/go.mod index f8ee70df8d0..d64f09c5912 100644 --- a/service/codestarconnections/go.mod +++ b/service/codestarconnections/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codestarconnections/go.sum b/service/codestarconnections/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codestarconnections/go.sum +++ b/service/codestarconnections/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/codestarnotifications/api_client.go b/service/codestarnotifications/api_client.go index 9cf2ee13bb4..4387fc4db4f 100644 --- a/service/codestarnotifications/api_client.go +++ b/service/codestarnotifications/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/codestarnotifications/endpoints.go b/service/codestarnotifications/endpoints.go index 71d5e5028c9..e3fc9023c5a 100644 --- a/service/codestarnotifications/endpoints.go +++ b/service/codestarnotifications/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/codestarnotifications/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CODESTAR_NOTIFICATIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "codestar notifications", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/codestarnotifications/endpoints_config_test.go b/service/codestarnotifications/endpoints_config_test.go new file mode 100644 index 00000000000..5a914075e64 --- /dev/null +++ b/service/codestarnotifications/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package codestarnotifications + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-notifications.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-notifications.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + expectURL: aws.String("https://env-codestar-notifications.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-notifications.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + expectURL: aws.String("http://config-codestar-notifications.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-codestar-notifications.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-codestar-notifications.dev", + clientEndpoint: aws.String("https://client-codestar-notifications.dev"), + expectURL: aws.String("https://client-codestar-notifications.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CODESTAR_NOTIFICATIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/codestarnotifications/generated.json b/service/codestarnotifications/generated.json index 9aa678f7bbc..86cdd7b4e44 100644 --- a/service/codestarnotifications/generated.json +++ b/service/codestarnotifications/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/codestarnotifications/go.mod b/service/codestarnotifications/go.mod index 3bd8814d79c..1935fd212b4 100644 --- a/service/codestarnotifications/go.mod +++ b/service/codestarnotifications/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/codestarnotifications/go.sum b/service/codestarnotifications/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/codestarnotifications/go.sum +++ b/service/codestarnotifications/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cognitoidentity/api_client.go b/service/cognitoidentity/api_client.go index 08a0f6117f9..c8d6dc531d6 100644 --- a/service/cognitoidentity/api_client.go +++ b/service/cognitoidentity/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cognitoidentity/endpoints.go b/service/cognitoidentity/endpoints.go index dc2cdbec61d..dfa182aa2ef 100644 --- a/service/cognitoidentity/endpoints.go +++ b/service/cognitoidentity/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cognitoidentity/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COGNITO_IDENTITY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cognito Identity", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cognitoidentity/endpoints_config_test.go b/service/cognitoidentity/endpoints_config_test.go new file mode 100644 index 00000000000..8b82046f0a7 --- /dev/null +++ b/service/cognitoidentity/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cognitoidentity + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + expectURL: aws.String("https://env-cognito-identity.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + expectURL: aws.String("http://config-cognito-identity.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity.dev", + clientEndpoint: aws.String("https://client-cognito-identity.dev"), + expectURL: aws.String("https://client-cognito-identity.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COGNITO_IDENTITY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cognitoidentity/generated.json b/service/cognitoidentity/generated.json index e60a92dd597..bfec40aa50b 100644 --- a/service/cognitoidentity/generated.json +++ b/service/cognitoidentity/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cognitoidentity/go.mod b/service/cognitoidentity/go.mod index d93fe6236e6..906242892c8 100644 --- a/service/cognitoidentity/go.mod +++ b/service/cognitoidentity/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cognitoidentity/go.sum b/service/cognitoidentity/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cognitoidentity/go.sum +++ b/service/cognitoidentity/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cognitoidentityprovider/api_client.go b/service/cognitoidentityprovider/api_client.go index 6864474be1c..619ff1e37e9 100644 --- a/service/cognitoidentityprovider/api_client.go +++ b/service/cognitoidentityprovider/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cognitoidentityprovider/endpoints.go b/service/cognitoidentityprovider/endpoints.go index 971c64d86ca..fda81dc65d5 100644 --- a/service/cognitoidentityprovider/endpoints.go +++ b/service/cognitoidentityprovider/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COGNITO_IDENTITY_PROVIDER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cognito Identity Provider", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cognitoidentityprovider/endpoints_config_test.go b/service/cognitoidentityprovider/endpoints_config_test.go new file mode 100644 index 00000000000..a9435cd3ecf --- /dev/null +++ b/service/cognitoidentityprovider/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cognitoidentityprovider + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity-provider.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity-provider.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + expectURL: aws.String("https://env-cognito-identity-provider.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity-provider.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + expectURL: aws.String("http://config-cognito-identity-provider.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-identity-provider.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-identity-provider.dev", + clientEndpoint: aws.String("https://client-cognito-identity-provider.dev"), + expectURL: aws.String("https://client-cognito-identity-provider.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COGNITO_IDENTITY_PROVIDER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cognitoidentityprovider/generated.json b/service/cognitoidentityprovider/generated.json index 4232b3959c1..298c52ab8e7 100644 --- a/service/cognitoidentityprovider/generated.json +++ b/service/cognitoidentityprovider/generated.json @@ -115,6 +115,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cognitoidentityprovider/go.mod b/service/cognitoidentityprovider/go.mod index 11cb4d36478..c768edcc883 100644 --- a/service/cognitoidentityprovider/go.mod +++ b/service/cognitoidentityprovider/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cognitoidentityprovider/go.sum b/service/cognitoidentityprovider/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cognitoidentityprovider/go.sum +++ b/service/cognitoidentityprovider/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/cognitosync/api_client.go b/service/cognitosync/api_client.go index 079952a898f..f2ffa77a649 100644 --- a/service/cognitosync/api_client.go +++ b/service/cognitosync/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/cognitosync/endpoints.go b/service/cognitosync/endpoints.go index 0e6eaf82d4f..5269d640409 100644 --- a/service/cognitosync/endpoints.go +++ b/service/cognitosync/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/cognitosync/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COGNITO_SYNC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cognito Sync", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/cognitosync/endpoints_config_test.go b/service/cognitosync/endpoints_config_test.go new file mode 100644 index 00000000000..cb7672595f5 --- /dev/null +++ b/service/cognitosync/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package cognitosync + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-sync.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-sync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + expectURL: aws.String("https://env-cognito-sync.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-sync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + expectURL: aws.String("http://config-cognito-sync.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cognito-sync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cognito-sync.dev", + clientEndpoint: aws.String("https://client-cognito-sync.dev"), + expectURL: aws.String("https://client-cognito-sync.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COGNITO_SYNC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/cognitosync/generated.json b/service/cognitosync/generated.json index 3c55375a191..3a1ac15cd2e 100644 --- a/service/cognitosync/generated.json +++ b/service/cognitosync/generated.json @@ -29,6 +29,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/cognitosync/go.mod b/service/cognitosync/go.mod index c43375a57f1..3e149776b16 100644 --- a/service/cognitosync/go.mod +++ b/service/cognitosync/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/cognitosync/go.sum b/service/cognitosync/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/cognitosync/go.sum +++ b/service/cognitosync/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/comprehend/api_client.go b/service/comprehend/api_client.go index 383ae5beaef..0082f77ac2b 100644 --- a/service/comprehend/api_client.go +++ b/service/comprehend/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/comprehend/endpoints.go b/service/comprehend/endpoints.go index 411a9ac79f8..dbb493ee9fd 100644 --- a/service/comprehend/endpoints.go +++ b/service/comprehend/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/comprehend/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COMPREHEND") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Comprehend", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/comprehend/endpoints_config_test.go b/service/comprehend/endpoints_config_test.go new file mode 100644 index 00000000000..658f30b6011 --- /dev/null +++ b/service/comprehend/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package comprehend + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehend.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + expectURL: aws.String("https://env-comprehend.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + expectURL: aws.String("http://config-comprehend.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehend.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehend.dev", + clientEndpoint: aws.String("https://client-comprehend.dev"), + expectURL: aws.String("https://client-comprehend.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COMPREHEND", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/comprehend/generated.json b/service/comprehend/generated.json index a588e1db53c..3cc3ceb09b7 100644 --- a/service/comprehend/generated.json +++ b/service/comprehend/generated.json @@ -96,6 +96,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/comprehend/go.mod b/service/comprehend/go.mod index f5cb1a8c479..e53b858b3e1 100644 --- a/service/comprehend/go.mod +++ b/service/comprehend/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/comprehend/go.sum b/service/comprehend/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/comprehend/go.sum +++ b/service/comprehend/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/comprehendmedical/api_client.go b/service/comprehendmedical/api_client.go index f8e3d848a1c..33045af94ca 100644 --- a/service/comprehendmedical/api_client.go +++ b/service/comprehendmedical/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/comprehendmedical/endpoints.go b/service/comprehendmedical/endpoints.go index 42d583d874c..c9ae32b111d 100644 --- a/service/comprehendmedical/endpoints.go +++ b/service/comprehendmedical/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/comprehendmedical/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COMPREHENDMEDICAL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ComprehendMedical", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/comprehendmedical/endpoints_config_test.go b/service/comprehendmedical/endpoints_config_test.go new file mode 100644 index 00000000000..a812e491c43 --- /dev/null +++ b/service/comprehendmedical/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package comprehendmedical + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehendmedical.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehendmedical.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + expectURL: aws.String("https://env-comprehendmedical.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehendmedical.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + expectURL: aws.String("http://config-comprehendmedical.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-comprehendmedical.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-comprehendmedical.dev", + clientEndpoint: aws.String("https://client-comprehendmedical.dev"), + expectURL: aws.String("https://client-comprehendmedical.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COMPREHENDMEDICAL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/comprehendmedical/generated.json b/service/comprehendmedical/generated.json index 637143c1203..fce2569195d 100644 --- a/service/comprehendmedical/generated.json +++ b/service/comprehendmedical/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/comprehendmedical/go.mod b/service/comprehendmedical/go.mod index 240eee46489..78ed6b269f7 100644 --- a/service/comprehendmedical/go.mod +++ b/service/comprehendmedical/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/comprehendmedical/go.sum b/service/comprehendmedical/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/comprehendmedical/go.sum +++ b/service/comprehendmedical/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/computeoptimizer/api_client.go b/service/computeoptimizer/api_client.go index 116e2df11f8..77aca739185 100644 --- a/service/computeoptimizer/api_client.go +++ b/service/computeoptimizer/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/computeoptimizer/endpoints.go b/service/computeoptimizer/endpoints.go index 4089f0d6967..ed4f2ea6e51 100644 --- a/service/computeoptimizer/endpoints.go +++ b/service/computeoptimizer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/computeoptimizer/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COMPUTE_OPTIMIZER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Compute Optimizer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/computeoptimizer/endpoints_config_test.go b/service/computeoptimizer/endpoints_config_test.go new file mode 100644 index 00000000000..478ddd45b9c --- /dev/null +++ b/service/computeoptimizer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package computeoptimizer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-compute-optimizer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-compute-optimizer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + expectURL: aws.String("https://env-compute-optimizer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-compute-optimizer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + expectURL: aws.String("http://config-compute-optimizer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-compute-optimizer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-compute-optimizer.dev", + clientEndpoint: aws.String("https://client-compute-optimizer.dev"), + expectURL: aws.String("https://client-compute-optimizer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COMPUTE_OPTIMIZER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/computeoptimizer/generated.json b/service/computeoptimizer/generated.json index d5d8bb639af..25327697baa 100644 --- a/service/computeoptimizer/generated.json +++ b/service/computeoptimizer/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/computeoptimizer/go.mod b/service/computeoptimizer/go.mod index 5d576075105..562b2aa0f0f 100644 --- a/service/computeoptimizer/go.mod +++ b/service/computeoptimizer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/computeoptimizer/go.sum b/service/computeoptimizer/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/computeoptimizer/go.sum +++ b/service/computeoptimizer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/configservice/api_client.go b/service/configservice/api_client.go index 8e2a5ccd066..17d10f61ba8 100644 --- a/service/configservice/api_client.go +++ b/service/configservice/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/configservice/endpoints.go b/service/configservice/endpoints.go index 1dbd637e15d..6ac019e9ea0 100644 --- a/service/configservice/endpoints.go +++ b/service/configservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/configservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONFIG_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Config Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/configservice/endpoints_config_test.go b/service/configservice/endpoints_config_test.go new file mode 100644 index 00000000000..952bb3a7658 --- /dev/null +++ b/service/configservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package configservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-config-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-config-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + expectURL: aws.String("https://env-config-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-config-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + expectURL: aws.String("http://config-config-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-config-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-config-service.dev", + clientEndpoint: aws.String("https://client-config-service.dev"), + expectURL: aws.String("https://client-config-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONFIG_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/configservice/generated.json b/service/configservice/generated.json index c5e34774016..e2ff556d615 100644 --- a/service/configservice/generated.json +++ b/service/configservice/generated.json @@ -104,6 +104,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/configservice/go.mod b/service/configservice/go.mod index 7b479c213d2..4c977c296f8 100644 --- a/service/configservice/go.mod +++ b/service/configservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/configservice/go.sum b/service/configservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/configservice/go.sum +++ b/service/configservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/connect/api_client.go b/service/connect/api_client.go index fbf1f7a3fad..56fc8f8ce72 100644 --- a/service/connect/api_client.go +++ b/service/connect/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/connect/endpoints.go b/service/connect/endpoints.go index 4a973104443..0e32fde8c2a 100644 --- a/service/connect/endpoints.go +++ b/service/connect/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/connect/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONNECT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Connect", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/connect/endpoints_config_test.go b/service/connect/endpoints_config_test.go new file mode 100644 index 00000000000..ddc4bd29178 --- /dev/null +++ b/service/connect/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package connect + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + expectURL: aws.String("https://env-connect.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + expectURL: aws.String("http://config-connect.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect.dev", + clientEndpoint: aws.String("https://client-connect.dev"), + expectURL: aws.String("https://client-connect.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONNECT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/connect/generated.json b/service/connect/generated.json index fa934398d27..f106cbefbf6 100644 --- a/service/connect/generated.json +++ b/service/connect/generated.json @@ -223,6 +223,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/connect/go.mod b/service/connect/go.mod index 94dddfe5d63..0d241b7a3f5 100644 --- a/service/connect/go.mod +++ b/service/connect/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/connect/go.sum b/service/connect/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/connect/go.sum +++ b/service/connect/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/connectcampaigns/api_client.go b/service/connectcampaigns/api_client.go index c1b14400239..e2122aac256 100644 --- a/service/connectcampaigns/api_client.go +++ b/service/connectcampaigns/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/connectcampaigns/endpoints.go b/service/connectcampaigns/endpoints.go index 9ba3fa53472..6b50e55399b 100644 --- a/service/connectcampaigns/endpoints.go +++ b/service/connectcampaigns/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/connectcampaigns/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONNECTCAMPAIGNS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ConnectCampaigns", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/connectcampaigns/endpoints_config_test.go b/service/connectcampaigns/endpoints_config_test.go new file mode 100644 index 00000000000..b9b3d5560da --- /dev/null +++ b/service/connectcampaigns/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package connectcampaigns + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcampaigns.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcampaigns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + expectURL: aws.String("https://env-connectcampaigns.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcampaigns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + expectURL: aws.String("http://config-connectcampaigns.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcampaigns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcampaigns.dev", + clientEndpoint: aws.String("https://client-connectcampaigns.dev"), + expectURL: aws.String("https://client-connectcampaigns.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONNECTCAMPAIGNS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/connectcampaigns/generated.json b/service/connectcampaigns/generated.json index b0d50020847..e7af6b35437 100644 --- a/service/connectcampaigns/generated.json +++ b/service/connectcampaigns/generated.json @@ -34,6 +34,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/connectcampaigns/go.mod b/service/connectcampaigns/go.mod index f77aebfe417..1d4fea9651b 100644 --- a/service/connectcampaigns/go.mod +++ b/service/connectcampaigns/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/connectcampaigns/go.sum b/service/connectcampaigns/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/connectcampaigns/go.sum +++ b/service/connectcampaigns/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/connectcases/api_client.go b/service/connectcases/api_client.go index 8cbb09eb598..1ea7aecb478 100644 --- a/service/connectcases/api_client.go +++ b/service/connectcases/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/connectcases/endpoints.go b/service/connectcases/endpoints.go index 5fe911f05da..70bd7854477 100644 --- a/service/connectcases/endpoints.go +++ b/service/connectcases/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/connectcases/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONNECTCASES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ConnectCases", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/connectcases/endpoints_config_test.go b/service/connectcases/endpoints_config_test.go new file mode 100644 index 00000000000..88186bb6286 --- /dev/null +++ b/service/connectcases/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package connectcases + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcases.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcases.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + expectURL: aws.String("https://env-connectcases.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcases.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + expectURL: aws.String("http://config-connectcases.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectcases.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectcases.dev", + clientEndpoint: aws.String("https://client-connectcases.dev"), + expectURL: aws.String("https://client-connectcases.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONNECTCASES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/connectcases/generated.json b/service/connectcases/generated.json index 006d845badc..aa8931b44bd 100644 --- a/service/connectcases/generated.json +++ b/service/connectcases/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/connectcases/go.mod b/service/connectcases/go.mod index ff8b8c790bb..a9806bf1c74 100644 --- a/service/connectcases/go.mod +++ b/service/connectcases/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/connectcases/go.sum b/service/connectcases/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/connectcases/go.sum +++ b/service/connectcases/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/connectcontactlens/api_client.go b/service/connectcontactlens/api_client.go index 50e5f2d7d6c..46357990dd3 100644 --- a/service/connectcontactlens/api_client.go +++ b/service/connectcontactlens/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/connectcontactlens/endpoints.go b/service/connectcontactlens/endpoints.go index f7a4f7d8353..90c8a86d47d 100644 --- a/service/connectcontactlens/endpoints.go +++ b/service/connectcontactlens/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/connectcontactlens/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONNECT_CONTACT_LENS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Connect Contact Lens", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/connectcontactlens/endpoints_config_test.go b/service/connectcontactlens/endpoints_config_test.go new file mode 100644 index 00000000000..f55a64de266 --- /dev/null +++ b/service/connectcontactlens/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package connectcontactlens + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect-contact-lens.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect-contact-lens.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + expectURL: aws.String("https://env-connect-contact-lens.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect-contact-lens.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + expectURL: aws.String("http://config-connect-contact-lens.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-connect-contact-lens.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connect-contact-lens.dev", + clientEndpoint: aws.String("https://client-connect-contact-lens.dev"), + expectURL: aws.String("https://client-connect-contact-lens.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONNECT_CONTACT_LENS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/connectcontactlens/generated.json b/service/connectcontactlens/generated.json index 08c7621fd10..1d3d7e47a38 100644 --- a/service/connectcontactlens/generated.json +++ b/service/connectcontactlens/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/connectcontactlens/go.mod b/service/connectcontactlens/go.mod index c3b77b2410e..d4d7b9c763e 100644 --- a/service/connectcontactlens/go.mod +++ b/service/connectcontactlens/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/connectcontactlens/go.sum b/service/connectcontactlens/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/connectcontactlens/go.sum +++ b/service/connectcontactlens/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/connectparticipant/api_client.go b/service/connectparticipant/api_client.go index 312808e4c00..bad43d699dc 100644 --- a/service/connectparticipant/api_client.go +++ b/service/connectparticipant/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/connectparticipant/endpoints.go b/service/connectparticipant/endpoints.go index cc79c492b58..345d66a2810 100644 --- a/service/connectparticipant/endpoints.go +++ b/service/connectparticipant/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/connectparticipant/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONNECTPARTICIPANT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ConnectParticipant", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/connectparticipant/endpoints_config_test.go b/service/connectparticipant/endpoints_config_test.go new file mode 100644 index 00000000000..76730fb1441 --- /dev/null +++ b/service/connectparticipant/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package connectparticipant + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectparticipant.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectparticipant.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + expectURL: aws.String("https://env-connectparticipant.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectparticipant.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + expectURL: aws.String("http://config-connectparticipant.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-connectparticipant.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-connectparticipant.dev", + clientEndpoint: aws.String("https://client-connectparticipant.dev"), + expectURL: aws.String("https://client-connectparticipant.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONNECTPARTICIPANT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/connectparticipant/generated.json b/service/connectparticipant/generated.json index 6bbb17b19ca..03893404975 100644 --- a/service/connectparticipant/generated.json +++ b/service/connectparticipant/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/connectparticipant/go.mod b/service/connectparticipant/go.mod index 35453b14beb..a4616790faa 100644 --- a/service/connectparticipant/go.mod +++ b/service/connectparticipant/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/connectparticipant/go.sum b/service/connectparticipant/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/connectparticipant/go.sum +++ b/service/connectparticipant/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/controltower/api_client.go b/service/controltower/api_client.go index 510dc0bfbae..25e9d992867 100644 --- a/service/controltower/api_client.go +++ b/service/controltower/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/controltower/endpoints.go b/service/controltower/endpoints.go index f6a1858a58f..31d42a85fe0 100644 --- a/service/controltower/endpoints.go +++ b/service/controltower/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/controltower/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CONTROLTOWER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ControlTower", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/controltower/endpoints_config_test.go b/service/controltower/endpoints_config_test.go new file mode 100644 index 00000000000..80f9b12473a --- /dev/null +++ b/service/controltower/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package controltower + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-controltower.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-controltower.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + expectURL: aws.String("https://env-controltower.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-controltower.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + expectURL: aws.String("http://config-controltower.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-controltower.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-controltower.dev", + clientEndpoint: aws.String("https://client-controltower.dev"), + expectURL: aws.String("https://client-controltower.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CONTROLTOWER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/controltower/generated.json b/service/controltower/generated.json index 08405c0865d..2843d77fccb 100644 --- a/service/controltower/generated.json +++ b/service/controltower/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/controltower/go.mod b/service/controltower/go.mod index 0a61d1c9349..9b8b34a36e3 100644 --- a/service/controltower/go.mod +++ b/service/controltower/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/controltower/go.sum b/service/controltower/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/controltower/go.sum +++ b/service/controltower/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/costandusagereportservice/api_client.go b/service/costandusagereportservice/api_client.go index 4f560457487..c3b37b0bc24 100644 --- a/service/costandusagereportservice/api_client.go +++ b/service/costandusagereportservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/costandusagereportservice/endpoints.go b/service/costandusagereportservice/endpoints.go index 1c673b64896..13c8afb47a9 100644 --- a/service/costandusagereportservice/endpoints.go +++ b/service/costandusagereportservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/costandusagereportservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COST_AND_USAGE_REPORT_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cost and Usage Report Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/costandusagereportservice/endpoints_config_test.go b/service/costandusagereportservice/endpoints_config_test.go new file mode 100644 index 00000000000..543140e8784 --- /dev/null +++ b/service/costandusagereportservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package costandusagereportservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-and-usage-report-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-and-usage-report-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + expectURL: aws.String("https://env-cost-and-usage-report-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-and-usage-report-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + expectURL: aws.String("http://config-cost-and-usage-report-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-and-usage-report-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-and-usage-report-service.dev", + clientEndpoint: aws.String("https://client-cost-and-usage-report-service.dev"), + expectURL: aws.String("https://client-cost-and-usage-report-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COST_AND_USAGE_REPORT_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/costandusagereportservice/generated.json b/service/costandusagereportservice/generated.json index e2ac832f231..d8a9fc0a5a4 100644 --- a/service/costandusagereportservice/generated.json +++ b/service/costandusagereportservice/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/costandusagereportservice/go.mod b/service/costandusagereportservice/go.mod index c0eff5dcdbc..cd794383b0c 100644 --- a/service/costandusagereportservice/go.mod +++ b/service/costandusagereportservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/costandusagereportservice/go.sum b/service/costandusagereportservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/costandusagereportservice/go.sum +++ b/service/costandusagereportservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/costexplorer/api_client.go b/service/costexplorer/api_client.go index ad6a754defc..efd139478a1 100644 --- a/service/costexplorer/api_client.go +++ b/service/costexplorer/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/costexplorer/endpoints.go b/service/costexplorer/endpoints.go index 8cafd6d7c04..436db563b5d 100644 --- a/service/costexplorer/endpoints.go +++ b/service/costexplorer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/costexplorer/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_COST_EXPLORER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Cost Explorer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/costexplorer/endpoints_config_test.go b/service/costexplorer/endpoints_config_test.go new file mode 100644 index 00000000000..68ec1247526 --- /dev/null +++ b/service/costexplorer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package costexplorer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-explorer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-explorer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + expectURL: aws.String("https://env-cost-explorer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-explorer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + expectURL: aws.String("http://config-cost-explorer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-cost-explorer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-cost-explorer.dev", + clientEndpoint: aws.String("https://client-cost-explorer.dev"), + expectURL: aws.String("https://client-cost-explorer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_COST_EXPLORER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/costexplorer/generated.json b/service/costexplorer/generated.json index 544708fd607..540fe4aff15 100644 --- a/service/costexplorer/generated.json +++ b/service/costexplorer/generated.json @@ -50,6 +50,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/costexplorer/go.mod b/service/costexplorer/go.mod index 8dbe9a2855a..ae02ae8fde5 100644 --- a/service/costexplorer/go.mod +++ b/service/costexplorer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/costexplorer/go.sum b/service/costexplorer/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/costexplorer/go.sum +++ b/service/costexplorer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/customerprofiles/api_client.go b/service/customerprofiles/api_client.go index eab6dd68416..29de518294f 100644 --- a/service/customerprofiles/api_client.go +++ b/service/customerprofiles/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/customerprofiles/endpoints.go b/service/customerprofiles/endpoints.go index 944bc400afa..9fe06322440 100644 --- a/service/customerprofiles/endpoints.go +++ b/service/customerprofiles/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/customerprofiles/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_CUSTOMER_PROFILES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Customer Profiles", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/customerprofiles/endpoints_config_test.go b/service/customerprofiles/endpoints_config_test.go new file mode 100644 index 00000000000..4d727911353 --- /dev/null +++ b/service/customerprofiles/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package customerprofiles + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-customer-profiles.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-customer-profiles.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + expectURL: aws.String("https://env-customer-profiles.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-customer-profiles.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + expectURL: aws.String("http://config-customer-profiles.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-customer-profiles.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-customer-profiles.dev", + clientEndpoint: aws.String("https://client-customer-profiles.dev"), + expectURL: aws.String("https://client-customer-profiles.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_CUSTOMER_PROFILES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/customerprofiles/generated.json b/service/customerprofiles/generated.json index 11501c1050c..e9ff592a83b 100644 --- a/service/customerprofiles/generated.json +++ b/service/customerprofiles/generated.json @@ -63,6 +63,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/customerprofiles/go.mod b/service/customerprofiles/go.mod index 7a6cff98c92..b92ae374f25 100644 --- a/service/customerprofiles/go.mod +++ b/service/customerprofiles/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/customerprofiles/go.sum b/service/customerprofiles/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/customerprofiles/go.sum +++ b/service/customerprofiles/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/databasemigrationservice/api_client.go b/service/databasemigrationservice/api_client.go index 50bea254811..2ab8ee6c551 100644 --- a/service/databasemigrationservice/api_client.go +++ b/service/databasemigrationservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/databasemigrationservice/endpoints.go b/service/databasemigrationservice/endpoints.go index a025f011251..de5de4d21fa 100644 --- a/service/databasemigrationservice/endpoints.go +++ b/service/databasemigrationservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATABASE_MIGRATION_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Database Migration Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/databasemigrationservice/endpoints_config_test.go b/service/databasemigrationservice/endpoints_config_test.go new file mode 100644 index 00000000000..995d2592401 --- /dev/null +++ b/service/databasemigrationservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package databasemigrationservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-database-migration-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-database-migration-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + expectURL: aws.String("https://env-database-migration-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-database-migration-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + expectURL: aws.String("http://config-database-migration-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-database-migration-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-database-migration-service.dev", + clientEndpoint: aws.String("https://client-database-migration-service.dev"), + expectURL: aws.String("https://client-database-migration-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATABASE_MIGRATION_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/databasemigrationservice/generated.json b/service/databasemigrationservice/generated.json index 47385066f93..7094d19553f 100644 --- a/service/databasemigrationservice/generated.json +++ b/service/databasemigrationservice/generated.json @@ -119,6 +119,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/databasemigrationservice/go.mod b/service/databasemigrationservice/go.mod index 08b87824eab..048027eda03 100644 --- a/service/databasemigrationservice/go.mod +++ b/service/databasemigrationservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/databasemigrationservice/go.sum b/service/databasemigrationservice/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/databasemigrationservice/go.sum +++ b/service/databasemigrationservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/databrew/api_client.go b/service/databrew/api_client.go index b6b078dd527..9b38c800386 100644 --- a/service/databrew/api_client.go +++ b/service/databrew/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/databrew/endpoints.go b/service/databrew/endpoints.go index 9eb71863c2e..3bd2d43ded4 100644 --- a/service/databrew/endpoints.go +++ b/service/databrew/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/databrew/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATABREW") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DataBrew", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/databrew/endpoints_config_test.go b/service/databrew/endpoints_config_test.go new file mode 100644 index 00000000000..fe03d17338e --- /dev/null +++ b/service/databrew/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package databrew + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-databrew.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-databrew.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + expectURL: aws.String("https://env-databrew.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-databrew.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + expectURL: aws.String("http://config-databrew.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-databrew.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-databrew.dev", + clientEndpoint: aws.String("https://client-databrew.dev"), + expectURL: aws.String("https://client-databrew.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATABREW", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/databrew/generated.json b/service/databrew/generated.json index a58c05a865d..c0d2b7bab37 100644 --- a/service/databrew/generated.json +++ b/service/databrew/generated.json @@ -56,6 +56,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/databrew/go.mod b/service/databrew/go.mod index ef349acfec1..f4273049bfb 100644 --- a/service/databrew/go.mod +++ b/service/databrew/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/databrew/go.sum b/service/databrew/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/databrew/go.sum +++ b/service/databrew/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/dataexchange/api_client.go b/service/dataexchange/api_client.go index 14856e032b0..274da59e3fb 100644 --- a/service/dataexchange/api_client.go +++ b/service/dataexchange/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/dataexchange/endpoints.go b/service/dataexchange/endpoints.go index 06e732cc59e..919dcc2fbb0 100644 --- a/service/dataexchange/endpoints.go +++ b/service/dataexchange/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/dataexchange/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATAEXCHANGE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DataExchange", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/dataexchange/endpoints_config_test.go b/service/dataexchange/endpoints_config_test.go new file mode 100644 index 00000000000..3dd09671e43 --- /dev/null +++ b/service/dataexchange/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package dataexchange + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dataexchange.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-dataexchange.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + expectURL: aws.String("https://env-dataexchange.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dataexchange.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + expectURL: aws.String("http://config-dataexchange.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-dataexchange.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dataexchange.dev", + clientEndpoint: aws.String("https://client-dataexchange.dev"), + expectURL: aws.String("https://client-dataexchange.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATAEXCHANGE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/dataexchange/generated.json b/service/dataexchange/generated.json index 71acb5d5a54..762c24ce870 100644 --- a/service/dataexchange/generated.json +++ b/service/dataexchange/generated.json @@ -41,6 +41,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/dataexchange/go.mod b/service/dataexchange/go.mod index ee371d43868..a5dbf74db29 100644 --- a/service/dataexchange/go.mod +++ b/service/dataexchange/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/dataexchange/go.sum b/service/dataexchange/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/dataexchange/go.sum +++ b/service/dataexchange/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/datapipeline/api_client.go b/service/datapipeline/api_client.go index 8dc453fc3d1..b9bf06bf046 100644 --- a/service/datapipeline/api_client.go +++ b/service/datapipeline/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/datapipeline/endpoints.go b/service/datapipeline/endpoints.go index 904b8565869..63c8c3feca8 100644 --- a/service/datapipeline/endpoints.go +++ b/service/datapipeline/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/datapipeline/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATA_PIPELINE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Data Pipeline", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/datapipeline/endpoints_config_test.go b/service/datapipeline/endpoints_config_test.go new file mode 100644 index 00000000000..e55f59d5931 --- /dev/null +++ b/service/datapipeline/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package datapipeline + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-data-pipeline.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-data-pipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + expectURL: aws.String("https://env-data-pipeline.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-data-pipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + expectURL: aws.String("http://config-data-pipeline.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-data-pipeline.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-data-pipeline.dev", + clientEndpoint: aws.String("https://client-data-pipeline.dev"), + expectURL: aws.String("https://client-data-pipeline.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATA_PIPELINE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/datapipeline/generated.json b/service/datapipeline/generated.json index ce4e9b926b6..4679aedb253 100644 --- a/service/datapipeline/generated.json +++ b/service/datapipeline/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/datapipeline/go.mod b/service/datapipeline/go.mod index bf82d945eac..e568dfacd92 100644 --- a/service/datapipeline/go.mod +++ b/service/datapipeline/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/datapipeline/go.sum b/service/datapipeline/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/datapipeline/go.sum +++ b/service/datapipeline/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/datasync/api_client.go b/service/datasync/api_client.go index 1a2d150b0b1..c2ecb65141d 100644 --- a/service/datasync/api_client.go +++ b/service/datasync/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/datasync/endpoints.go b/service/datasync/endpoints.go index 4543c772517..8b9bd403262 100644 --- a/service/datasync/endpoints.go +++ b/service/datasync/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/datasync/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATASYNC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DataSync", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/datasync/endpoints_config_test.go b/service/datasync/endpoints_config_test.go new file mode 100644 index 00000000000..fd5df4207ee --- /dev/null +++ b/service/datasync/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package datasync + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-datasync.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-datasync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + expectURL: aws.String("https://env-datasync.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-datasync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + expectURL: aws.String("http://config-datasync.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-datasync.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datasync.dev", + clientEndpoint: aws.String("https://client-datasync.dev"), + expectURL: aws.String("https://client-datasync.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATASYNC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/datasync/generated.json b/service/datasync/generated.json index fc13e6cb6f3..a29deeb24d6 100644 --- a/service/datasync/generated.json +++ b/service/datasync/generated.json @@ -72,6 +72,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/datasync/go.mod b/service/datasync/go.mod index f36ee576f82..bb38f764e71 100644 --- a/service/datasync/go.mod +++ b/service/datasync/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/datasync/go.sum b/service/datasync/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/datasync/go.sum +++ b/service/datasync/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/datazone/api_client.go b/service/datazone/api_client.go index a8029b6af29..9a4138032b6 100644 --- a/service/datazone/api_client.go +++ b/service/datazone/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/datazone/endpoints.go b/service/datazone/endpoints.go index 6c75bf5da50..c5876729ecf 100644 --- a/service/datazone/endpoints.go +++ b/service/datazone/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/datazone/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DATAZONE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DataZone", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/datazone/endpoints_config_test.go b/service/datazone/endpoints_config_test.go new file mode 100644 index 00000000000..8ddd4eade6d --- /dev/null +++ b/service/datazone/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package datazone + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-datazone.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-datazone.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + expectURL: aws.String("https://env-datazone.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-datazone.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + expectURL: aws.String("http://config-datazone.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-datazone.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-datazone.dev", + clientEndpoint: aws.String("https://client-datazone.dev"), + expectURL: aws.String("https://client-datazone.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DATAZONE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/datazone/generated.json b/service/datazone/generated.json index a7d0ae4e5f4..27e96362ce5 100644 --- a/service/datazone/generated.json +++ b/service/datazone/generated.json @@ -111,6 +111,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/datazone/go.mod b/service/datazone/go.mod index 258921baf23..8607c7bb80b 100644 --- a/service/datazone/go.mod +++ b/service/datazone/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/datazone/go.sum b/service/datazone/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/datazone/go.sum +++ b/service/datazone/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/dax/api_client.go b/service/dax/api_client.go index fb338bcae85..e529f0741c1 100644 --- a/service/dax/api_client.go +++ b/service/dax/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/dax/endpoints.go b/service/dax/endpoints.go index 211d1cd029e..5ce455c87eb 100644 --- a/service/dax/endpoints.go +++ b/service/dax/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/dax/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DAX") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DAX", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/dax/endpoints_config_test.go b/service/dax/endpoints_config_test.go new file mode 100644 index 00000000000..f67ee5b2953 --- /dev/null +++ b/service/dax/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package dax + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dax.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-dax.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + expectURL: aws.String("https://env-dax.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dax.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + expectURL: aws.String("http://config-dax.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-dax.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dax.dev", + clientEndpoint: aws.String("https://client-dax.dev"), + expectURL: aws.String("https://client-dax.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DAX", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/dax/generated.json b/service/dax/generated.json index 8ced0de0a0b..47f589bd88d 100644 --- a/service/dax/generated.json +++ b/service/dax/generated.json @@ -33,6 +33,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/dax/go.mod b/service/dax/go.mod index 2a079459ce1..434e03b5458 100644 --- a/service/dax/go.mod +++ b/service/dax/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/dax/go.sum b/service/dax/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/dax/go.sum +++ b/service/dax/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/detective/api_client.go b/service/detective/api_client.go index ab067e06676..ee64b8e07e6 100644 --- a/service/detective/api_client.go +++ b/service/detective/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/detective/endpoints.go b/service/detective/endpoints.go index c8fbad0fffb..f0dbf61fc7f 100644 --- a/service/detective/endpoints.go +++ b/service/detective/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/detective/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DETECTIVE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Detective", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/detective/endpoints_config_test.go b/service/detective/endpoints_config_test.go new file mode 100644 index 00000000000..ce2bd3fb217 --- /dev/null +++ b/service/detective/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package detective + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-detective.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-detective.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + expectURL: aws.String("https://env-detective.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-detective.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + expectURL: aws.String("http://config-detective.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-detective.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-detective.dev", + clientEndpoint: aws.String("https://client-detective.dev"), + expectURL: aws.String("https://client-detective.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DETECTIVE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/detective/generated.json b/service/detective/generated.json index 59c162374d0..e267c389b43 100644 --- a/service/detective/generated.json +++ b/service/detective/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/detective/go.mod b/service/detective/go.mod index fcc546e500d..1189b15af8b 100644 --- a/service/detective/go.mod +++ b/service/detective/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/detective/go.sum b/service/detective/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/detective/go.sum +++ b/service/detective/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/devicefarm/api_client.go b/service/devicefarm/api_client.go index 6a58e413200..8ba5cf99e00 100644 --- a/service/devicefarm/api_client.go +++ b/service/devicefarm/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/devicefarm/endpoints.go b/service/devicefarm/endpoints.go index 2abb2a7917a..c09c8d7f00b 100644 --- a/service/devicefarm/endpoints.go +++ b/service/devicefarm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/devicefarm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DEVICE_FARM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Device Farm", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/devicefarm/endpoints_config_test.go b/service/devicefarm/endpoints_config_test.go new file mode 100644 index 00000000000..5de3cbeb18f --- /dev/null +++ b/service/devicefarm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package devicefarm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-device-farm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-device-farm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + expectURL: aws.String("https://env-device-farm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-device-farm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + expectURL: aws.String("http://config-device-farm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-device-farm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-device-farm.dev", + clientEndpoint: aws.String("https://client-device-farm.dev"), + expectURL: aws.String("https://client-device-farm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DEVICE_FARM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/devicefarm/generated.json b/service/devicefarm/generated.json index 6da9dbdd385..2e143d0b23a 100644 --- a/service/devicefarm/generated.json +++ b/service/devicefarm/generated.json @@ -89,6 +89,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/devicefarm/go.mod b/service/devicefarm/go.mod index 12c0b607c57..1dedb6495de 100644 --- a/service/devicefarm/go.mod +++ b/service/devicefarm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/devicefarm/go.sum b/service/devicefarm/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/devicefarm/go.sum +++ b/service/devicefarm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/devopsguru/api_client.go b/service/devopsguru/api_client.go index cc557bfd6f4..91b9f5393ba 100644 --- a/service/devopsguru/api_client.go +++ b/service/devopsguru/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/devopsguru/endpoints.go b/service/devopsguru/endpoints.go index abfb474bc02..f17ab8f3091 100644 --- a/service/devopsguru/endpoints.go +++ b/service/devopsguru/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/devopsguru/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DEVOPS_GURU") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DevOps Guru", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/devopsguru/endpoints_config_test.go b/service/devopsguru/endpoints_config_test.go new file mode 100644 index 00000000000..37238af57df --- /dev/null +++ b/service/devopsguru/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package devopsguru + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-devops-guru.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-devops-guru.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + expectURL: aws.String("https://env-devops-guru.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-devops-guru.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + expectURL: aws.String("http://config-devops-guru.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-devops-guru.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-devops-guru.dev", + clientEndpoint: aws.String("https://client-devops-guru.dev"), + expectURL: aws.String("https://client-devops-guru.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DEVOPS_GURU", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/devopsguru/generated.json b/service/devopsguru/generated.json index fdc0728fe50..0548b91d198 100644 --- a/service/devopsguru/generated.json +++ b/service/devopsguru/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/devopsguru/go.mod b/service/devopsguru/go.mod index 8311ecdf864..29bf0f42d09 100644 --- a/service/devopsguru/go.mod +++ b/service/devopsguru/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/devopsguru/go.sum b/service/devopsguru/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/devopsguru/go.sum +++ b/service/devopsguru/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/directconnect/api_client.go b/service/directconnect/api_client.go index f261619f211..64350d37c1e 100644 --- a/service/directconnect/api_client.go +++ b/service/directconnect/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/directconnect/endpoints.go b/service/directconnect/endpoints.go index fd779828c0d..5d8feb1f050 100644 --- a/service/directconnect/endpoints.go +++ b/service/directconnect/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/directconnect/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DIRECT_CONNECT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Direct Connect", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/directconnect/endpoints_config_test.go b/service/directconnect/endpoints_config_test.go new file mode 100644 index 00000000000..52db5a91d38 --- /dev/null +++ b/service/directconnect/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package directconnect + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-direct-connect.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-direct-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + expectURL: aws.String("https://env-direct-connect.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-direct-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + expectURL: aws.String("http://config-direct-connect.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-direct-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-direct-connect.dev", + clientEndpoint: aws.String("https://client-direct-connect.dev"), + expectURL: aws.String("https://client-direct-connect.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DIRECT_CONNECT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/directconnect/generated.json b/service/directconnect/generated.json index 9a928203911..9a1a4e1eae9 100644 --- a/service/directconnect/generated.json +++ b/service/directconnect/generated.json @@ -75,6 +75,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/directconnect/go.mod b/service/directconnect/go.mod index 82ab887f50e..213c4921107 100644 --- a/service/directconnect/go.mod +++ b/service/directconnect/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/directconnect/go.sum b/service/directconnect/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/directconnect/go.sum +++ b/service/directconnect/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/directoryservice/api_client.go b/service/directoryservice/api_client.go index 19c28d5674b..de719e64ffb 100644 --- a/service/directoryservice/api_client.go +++ b/service/directoryservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/directoryservice/endpoints.go b/service/directoryservice/endpoints.go index 0565dbe41a8..8148cff88f6 100644 --- a/service/directoryservice/endpoints.go +++ b/service/directoryservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/directoryservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DIRECTORY_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Directory Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/directoryservice/endpoints_config_test.go b/service/directoryservice/endpoints_config_test.go new file mode 100644 index 00000000000..c6740e1a243 --- /dev/null +++ b/service/directoryservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package directoryservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-directory-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-directory-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + expectURL: aws.String("https://env-directory-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-directory-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + expectURL: aws.String("http://config-directory-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-directory-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-directory-service.dev", + clientEndpoint: aws.String("https://client-directory-service.dev"), + expectURL: aws.String("https://client-directory-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DIRECTORY_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/directoryservice/generated.json b/service/directoryservice/generated.json index 03492a2afe1..60e7508afb7 100644 --- a/service/directoryservice/generated.json +++ b/service/directoryservice/generated.json @@ -79,6 +79,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/directoryservice/go.mod b/service/directoryservice/go.mod index a4985fa07d7..60282e174a9 100644 --- a/service/directoryservice/go.mod +++ b/service/directoryservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/directoryservice/go.sum b/service/directoryservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/directoryservice/go.sum +++ b/service/directoryservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/dlm/api_client.go b/service/dlm/api_client.go index c5042770d79..dcd4b36c046 100644 --- a/service/dlm/api_client.go +++ b/service/dlm/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/dlm/endpoints.go b/service/dlm/endpoints.go index c2f073fff57..f5a06c30a7c 100644 --- a/service/dlm/endpoints.go +++ b/service/dlm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/dlm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DLM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DLM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/dlm/endpoints_config_test.go b/service/dlm/endpoints_config_test.go new file mode 100644 index 00000000000..591fa125996 --- /dev/null +++ b/service/dlm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package dlm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dlm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-dlm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + expectURL: aws.String("https://env-dlm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dlm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + expectURL: aws.String("http://config-dlm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-dlm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dlm.dev", + clientEndpoint: aws.String("https://client-dlm.dev"), + expectURL: aws.String("https://client-dlm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DLM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/dlm/generated.json b/service/dlm/generated.json index 7eac7812756..78b4110392b 100644 --- a/service/dlm/generated.json +++ b/service/dlm/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/dlm/go.mod b/service/dlm/go.mod index a63642d057c..d1106bb6d73 100644 --- a/service/dlm/go.mod +++ b/service/dlm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/dlm/go.sum b/service/dlm/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/dlm/go.sum +++ b/service/dlm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/docdb/api_client.go b/service/docdb/api_client.go index 1ca0385ad97..860a3a7c084 100644 --- a/service/docdb/api_client.go +++ b/service/docdb/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/docdb/endpoints.go b/service/docdb/endpoints.go index e8636375cdf..f1af3499b09 100644 --- a/service/docdb/endpoints.go +++ b/service/docdb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/docdb/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DOCDB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DocDB", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/docdb/endpoints_config_test.go b/service/docdb/endpoints_config_test.go new file mode 100644 index 00000000000..b4785c531b4 --- /dev/null +++ b/service/docdb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package docdb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + expectURL: aws.String("https://env-docdb.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + expectURL: aws.String("http://config-docdb.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb.dev", + clientEndpoint: aws.String("https://client-docdb.dev"), + expectURL: aws.String("https://client-docdb.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DOCDB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/docdb/generated.json b/service/docdb/generated.json index 64c394b91cc..65c4e750916 100644 --- a/service/docdb/generated.json +++ b/service/docdb/generated.json @@ -69,6 +69,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/docdb/go.mod b/service/docdb/go.mod index b609eafe437..6b5c68934ba 100644 --- a/service/docdb/go.mod +++ b/service/docdb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -14,8 +15,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/docdb/go.sum b/service/docdb/go.sum index ef5982af332..c64803e87e7 100644 --- a/service/docdb/go.sum +++ b/service/docdb/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/docdbelastic/api_client.go b/service/docdbelastic/api_client.go index fb4990c1120..76323b65f29 100644 --- a/service/docdbelastic/api_client.go +++ b/service/docdbelastic/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/docdbelastic/endpoints.go b/service/docdbelastic/endpoints.go index ccba0bba7e1..c7159d3cbc1 100644 --- a/service/docdbelastic/endpoints.go +++ b/service/docdbelastic/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/docdbelastic/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DOCDB_ELASTIC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DocDB Elastic", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/docdbelastic/endpoints_config_test.go b/service/docdbelastic/endpoints_config_test.go new file mode 100644 index 00000000000..12cbbf3fcfe --- /dev/null +++ b/service/docdbelastic/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package docdbelastic + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb-elastic.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb-elastic.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + expectURL: aws.String("https://env-docdb-elastic.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb-elastic.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + expectURL: aws.String("http://config-docdb-elastic.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-docdb-elastic.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-docdb-elastic.dev", + clientEndpoint: aws.String("https://client-docdb-elastic.dev"), + expectURL: aws.String("https://client-docdb-elastic.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DOCDB_ELASTIC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/docdbelastic/generated.json b/service/docdbelastic/generated.json index a9ad2ff9328..ea65e2f2395 100644 --- a/service/docdbelastic/generated.json +++ b/service/docdbelastic/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/docdbelastic/go.mod b/service/docdbelastic/go.mod index a664995b886..99a96be7e97 100644 --- a/service/docdbelastic/go.mod +++ b/service/docdbelastic/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/docdbelastic/go.sum b/service/docdbelastic/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/docdbelastic/go.sum +++ b/service/docdbelastic/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/drs/api_client.go b/service/drs/api_client.go index d1ffffdee7e..d838b653908 100644 --- a/service/drs/api_client.go +++ b/service/drs/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/drs/endpoints.go b/service/drs/endpoints.go index ffcf2bf0c70..b600ad65bbb 100644 --- a/service/drs/endpoints.go +++ b/service/drs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/drs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DRS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "drs", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/drs/endpoints_config_test.go b/service/drs/endpoints_config_test.go new file mode 100644 index 00000000000..232932eef4a --- /dev/null +++ b/service/drs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package drs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-drs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-drs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + expectURL: aws.String("https://env-drs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-drs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + expectURL: aws.String("http://config-drs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-drs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-drs.dev", + clientEndpoint: aws.String("https://client-drs.dev"), + expectURL: aws.String("https://client-drs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DRS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/drs/generated.json b/service/drs/generated.json index 53f1cf19a19..831a9cd221b 100644 --- a/service/drs/generated.json +++ b/service/drs/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/drs/go.mod b/service/drs/go.mod index bb18ab89adf..13e4d9142aa 100644 --- a/service/drs/go.mod +++ b/service/drs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/drs/go.sum b/service/drs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/drs/go.sum +++ b/service/drs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/dynamodb/api_client.go b/service/dynamodb/api_client.go index 3cdb24e1ebe..a8888e91329 100644 --- a/service/dynamodb/api_client.go +++ b/service/dynamodb/api_client.go @@ -327,6 +327,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/dynamodb/endpoints.go b/service/dynamodb/endpoints.go index 710499223b5..efee4e11022 100644 --- a/service/dynamodb/endpoints.go +++ b/service/dynamodb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/dynamodb/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DYNAMODB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DynamoDB", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/dynamodb/endpoints_config_test.go b/service/dynamodb/endpoints_config_test.go new file mode 100644 index 00000000000..7bdf2ae6f67 --- /dev/null +++ b/service/dynamodb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package dynamodb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + expectURL: aws.String("https://env-dynamodb.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + expectURL: aws.String("http://config-dynamodb.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb.dev", + clientEndpoint: aws.String("https://client-dynamodb.dev"), + expectURL: aws.String("https://client-dynamodb.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DYNAMODB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/dynamodb/generated.json b/service/dynamodb/generated.json index 633c9fae992..20bff55d3ff 100644 --- a/service/dynamodb/generated.json +++ b/service/dynamodb/generated.json @@ -68,6 +68,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/dynamodb/go.mod b/service/dynamodb/go.mod index a9420105fb1..98e75247b24 100644 --- a/service/dynamodb/go.mod +++ b/service/dynamodb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 @@ -15,10 +16,28 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/dynamodb/go.sum b/service/dynamodb/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/dynamodb/go.sum +++ b/service/dynamodb/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/dynamodbstreams/api_client.go b/service/dynamodbstreams/api_client.go index a406647d16e..40029083ad8 100644 --- a/service/dynamodbstreams/api_client.go +++ b/service/dynamodbstreams/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/dynamodbstreams/endpoints.go b/service/dynamodbstreams/endpoints.go index 943063b7b35..19d1fd3e070 100644 --- a/service/dynamodbstreams/endpoints.go +++ b/service/dynamodbstreams/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/dynamodbstreams/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_DYNAMODB_STREAMS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "DynamoDB Streams", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/dynamodbstreams/endpoints_config_test.go b/service/dynamodbstreams/endpoints_config_test.go new file mode 100644 index 00000000000..a9d41bdf2a2 --- /dev/null +++ b/service/dynamodbstreams/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package dynamodbstreams + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb-streams.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb-streams.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + expectURL: aws.String("https://env-dynamodb-streams.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb-streams.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + expectURL: aws.String("http://config-dynamodb-streams.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-dynamodb-streams.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-dynamodb-streams.dev", + clientEndpoint: aws.String("https://client-dynamodb-streams.dev"), + expectURL: aws.String("https://client-dynamodb-streams.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_DYNAMODB_STREAMS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/dynamodbstreams/generated.json b/service/dynamodbstreams/generated.json index 344886f846c..8533fe1aa78 100644 --- a/service/dynamodbstreams/generated.json +++ b/service/dynamodbstreams/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/dynamodbstreams/go.mod b/service/dynamodbstreams/go.mod index 18487c262eb..f73a2469f34 100644 --- a/service/dynamodbstreams/go.mod +++ b/service/dynamodbstreams/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/dynamodbstreams/go.sum b/service/dynamodbstreams/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/dynamodbstreams/go.sum +++ b/service/dynamodbstreams/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ebs/api_client.go b/service/ebs/api_client.go index ba6ab11eb4a..f846090612e 100644 --- a/service/ebs/api_client.go +++ b/service/ebs/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ebs/endpoints.go b/service/ebs/endpoints.go index 72267977630..d9e383f9229 100644 --- a/service/ebs/endpoints.go +++ b/service/ebs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ebs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EBS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EBS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ebs/endpoints_config_test.go b/service/ebs/endpoints_config_test.go new file mode 100644 index 00000000000..a98cdfa0e8b --- /dev/null +++ b/service/ebs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ebs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ebs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ebs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + expectURL: aws.String("https://env-ebs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ebs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + expectURL: aws.String("http://config-ebs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ebs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ebs.dev", + clientEndpoint: aws.String("https://client-ebs.dev"), + expectURL: aws.String("https://client-ebs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EBS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ebs/generated.json b/service/ebs/generated.json index 2308f20ab0d..f07cfa26ebf 100644 --- a/service/ebs/generated.json +++ b/service/ebs/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ebs/go.mod b/service/ebs/go.mod index fb762b40619..ed191a04570 100644 --- a/service/ebs/go.mod +++ b/service/ebs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ebs/go.sum b/service/ebs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ebs/go.sum +++ b/service/ebs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ec2/api_client.go b/service/ec2/api_client.go index 13b38d11ebf..e360fd22af3 100644 --- a/service/ec2/api_client.go +++ b/service/ec2/api_client.go @@ -306,6 +306,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ec2/endpoints.go b/service/ec2/endpoints.go index 2517fe6ab8c..d34b46308ae 100644 --- a/service/ec2/endpoints.go +++ b/service/ec2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ec2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EC2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EC2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ec2/endpoints_config_test.go b/service/ec2/endpoints_config_test.go new file mode 100644 index 00000000000..7ba39b673e5 --- /dev/null +++ b/service/ec2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ec2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + expectURL: aws.String("https://env-ec2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + expectURL: aws.String("http://config-ec2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2.dev", + clientEndpoint: aws.String("https://client-ec2.dev"), + expectURL: aws.String("https://client-ec2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EC2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ec2/generated.json b/service/ec2/generated.json index 2b8971d4634..f0a5b173cec 100644 --- a/service/ec2/generated.json +++ b/service/ec2/generated.json @@ -614,6 +614,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ec2/go.mod b/service/ec2/go.mod index 0d10d67fc34..5cb64cda29f 100644 --- a/service/ec2/go.mod +++ b/service/ec2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -14,8 +15,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ec2/go.sum b/service/ec2/go.sum index ef5982af332..c64803e87e7 100644 --- a/service/ec2/go.sum +++ b/service/ec2/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/ec2instanceconnect/api_client.go b/service/ec2instanceconnect/api_client.go index 731df1b9290..395f5ed8d80 100644 --- a/service/ec2instanceconnect/api_client.go +++ b/service/ec2instanceconnect/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ec2instanceconnect/endpoints.go b/service/ec2instanceconnect/endpoints.go index c5a5fb0a542..14137d8de4f 100644 --- a/service/ec2instanceconnect/endpoints.go +++ b/service/ec2instanceconnect/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ec2instanceconnect/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EC2_INSTANCE_CONNECT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EC2 Instance Connect", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ec2instanceconnect/endpoints_config_test.go b/service/ec2instanceconnect/endpoints_config_test.go new file mode 100644 index 00000000000..9261e771854 --- /dev/null +++ b/service/ec2instanceconnect/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ec2instanceconnect + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-instance-connect.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-instance-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + expectURL: aws.String("https://env-ec2-instance-connect.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-instance-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + expectURL: aws.String("http://config-ec2-instance-connect.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ec2-instance-connect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ec2-instance-connect.dev", + clientEndpoint: aws.String("https://client-ec2-instance-connect.dev"), + expectURL: aws.String("https://client-ec2-instance-connect.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EC2_INSTANCE_CONNECT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ec2instanceconnect/generated.json b/service/ec2instanceconnect/generated.json index 49889ae645e..728006b6069 100644 --- a/service/ec2instanceconnect/generated.json +++ b/service/ec2instanceconnect/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ec2instanceconnect/go.mod b/service/ec2instanceconnect/go.mod index 7847d451a38..78f629c5604 100644 --- a/service/ec2instanceconnect/go.mod +++ b/service/ec2instanceconnect/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ec2instanceconnect/go.sum b/service/ec2instanceconnect/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ec2instanceconnect/go.sum +++ b/service/ec2instanceconnect/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ecr/api_client.go b/service/ecr/api_client.go index f1984dd44b8..d50ce733f14 100644 --- a/service/ecr/api_client.go +++ b/service/ecr/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ecr/endpoints.go b/service/ecr/endpoints.go index 8d169bdb22f..05e77f1be68 100644 --- a/service/ecr/endpoints.go +++ b/service/ecr/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ecr/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ECR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ECR", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ecr/endpoints_config_test.go b/service/ecr/endpoints_config_test.go new file mode 100644 index 00000000000..48520c39d9f --- /dev/null +++ b/service/ecr/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ecr + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + expectURL: aws.String("https://env-ecr.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + expectURL: aws.String("http://config-ecr.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr.dev", + clientEndpoint: aws.String("https://client-ecr.dev"), + expectURL: aws.String("https://client-ecr.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ECR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ecr/generated.json b/service/ecr/generated.json index 0b78f9a8986..f8382538879 100644 --- a/service/ecr/generated.json +++ b/service/ecr/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ecr/go.mod b/service/ecr/go.mod index 6c695338dea..27711cca355 100644 --- a/service/ecr/go.mod +++ b/service/ecr/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ecr/go.sum b/service/ecr/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/ecr/go.sum +++ b/service/ecr/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/ecrpublic/api_client.go b/service/ecrpublic/api_client.go index a8264f47a9d..4893a92acb7 100644 --- a/service/ecrpublic/api_client.go +++ b/service/ecrpublic/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ecrpublic/endpoints.go b/service/ecrpublic/endpoints.go index b2ed7307008..31f55832db0 100644 --- a/service/ecrpublic/endpoints.go +++ b/service/ecrpublic/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ecrpublic/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ECR_PUBLIC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ECR PUBLIC", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ecrpublic/endpoints_config_test.go b/service/ecrpublic/endpoints_config_test.go new file mode 100644 index 00000000000..367a2ae25ff --- /dev/null +++ b/service/ecrpublic/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ecrpublic + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr-public.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr-public.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + expectURL: aws.String("https://env-ecr-public.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr-public.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + expectURL: aws.String("http://config-ecr-public.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecr-public.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecr-public.dev", + clientEndpoint: aws.String("https://client-ecr-public.dev"), + expectURL: aws.String("https://client-ecr-public.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ECR_PUBLIC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ecrpublic/generated.json b/service/ecrpublic/generated.json index 067ae4319ee..51f6cdd59b0 100644 --- a/service/ecrpublic/generated.json +++ b/service/ecrpublic/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ecrpublic/go.mod b/service/ecrpublic/go.mod index b7e91fcf506..b5201a8a356 100644 --- a/service/ecrpublic/go.mod +++ b/service/ecrpublic/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ecrpublic/go.sum b/service/ecrpublic/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ecrpublic/go.sum +++ b/service/ecrpublic/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ecs/api_client.go b/service/ecs/api_client.go index c0ab6174679..d8d3afeb7af 100644 --- a/service/ecs/api_client.go +++ b/service/ecs/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ecs/endpoints.go b/service/ecs/endpoints.go index fbb12c084d1..7bb81a2020d 100644 --- a/service/ecs/endpoints.go +++ b/service/ecs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ecs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ECS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ECS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ecs/endpoints_config_test.go b/service/ecs/endpoints_config_test.go new file mode 100644 index 00000000000..b17324af5fb --- /dev/null +++ b/service/ecs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ecs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + expectURL: aws.String("https://env-ecs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + expectURL: aws.String("http://config-ecs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ecs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ecs.dev", + clientEndpoint: aws.String("https://client-ecs.dev"), + expectURL: aws.String("https://client-ecs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ECS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ecs/generated.json b/service/ecs/generated.json index 89e5102dcc3..4edbf0d29a2 100644 --- a/service/ecs/generated.json +++ b/service/ecs/generated.json @@ -69,6 +69,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ecs/go.mod b/service/ecs/go.mod index a3a434e6806..ec5281211f4 100644 --- a/service/ecs/go.mod +++ b/service/ecs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ecs/go.sum b/service/ecs/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/ecs/go.sum +++ b/service/ecs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/efs/api_client.go b/service/efs/api_client.go index 5dc03410b86..8ef54e01eeb 100644 --- a/service/efs/api_client.go +++ b/service/efs/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/efs/endpoints.go b/service/efs/endpoints.go index c18e9c888fa..8d628cdd472 100644 --- a/service/efs/endpoints.go +++ b/service/efs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/efs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EFS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EFS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/efs/endpoints_config_test.go b/service/efs/endpoints_config_test.go new file mode 100644 index 00000000000..7c86e18b833 --- /dev/null +++ b/service/efs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package efs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-efs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-efs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + expectURL: aws.String("https://env-efs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-efs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + expectURL: aws.String("http://config-efs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-efs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-efs.dev", + clientEndpoint: aws.String("https://client-efs.dev"), + expectURL: aws.String("https://client-efs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EFS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/efs/generated.json b/service/efs/generated.json index 18f17ffc06a..64e743b71a9 100644 --- a/service/efs/generated.json +++ b/service/efs/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/efs/go.mod b/service/efs/go.mod index a5a902d65f0..e843f0fd06d 100644 --- a/service/efs/go.mod +++ b/service/efs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/efs/go.sum b/service/efs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/efs/go.sum +++ b/service/efs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/eks/api_client.go b/service/eks/api_client.go index 38a685bd238..953ea03cd5f 100644 --- a/service/eks/api_client.go +++ b/service/eks/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/eks/endpoints.go b/service/eks/endpoints.go index eb0cab6e104..3c9000862b8 100644 --- a/service/eks/endpoints.go +++ b/service/eks/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/eks/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EKS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EKS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/eks/endpoints_config_test.go b/service/eks/endpoints_config_test.go new file mode 100644 index 00000000000..2b837e3c2fb --- /dev/null +++ b/service/eks/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package eks + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-eks.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-eks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + expectURL: aws.String("https://env-eks.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-eks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + expectURL: aws.String("http://config-eks.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-eks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eks.dev", + clientEndpoint: aws.String("https://client-eks.dev"), + expectURL: aws.String("https://client-eks.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EKS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/eks/generated.json b/service/eks/generated.json index 1087b29eda2..5dd7ed33a14 100644 --- a/service/eks/generated.json +++ b/service/eks/generated.json @@ -48,6 +48,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/eks/go.mod b/service/eks/go.mod index 99e840768ff..8f9c8a26e25 100644 --- a/service/eks/go.mod +++ b/service/eks/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/eks/go.sum b/service/eks/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/eks/go.sum +++ b/service/eks/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/elasticache/api_client.go b/service/elasticache/api_client.go index d75c9e709a9..719101292ab 100644 --- a/service/elasticache/api_client.go +++ b/service/elasticache/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticache/endpoints.go b/service/elasticache/endpoints.go index 538180dac99..c5e62f3e162 100644 --- a/service/elasticache/endpoints.go +++ b/service/elasticache/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticache/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTICACHE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ElastiCache", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticache/endpoints_config_test.go b/service/elasticache/endpoints_config_test.go new file mode 100644 index 00000000000..cb24f4c08cb --- /dev/null +++ b/service/elasticache/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticache + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticache.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticache.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + expectURL: aws.String("https://env-elasticache.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticache.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + expectURL: aws.String("http://config-elasticache.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticache.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticache.dev", + clientEndpoint: aws.String("https://client-elasticache.dev"), + expectURL: aws.String("https://client-elasticache.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTICACHE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticache/generated.json b/service/elasticache/generated.json index 5391227661a..6815fd30a98 100644 --- a/service/elasticache/generated.json +++ b/service/elasticache/generated.json @@ -79,6 +79,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elasticache/go.mod b/service/elasticache/go.mod index 07f7396ce11..935f443a14d 100644 --- a/service/elasticache/go.mod +++ b/service/elasticache/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticache/go.sum b/service/elasticache/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/elasticache/go.sum +++ b/service/elasticache/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/elasticbeanstalk/go.mod b/service/elasticbeanstalk/go.mod index 10fe0610e91..3ed48b71ab8 100644 --- a/service/elasticbeanstalk/go.mod +++ b/service/elasticbeanstalk/go.mod @@ -3,10 +3,35 @@ module github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk go 1.15 require ( + github.com/aws/aws-sdk-go-v2 v1.21.2 + github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 + github.com/aws/smithy-go v1.15.0 + github.com/google/go-cmp v0.5.8 github.com/jmespath/go-jmespath v0.4.0 - github.com/aws/aws-sdk-go-v2 v1.4.0 - github.com/aws/aws-sdk-go-v2/internal/configsources v0.0.0-00010101000000-000000000000 - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.0-00010101000000-000000000000 - github.com/aws/smithy-go v1.4.0 - github.com/google/go-cmp v0.5.4 ) + +replace github.com/aws/aws-sdk-go-v2 => ../../ + +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + +replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticinference/api_client.go b/service/elasticinference/api_client.go index 6c6a2716972..5ffc00b0bf6 100644 --- a/service/elasticinference/api_client.go +++ b/service/elasticinference/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticinference/endpoints.go b/service/elasticinference/endpoints.go index e8f475e6bd2..d3d08c48320 100644 --- a/service/elasticinference/endpoints.go +++ b/service/elasticinference/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticinference/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_INFERENCE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Inference", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticinference/endpoints_config_test.go b/service/elasticinference/endpoints_config_test.go new file mode 100644 index 00000000000..8336d052a04 --- /dev/null +++ b/service/elasticinference/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticinference + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-inference.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-inference.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + expectURL: aws.String("https://env-elastic-inference.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-inference.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + expectURL: aws.String("http://config-elastic-inference.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-inference.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-inference.dev", + clientEndpoint: aws.String("https://client-elastic-inference.dev"), + expectURL: aws.String("https://client-elastic-inference.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTIC_INFERENCE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticinference/generated.json b/service/elasticinference/generated.json index b8087ec7a86..3d01f16563c 100644 --- a/service/elasticinference/generated.json +++ b/service/elasticinference/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elasticinference/go.mod b/service/elasticinference/go.mod index 24c4d3c3ac3..091b12701b2 100644 --- a/service/elasticinference/go.mod +++ b/service/elasticinference/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticinference/go.sum b/service/elasticinference/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/elasticinference/go.sum +++ b/service/elasticinference/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/elasticloadbalancing/api_client.go b/service/elasticloadbalancing/api_client.go index 6badf7e4cef..4745b4939e3 100644 --- a/service/elasticloadbalancing/api_client.go +++ b/service/elasticloadbalancing/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticloadbalancing/endpoints.go b/service/elasticloadbalancing/endpoints.go index 52f36dcc761..5a31df6d97d 100644 --- a/service/elasticloadbalancing/endpoints.go +++ b/service/elasticloadbalancing/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Load Balancing", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticloadbalancing/endpoints_config_test.go b/service/elasticloadbalancing/endpoints_config_test.go new file mode 100644 index 00000000000..da5415b9220 --- /dev/null +++ b/service/elasticloadbalancing/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticloadbalancing + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + expectURL: aws.String("https://env-elastic-load-balancing.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + expectURL: aws.String("http://config-elastic-load-balancing.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing.dev", + clientEndpoint: aws.String("https://client-elastic-load-balancing.dev"), + expectURL: aws.String("https://client-elastic-load-balancing.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticloadbalancing/generated.json b/service/elasticloadbalancing/generated.json index 43a4f9be4db..55443a677cc 100644 --- a/service/elasticloadbalancing/generated.json +++ b/service/elasticloadbalancing/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elasticloadbalancing/go.mod b/service/elasticloadbalancing/go.mod index 86841f518a3..e6f942bfc0d 100644 --- a/service/elasticloadbalancing/go.mod +++ b/service/elasticloadbalancing/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticloadbalancing/go.sum b/service/elasticloadbalancing/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/elasticloadbalancing/go.sum +++ b/service/elasticloadbalancing/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/elasticloadbalancingv2/api_client.go b/service/elasticloadbalancingv2/api_client.go index e0a8cb15fd7..8ea0b25f26e 100644 --- a/service/elasticloadbalancingv2/api_client.go +++ b/service/elasticloadbalancingv2/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticloadbalancingv2/endpoints.go b/service/elasticloadbalancingv2/endpoints.go index bb0d0339f27..a2013f8ace8 100644 --- a/service/elasticloadbalancingv2/endpoints.go +++ b/service/elasticloadbalancingv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Load Balancing v2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticloadbalancingv2/endpoints_config_test.go b/service/elasticloadbalancingv2/endpoints_config_test.go new file mode 100644 index 00000000000..b9d94c4b9e5 --- /dev/null +++ b/service/elasticloadbalancingv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticloadbalancingv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + expectURL: aws.String("https://env-elastic-load-balancing-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + expectURL: aws.String("http://config-elastic-load-balancing-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-load-balancing-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-load-balancing-v2.dev", + clientEndpoint: aws.String("https://client-elastic-load-balancing-v2.dev"), + expectURL: aws.String("https://client-elastic-load-balancing-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticloadbalancingv2/generated.json b/service/elasticloadbalancingv2/generated.json index c81ab646bf2..c70c3ed69b8 100644 --- a/service/elasticloadbalancingv2/generated.json +++ b/service/elasticloadbalancingv2/generated.json @@ -47,6 +47,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elasticloadbalancingv2/go.mod b/service/elasticloadbalancingv2/go.mod index 667089680f9..f811213161c 100644 --- a/service/elasticloadbalancingv2/go.mod +++ b/service/elasticloadbalancingv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticloadbalancingv2/go.sum b/service/elasticloadbalancingv2/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/elasticloadbalancingv2/go.sum +++ b/service/elasticloadbalancingv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/elasticsearchservice/api_client.go b/service/elasticsearchservice/api_client.go index eb060b8bdd7..24a02c8e849 100644 --- a/service/elasticsearchservice/api_client.go +++ b/service/elasticsearchservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elasticsearchservice/endpoints.go b/service/elasticsearchservice/endpoints.go index 7ab232ca20e..a220bcfa822 100644 --- a/service/elasticsearchservice/endpoints.go +++ b/service/elasticsearchservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elasticsearchservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTICSEARCH_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elasticsearch Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elasticsearchservice/endpoints_config_test.go b/service/elasticsearchservice/endpoints_config_test.go new file mode 100644 index 00000000000..8a4b8ba6be3 --- /dev/null +++ b/service/elasticsearchservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elasticsearchservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticsearch-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticsearch-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + expectURL: aws.String("https://env-elasticsearch-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticsearch-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + expectURL: aws.String("http://config-elasticsearch-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elasticsearch-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elasticsearch-service.dev", + clientEndpoint: aws.String("https://client-elasticsearch-service.dev"), + expectURL: aws.String("https://client-elasticsearch-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTICSEARCH_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elasticsearchservice/generated.json b/service/elasticsearchservice/generated.json index 8be6f08ac0e..1240a605c7f 100644 --- a/service/elasticsearchservice/generated.json +++ b/service/elasticsearchservice/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elasticsearchservice/go.mod b/service/elasticsearchservice/go.mod index cee49128e18..3340735c1cb 100644 --- a/service/elasticsearchservice/go.mod +++ b/service/elasticsearchservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elasticsearchservice/go.sum b/service/elasticsearchservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/elasticsearchservice/go.sum +++ b/service/elasticsearchservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/elastictranscoder/api_client.go b/service/elastictranscoder/api_client.go index 068e42fe40c..4e3550f95be 100644 --- a/service/elastictranscoder/api_client.go +++ b/service/elastictranscoder/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/elastictranscoder/endpoints.go b/service/elastictranscoder/endpoints.go index b3d7b1f4c70..9503188353e 100644 --- a/service/elastictranscoder/endpoints.go +++ b/service/elastictranscoder/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/elastictranscoder/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ELASTIC_TRANSCODER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Elastic Transcoder", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/elastictranscoder/endpoints_config_test.go b/service/elastictranscoder/endpoints_config_test.go new file mode 100644 index 00000000000..2d9d7186386 --- /dev/null +++ b/service/elastictranscoder/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package elastictranscoder + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-transcoder.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-transcoder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + expectURL: aws.String("https://env-elastic-transcoder.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-transcoder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + expectURL: aws.String("http://config-elastic-transcoder.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-elastic-transcoder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-elastic-transcoder.dev", + clientEndpoint: aws.String("https://client-elastic-transcoder.dev"), + expectURL: aws.String("https://client-elastic-transcoder.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ELASTIC_TRANSCODER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/elastictranscoder/generated.json b/service/elastictranscoder/generated.json index 727faaeb29f..2e15f7902b6 100644 --- a/service/elastictranscoder/generated.json +++ b/service/elastictranscoder/generated.json @@ -30,6 +30,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/elastictranscoder/go.mod b/service/elastictranscoder/go.mod index 4a954caa573..e7163e5a89e 100644 --- a/service/elastictranscoder/go.mod +++ b/service/elastictranscoder/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/elastictranscoder/go.sum b/service/elastictranscoder/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/elastictranscoder/go.sum +++ b/service/elastictranscoder/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/emr/api_client.go b/service/emr/api_client.go index 6aa890a9d68..1c03fb809da 100644 --- a/service/emr/api_client.go +++ b/service/emr/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/emr/endpoints.go b/service/emr/endpoints.go index 337aca88eb3..ad0bd3caa85 100644 --- a/service/emr/endpoints.go +++ b/service/emr/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/emr/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EMR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EMR", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/emr/endpoints_config_test.go b/service/emr/endpoints_config_test.go new file mode 100644 index 00000000000..e2c7c837dd8 --- /dev/null +++ b/service/emr/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package emr + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + expectURL: aws.String("https://env-emr.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + expectURL: aws.String("http://config-emr.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr.dev", + clientEndpoint: aws.String("https://client-emr.dev"), + expectURL: aws.String("https://client-emr.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EMR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/emr/generated.json b/service/emr/generated.json index 718b56496fc..5bf089b83d7 100644 --- a/service/emr/generated.json +++ b/service/emr/generated.json @@ -67,6 +67,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/emr/go.mod b/service/emr/go.mod index 84c96c12148..edba388d9db 100644 --- a/service/emr/go.mod +++ b/service/emr/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/emr/go.sum b/service/emr/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/emr/go.sum +++ b/service/emr/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/emrcontainers/api_client.go b/service/emrcontainers/api_client.go index 7410565c93d..326b69080ea 100644 --- a/service/emrcontainers/api_client.go +++ b/service/emrcontainers/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/emrcontainers/endpoints.go b/service/emrcontainers/endpoints.go index 91e8f7464ee..219305e2aee 100644 --- a/service/emrcontainers/endpoints.go +++ b/service/emrcontainers/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/emrcontainers/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EMR_CONTAINERS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EMR containers", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/emrcontainers/endpoints_config_test.go b/service/emrcontainers/endpoints_config_test.go new file mode 100644 index 00000000000..17d935c48ac --- /dev/null +++ b/service/emrcontainers/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package emrcontainers + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-containers.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-containers.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + expectURL: aws.String("https://env-emr-containers.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-containers.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + expectURL: aws.String("http://config-emr-containers.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-containers.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-containers.dev", + clientEndpoint: aws.String("https://client-emr-containers.dev"), + expectURL: aws.String("https://client-emr-containers.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EMR_CONTAINERS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/emrcontainers/generated.json b/service/emrcontainers/generated.json index ae57913eb58..f9fa176811c 100644 --- a/service/emrcontainers/generated.json +++ b/service/emrcontainers/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/emrcontainers/go.mod b/service/emrcontainers/go.mod index 44fff39b01d..6125fdacd91 100644 --- a/service/emrcontainers/go.mod +++ b/service/emrcontainers/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/emrcontainers/go.sum b/service/emrcontainers/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/emrcontainers/go.sum +++ b/service/emrcontainers/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/emrserverless/api_client.go b/service/emrserverless/api_client.go index 532cae506b9..9825cad7f73 100644 --- a/service/emrserverless/api_client.go +++ b/service/emrserverless/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/emrserverless/endpoints.go b/service/emrserverless/endpoints.go index ecf9dccee2a..8641f2c981c 100644 --- a/service/emrserverless/endpoints.go +++ b/service/emrserverless/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/emrserverless/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EMR_SERVERLESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EMR Serverless", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/emrserverless/endpoints_config_test.go b/service/emrserverless/endpoints_config_test.go new file mode 100644 index 00000000000..658b0bdc1ce --- /dev/null +++ b/service/emrserverless/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package emrserverless + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-serverless.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + expectURL: aws.String("https://env-emr-serverless.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + expectURL: aws.String("http://config-emr-serverless.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-emr-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-emr-serverless.dev", + clientEndpoint: aws.String("https://client-emr-serverless.dev"), + expectURL: aws.String("https://client-emr-serverless.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EMR_SERVERLESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/emrserverless/generated.json b/service/emrserverless/generated.json index a426e6aeece..6cf95cb3337 100644 --- a/service/emrserverless/generated.json +++ b/service/emrserverless/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/emrserverless/go.mod b/service/emrserverless/go.mod index 1b618e53a6d..82a134346bb 100644 --- a/service/emrserverless/go.mod +++ b/service/emrserverless/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/emrserverless/go.sum b/service/emrserverless/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/emrserverless/go.sum +++ b/service/emrserverless/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/entityresolution/api_client.go b/service/entityresolution/api_client.go index d9061490d9d..cc587e072b7 100644 --- a/service/entityresolution/api_client.go +++ b/service/entityresolution/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/entityresolution/endpoints.go b/service/entityresolution/endpoints.go index 15c3179315b..d5f9d1511f0 100644 --- a/service/entityresolution/endpoints.go +++ b/service/entityresolution/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/entityresolution/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ENTITYRESOLUTION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EntityResolution", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/entityresolution/endpoints_config_test.go b/service/entityresolution/endpoints_config_test.go new file mode 100644 index 00000000000..b8b32bfce3f --- /dev/null +++ b/service/entityresolution/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package entityresolution + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-entityresolution.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-entityresolution.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + expectURL: aws.String("https://env-entityresolution.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-entityresolution.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + expectURL: aws.String("http://config-entityresolution.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-entityresolution.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-entityresolution.dev", + clientEndpoint: aws.String("https://client-entityresolution.dev"), + expectURL: aws.String("https://client-entityresolution.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ENTITYRESOLUTION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/entityresolution/generated.json b/service/entityresolution/generated.json index 5d6bbe9eed8..c0cd18d99ce 100644 --- a/service/entityresolution/generated.json +++ b/service/entityresolution/generated.json @@ -41,6 +41,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/entityresolution/go.mod b/service/entityresolution/go.mod index 292cc0f3636..9225980b357 100644 --- a/service/entityresolution/go.mod +++ b/service/entityresolution/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/entityresolution/go.sum b/service/entityresolution/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/entityresolution/go.sum +++ b/service/entityresolution/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/eventbridge/endpoints.go b/service/eventbridge/endpoints.go index 16d9480a7c4..d5a9048d63c 100644 --- a/service/eventbridge/endpoints.go +++ b/service/eventbridge/endpoints.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/eventbridge/internal/endpoints" @@ -20,6 +19,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -202,13 +202,15 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []config.Config - for _, c := range cfg.ConfigSources { - if cs, ok := c.(config.Config); ok { - configSources = append(configSources, cs) - } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EVENTBRIDGE") + + if g && !s { + return } - value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EventBridge", configSources) + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "EventBridge", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } diff --git a/service/eventbridge/endpoints_config_test.go b/service/eventbridge/endpoints_config_test.go index 476b53fff36..102ad15583d 100644 --- a/service/eventbridge/endpoints_config_test.go +++ b/service/eventbridge/endpoints_config_test.go @@ -5,141 +5,133 @@ package eventbridge import ( "context" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" "os" - "path/filepath" "reflect" "testing" ) -func TestConfiguredEndpoints(t *testing.T) { +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-eventbridge - -[services testing-eventbridge] -eventbridge = - endpoint_url = http://config-eventbridge.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-eventbridge.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-eventbridge - -[services testing-eventbridge] -eventbridge = - endpoint_url = http://config-eventbridge.dev -`, - ExpectURL: aws.String("https://env-eventbridge.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-eventbridge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + expectURL: aws.String("https://env-eventbridge.dev"), }, "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-eventbridge -ignore_configured_endpoint_urls = true - -[services testing-eventbridge] -eventbridge = - endpoint_url = http://config-eventbridge.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-eventbridge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + configIgnore: true, + expectURL: nil, }, "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("http://config-global.dev"), + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), }, "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-eventbridge - -[services testing-eventbridge] -eventbridge = - endpoint_url = http://config-eventbridge.dev -`, - ExpectURL: aws.String("http://config-eventbridge.dev"), + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + expectURL: aws.String("http://config-eventbridge.dev"), }, "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_EVENTBRIDGE": "https://env-eventbridge.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-eventbridge - -[services testing-eventbridge] -eventbridge = - endpoint_url = http://config-eventbridge.dev -`, - ClientEndpoint: aws.String("https://client-eventbridge.dev"), - ExpectURL: aws.String("https://client-eventbridge.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-eventbridge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-eventbridge.dev", + clientEndpoint: aws.String("https://client-eventbridge.dev"), + expectURL: aws.String("https://client-eventbridge.dev"), }, } for name, c := range cases { t.Run(name, func(t *testing.T) { os.Clearenv() - for k, v := range c.Env { - t.Setenv(k, v) + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) } - tmpDir := t.TempDir() - os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EVENTBRIDGE", c.envService) + } - awsConfig, err := config.LoadDefaultConfig( - context.TODO(), - config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), - config.WithSharedConfigProfile("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, } client := NewFromConfig(awsConfig, func(o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) diff --git a/service/eventbridge/go.mod b/service/eventbridge/go.mod index f9db8aaf841..a4f363728a8 100644 --- a/service/eventbridge/go.mod +++ b/service/eventbridge/go.mod @@ -4,7 +4,6 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 - github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 @@ -15,12 +14,26 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ -replace github.com/aws/aws-sdk-go-v2/config => ../../config +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ -replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/v4a => ../../internal/v4a/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/evidently/api_client.go b/service/evidently/api_client.go index 15356a46671..7767df37e91 100644 --- a/service/evidently/api_client.go +++ b/service/evidently/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/evidently/endpoints.go b/service/evidently/endpoints.go index 284b247e3a1..72ca6f0e8a9 100644 --- a/service/evidently/endpoints.go +++ b/service/evidently/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/evidently/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_EVIDENTLY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Evidently", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/evidently/endpoints_config_test.go b/service/evidently/endpoints_config_test.go new file mode 100644 index 00000000000..f019110b892 --- /dev/null +++ b/service/evidently/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package evidently + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-evidently.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-evidently.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + expectURL: aws.String("https://env-evidently.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-evidently.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + expectURL: aws.String("http://config-evidently.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-evidently.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-evidently.dev", + clientEndpoint: aws.String("https://client-evidently.dev"), + expectURL: aws.String("https://client-evidently.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_EVIDENTLY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/evidently/generated.json b/service/evidently/generated.json index 5f4772ace3a..2176c7dc564 100644 --- a/service/evidently/generated.json +++ b/service/evidently/generated.json @@ -50,6 +50,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/evidently/go.mod b/service/evidently/go.mod index 74bb682fe44..fe1a2efb71e 100644 --- a/service/evidently/go.mod +++ b/service/evidently/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/evidently/go.sum b/service/evidently/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/evidently/go.sum +++ b/service/evidently/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/finspace/api_client.go b/service/finspace/api_client.go index 8649c4bfea2..dee807ed54f 100644 --- a/service/finspace/api_client.go +++ b/service/finspace/api_client.go @@ -305,6 +305,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/finspace/endpoints.go b/service/finspace/endpoints.go index 5a4853f2d04..d3f0ce58c7a 100644 --- a/service/finspace/endpoints.go +++ b/service/finspace/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/finspace/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FINSPACE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "finspace", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/finspace/endpoints_config_test.go b/service/finspace/endpoints_config_test.go new file mode 100644 index 00000000000..c7562d3c9b7 --- /dev/null +++ b/service/finspace/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package finspace + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + expectURL: aws.String("https://env-finspace.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + expectURL: aws.String("http://config-finspace.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace.dev", + clientEndpoint: aws.String("https://client-finspace.dev"), + expectURL: aws.String("https://client-finspace.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FINSPACE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/finspace/generated.json b/service/finspace/generated.json index efea387a8af..c09e04f4f3b 100644 --- a/service/finspace/generated.json +++ b/service/finspace/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/finspace/go.mod b/service/finspace/go.mod index 47ec7045616..80d86a10691 100644 --- a/service/finspace/go.mod +++ b/service/finspace/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/finspace/go.sum b/service/finspace/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/finspace/go.sum +++ b/service/finspace/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/finspacedata/api_client.go b/service/finspacedata/api_client.go index ecd60b702f8..fe2cd4c40ef 100644 --- a/service/finspacedata/api_client.go +++ b/service/finspacedata/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/finspacedata/endpoints.go b/service/finspacedata/endpoints.go index bf401a95c51..575f9b30e23 100644 --- a/service/finspacedata/endpoints.go +++ b/service/finspacedata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/finspacedata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FINSPACE_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "finspace data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/finspacedata/endpoints_config_test.go b/service/finspacedata/endpoints_config_test.go new file mode 100644 index 00000000000..c7e49876de9 --- /dev/null +++ b/service/finspacedata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package finspacedata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + expectURL: aws.String("https://env-finspace-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + expectURL: aws.String("http://config-finspace-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-finspace-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-finspace-data.dev", + clientEndpoint: aws.String("https://client-finspace-data.dev"), + expectURL: aws.String("https://client-finspace-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FINSPACE_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/finspacedata/generated.json b/service/finspacedata/generated.json index 09ba517c61d..39b29973f7d 100644 --- a/service/finspacedata/generated.json +++ b/service/finspacedata/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/finspacedata/go.mod b/service/finspacedata/go.mod index f1593ddde4b..d145f59c254 100644 --- a/service/finspacedata/go.mod +++ b/service/finspacedata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/finspacedata/go.sum b/service/finspacedata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/finspacedata/go.sum +++ b/service/finspacedata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/firehose/api_client.go b/service/firehose/api_client.go index 1badb780f3d..6e7b6eab7a5 100644 --- a/service/firehose/api_client.go +++ b/service/firehose/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/firehose/endpoints.go b/service/firehose/endpoints.go index 38ed9c8b501..826475bb8c5 100644 --- a/service/firehose/endpoints.go +++ b/service/firehose/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/firehose/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FIREHOSE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Firehose", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/firehose/endpoints_config_test.go b/service/firehose/endpoints_config_test.go new file mode 100644 index 00000000000..515f2c9acd2 --- /dev/null +++ b/service/firehose/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package firehose + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-firehose.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-firehose.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + expectURL: aws.String("https://env-firehose.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-firehose.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + expectURL: aws.String("http://config-firehose.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-firehose.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-firehose.dev", + clientEndpoint: aws.String("https://client-firehose.dev"), + expectURL: aws.String("https://client-firehose.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FIREHOSE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/firehose/generated.json b/service/firehose/generated.json index 862896a03be..1e6d13d2d22 100644 --- a/service/firehose/generated.json +++ b/service/firehose/generated.json @@ -24,6 +24,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/firehose/go.mod b/service/firehose/go.mod index 69c86cdbe2e..9f383d97468 100644 --- a/service/firehose/go.mod +++ b/service/firehose/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/firehose/go.sum b/service/firehose/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/firehose/go.sum +++ b/service/firehose/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/fis/api_client.go b/service/fis/api_client.go index 17b44dc9e9e..00a55c005bc 100644 --- a/service/fis/api_client.go +++ b/service/fis/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/fis/endpoints.go b/service/fis/endpoints.go index 1f0ec18d368..d086458fb43 100644 --- a/service/fis/endpoints.go +++ b/service/fis/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/fis/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FIS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "fis", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/fis/endpoints_config_test.go b/service/fis/endpoints_config_test.go new file mode 100644 index 00000000000..58cab4de858 --- /dev/null +++ b/service/fis/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package fis + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fis.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-fis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + expectURL: aws.String("https://env-fis.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + expectURL: aws.String("http://config-fis.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-fis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fis.dev", + clientEndpoint: aws.String("https://client-fis.dev"), + expectURL: aws.String("https://client-fis.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FIS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/fis/generated.json b/service/fis/generated.json index 8847c943ddc..143f5e96e36 100644 --- a/service/fis/generated.json +++ b/service/fis/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/fis/go.mod b/service/fis/go.mod index 3adf861ec78..d277173f2f6 100644 --- a/service/fis/go.mod +++ b/service/fis/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/fis/go.sum b/service/fis/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/fis/go.sum +++ b/service/fis/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/fms/api_client.go b/service/fms/api_client.go index bd9f94249f6..d118539e503 100644 --- a/service/fms/api_client.go +++ b/service/fms/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/fms/endpoints.go b/service/fms/endpoints.go index 0359d1b3b4c..d735cb6e63f 100644 --- a/service/fms/endpoints.go +++ b/service/fms/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/fms/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FMS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "FMS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/fms/endpoints_config_test.go b/service/fms/endpoints_config_test.go new file mode 100644 index 00000000000..82d5c4e54ea --- /dev/null +++ b/service/fms/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package fms + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fms.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-fms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + expectURL: aws.String("https://env-fms.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + expectURL: aws.String("http://config-fms.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-fms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fms.dev", + clientEndpoint: aws.String("https://client-fms.dev"), + expectURL: aws.String("https://client-fms.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FMS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/fms/generated.json b/service/fms/generated.json index 936a0eea9ac..ecc052093a1 100644 --- a/service/fms/generated.json +++ b/service/fms/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/fms/go.mod b/service/fms/go.mod index 92481b68ca9..3357f173c37 100644 --- a/service/fms/go.mod +++ b/service/fms/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/fms/go.sum b/service/fms/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/fms/go.sum +++ b/service/fms/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/forecast/api_client.go b/service/forecast/api_client.go index 1315e10997d..97a4f6039f1 100644 --- a/service/forecast/api_client.go +++ b/service/forecast/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/forecast/endpoints.go b/service/forecast/endpoints.go index 2055c6a5888..37baa3a50a6 100644 --- a/service/forecast/endpoints.go +++ b/service/forecast/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/forecast/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FORECAST") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "forecast", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/forecast/endpoints_config_test.go b/service/forecast/endpoints_config_test.go new file mode 100644 index 00000000000..bf953a7cfd2 --- /dev/null +++ b/service/forecast/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package forecast + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecast.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecast.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + expectURL: aws.String("https://env-forecast.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecast.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + expectURL: aws.String("http://config-forecast.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecast.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecast.dev", + clientEndpoint: aws.String("https://client-forecast.dev"), + expectURL: aws.String("https://client-forecast.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FORECAST", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/forecast/generated.json b/service/forecast/generated.json index 20b3071b031..1e4a7331447 100644 --- a/service/forecast/generated.json +++ b/service/forecast/generated.json @@ -75,6 +75,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/forecast/go.mod b/service/forecast/go.mod index 7a79f2efbc9..d7f2b9be0e8 100644 --- a/service/forecast/go.mod +++ b/service/forecast/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/forecast/go.sum b/service/forecast/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/forecast/go.sum +++ b/service/forecast/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/forecastquery/api_client.go b/service/forecastquery/api_client.go index 2ca1aba2d0d..32cd582e20f 100644 --- a/service/forecastquery/api_client.go +++ b/service/forecastquery/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/forecastquery/endpoints.go b/service/forecastquery/endpoints.go index 7da3c4e5ea3..ae46250b2cb 100644 --- a/service/forecastquery/endpoints.go +++ b/service/forecastquery/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/forecastquery/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FORECASTQUERY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "forecastquery", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/forecastquery/endpoints_config_test.go b/service/forecastquery/endpoints_config_test.go new file mode 100644 index 00000000000..e007d2a5ee7 --- /dev/null +++ b/service/forecastquery/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package forecastquery + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecastquery.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecastquery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + expectURL: aws.String("https://env-forecastquery.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecastquery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + expectURL: aws.String("http://config-forecastquery.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-forecastquery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-forecastquery.dev", + clientEndpoint: aws.String("https://client-forecastquery.dev"), + expectURL: aws.String("https://client-forecastquery.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FORECASTQUERY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/forecastquery/generated.json b/service/forecastquery/generated.json index 076b7bb94a9..184047cbc91 100644 --- a/service/forecastquery/generated.json +++ b/service/forecastquery/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/forecastquery/go.mod b/service/forecastquery/go.mod index 1c4f7674b83..7a407af7232 100644 --- a/service/forecastquery/go.mod +++ b/service/forecastquery/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/forecastquery/go.sum b/service/forecastquery/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/forecastquery/go.sum +++ b/service/forecastquery/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/frauddetector/api_client.go b/service/frauddetector/api_client.go index f5e6606d23c..f729f148ff9 100644 --- a/service/frauddetector/api_client.go +++ b/service/frauddetector/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/frauddetector/endpoints.go b/service/frauddetector/endpoints.go index b72a96a2791..369d2fd9b5a 100644 --- a/service/frauddetector/endpoints.go +++ b/service/frauddetector/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/frauddetector/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FRAUDDETECTOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "FraudDetector", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/frauddetector/endpoints_config_test.go b/service/frauddetector/endpoints_config_test.go new file mode 100644 index 00000000000..5fd54e5ecc7 --- /dev/null +++ b/service/frauddetector/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package frauddetector + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-frauddetector.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-frauddetector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + expectURL: aws.String("https://env-frauddetector.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-frauddetector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + expectURL: aws.String("http://config-frauddetector.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-frauddetector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-frauddetector.dev", + clientEndpoint: aws.String("https://client-frauddetector.dev"), + expectURL: aws.String("https://client-frauddetector.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FRAUDDETECTOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/frauddetector/generated.json b/service/frauddetector/generated.json index 74cfe3f7da0..cb10a57c06b 100644 --- a/service/frauddetector/generated.json +++ b/service/frauddetector/generated.json @@ -85,6 +85,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/frauddetector/go.mod b/service/frauddetector/go.mod index b29d207a150..45fde211830 100644 --- a/service/frauddetector/go.mod +++ b/service/frauddetector/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/frauddetector/go.sum b/service/frauddetector/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/frauddetector/go.sum +++ b/service/frauddetector/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/fsx/api_client.go b/service/fsx/api_client.go index 39a524cfe57..cf85df42647 100644 --- a/service/fsx/api_client.go +++ b/service/fsx/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/fsx/endpoints.go b/service/fsx/endpoints.go index 8cd3d899c62..bef9e119c41 100644 --- a/service/fsx/endpoints.go +++ b/service/fsx/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/fsx/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_FSX") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "FSx", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/fsx/endpoints_config_test.go b/service/fsx/endpoints_config_test.go new file mode 100644 index 00000000000..0a6080988df --- /dev/null +++ b/service/fsx/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package fsx + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fsx.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-fsx.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + expectURL: aws.String("https://env-fsx.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-fsx.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + expectURL: aws.String("http://config-fsx.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-fsx.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-fsx.dev", + clientEndpoint: aws.String("https://client-fsx.dev"), + expectURL: aws.String("https://client-fsx.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_FSX", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/fsx/generated.json b/service/fsx/generated.json index 04146fb7f67..cd038306576 100644 --- a/service/fsx/generated.json +++ b/service/fsx/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/fsx/go.mod b/service/fsx/go.mod index ed8f0420ad9..ba078926065 100644 --- a/service/fsx/go.mod +++ b/service/fsx/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/fsx/go.sum b/service/fsx/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/fsx/go.sum +++ b/service/fsx/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/gamelift/api_client.go b/service/gamelift/api_client.go index 31544769599..f12487bbe96 100644 --- a/service/gamelift/api_client.go +++ b/service/gamelift/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/gamelift/endpoints.go b/service/gamelift/endpoints.go index bec26de4d75..ddd8df946b3 100644 --- a/service/gamelift/endpoints.go +++ b/service/gamelift/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/gamelift/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GAMELIFT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "GameLift", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/gamelift/endpoints_config_test.go b/service/gamelift/endpoints_config_test.go new file mode 100644 index 00000000000..46ba2622251 --- /dev/null +++ b/service/gamelift/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package gamelift + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-gamelift.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-gamelift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + expectURL: aws.String("https://env-gamelift.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-gamelift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + expectURL: aws.String("http://config-gamelift.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-gamelift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-gamelift.dev", + clientEndpoint: aws.String("https://client-gamelift.dev"), + expectURL: aws.String("https://client-gamelift.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GAMELIFT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/gamelift/generated.json b/service/gamelift/generated.json index a37b21e6e72..d6d91ae5aa3 100644 --- a/service/gamelift/generated.json +++ b/service/gamelift/generated.json @@ -116,6 +116,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/gamelift/go.mod b/service/gamelift/go.mod index 1b5c12f979d..f7a59f50e0b 100644 --- a/service/gamelift/go.mod +++ b/service/gamelift/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/gamelift/go.sum b/service/gamelift/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/gamelift/go.sum +++ b/service/gamelift/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/glacier/api_client.go b/service/glacier/api_client.go index 8c476c70dcc..6b0215e3b11 100644 --- a/service/glacier/api_client.go +++ b/service/glacier/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/glacier/endpoints.go b/service/glacier/endpoints.go index c042a4344bf..571d50ae205 100644 --- a/service/glacier/endpoints.go +++ b/service/glacier/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/glacier/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GLACIER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Glacier", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/glacier/endpoints_config_test.go b/service/glacier/endpoints_config_test.go new file mode 100644 index 00000000000..e4d73740703 --- /dev/null +++ b/service/glacier/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package glacier + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-glacier.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-glacier.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + expectURL: aws.String("https://env-glacier.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-glacier.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + expectURL: aws.String("http://config-glacier.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-glacier.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glacier.dev", + clientEndpoint: aws.String("https://client-glacier.dev"), + expectURL: aws.String("https://client-glacier.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GLACIER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/glacier/generated.json b/service/glacier/generated.json index 56ff1fe76cd..6c27f326bb1 100644 --- a/service/glacier/generated.json +++ b/service/glacier/generated.json @@ -45,6 +45,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/glacier/go.mod b/service/glacier/go.mod index b124516d916..da02f139f9d 100644 --- a/service/glacier/go.mod +++ b/service/glacier/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/glacier/go.sum b/service/glacier/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/glacier/go.sum +++ b/service/glacier/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/globalaccelerator/api_client.go b/service/globalaccelerator/api_client.go index ba52386b9ae..b09165385a7 100644 --- a/service/globalaccelerator/api_client.go +++ b/service/globalaccelerator/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/globalaccelerator/endpoints.go b/service/globalaccelerator/endpoints.go index a63e6acb7ad..ae2007792a3 100644 --- a/service/globalaccelerator/endpoints.go +++ b/service/globalaccelerator/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/globalaccelerator/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GLOBAL_ACCELERATOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Global Accelerator", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/globalaccelerator/endpoints_config_test.go b/service/globalaccelerator/endpoints_config_test.go new file mode 100644 index 00000000000..c5ebb730f27 --- /dev/null +++ b/service/globalaccelerator/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package globalaccelerator + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-global-accelerator.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-global-accelerator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + expectURL: aws.String("https://env-global-accelerator.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-global-accelerator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + expectURL: aws.String("http://config-global-accelerator.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-global-accelerator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-global-accelerator.dev", + clientEndpoint: aws.String("https://client-global-accelerator.dev"), + expectURL: aws.String("https://client-global-accelerator.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GLOBAL_ACCELERATOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/globalaccelerator/generated.json b/service/globalaccelerator/generated.json index 6082333e927..25b09b4d3af 100644 --- a/service/globalaccelerator/generated.json +++ b/service/globalaccelerator/generated.json @@ -61,6 +61,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/globalaccelerator/go.mod b/service/globalaccelerator/go.mod index 663474878b7..ab377c2123f 100644 --- a/service/globalaccelerator/go.mod +++ b/service/globalaccelerator/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/globalaccelerator/go.sum b/service/globalaccelerator/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/globalaccelerator/go.sum +++ b/service/globalaccelerator/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/glue/api_client.go b/service/glue/api_client.go index 4c467ebbb46..fb21544aa6e 100644 --- a/service/glue/api_client.go +++ b/service/glue/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/glue/endpoints.go b/service/glue/endpoints.go index dc42f91d6ed..dbeac1390ae 100644 --- a/service/glue/endpoints.go +++ b/service/glue/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/glue/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GLUE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Glue", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/glue/endpoints_config_test.go b/service/glue/endpoints_config_test.go new file mode 100644 index 00000000000..ff4caa68ac1 --- /dev/null +++ b/service/glue/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package glue + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-glue.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-glue.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + expectURL: aws.String("https://env-glue.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-glue.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + expectURL: aws.String("http://config-glue.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-glue.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-glue.dev", + clientEndpoint: aws.String("https://client-glue.dev"), + expectURL: aws.String("https://client-glue.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GLUE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/glue/generated.json b/service/glue/generated.json index 82116982b36..6e668926df7 100644 --- a/service/glue/generated.json +++ b/service/glue/generated.json @@ -214,6 +214,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/glue/go.mod b/service/glue/go.mod index d8cfe8fc659..c0b81707334 100644 --- a/service/glue/go.mod +++ b/service/glue/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/glue/go.sum b/service/glue/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/glue/go.sum +++ b/service/glue/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/grafana/api_client.go b/service/grafana/api_client.go index a78d37fc155..d87305232ff 100644 --- a/service/grafana/api_client.go +++ b/service/grafana/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/grafana/endpoints.go b/service/grafana/endpoints.go index a11eb1ce369..d4800022583 100644 --- a/service/grafana/endpoints.go +++ b/service/grafana/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/grafana/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GRAFANA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "grafana", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/grafana/endpoints_config_test.go b/service/grafana/endpoints_config_test.go new file mode 100644 index 00000000000..61b2d4a2f26 --- /dev/null +++ b/service/grafana/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package grafana + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-grafana.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-grafana.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + expectURL: aws.String("https://env-grafana.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-grafana.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + expectURL: aws.String("http://config-grafana.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-grafana.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-grafana.dev", + clientEndpoint: aws.String("https://client-grafana.dev"), + expectURL: aws.String("https://client-grafana.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GRAFANA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/grafana/generated.json b/service/grafana/generated.json index 8b191b4f2ca..03b25d8fbee 100644 --- a/service/grafana/generated.json +++ b/service/grafana/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/grafana/go.mod b/service/grafana/go.mod index d5b30f2494c..5dd1999b3b2 100644 --- a/service/grafana/go.mod +++ b/service/grafana/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/grafana/go.sum b/service/grafana/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/grafana/go.sum +++ b/service/grafana/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/greengrass/api_client.go b/service/greengrass/api_client.go index 5799b0b7fb9..ef401aaded4 100644 --- a/service/greengrass/api_client.go +++ b/service/greengrass/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/greengrass/endpoints.go b/service/greengrass/endpoints.go index 2841a9e71ae..0c84fb63031 100644 --- a/service/greengrass/endpoints.go +++ b/service/greengrass/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/greengrass/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GREENGRASS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Greengrass", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/greengrass/endpoints_config_test.go b/service/greengrass/endpoints_config_test.go new file mode 100644 index 00000000000..2c4c28df37d --- /dev/null +++ b/service/greengrass/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package greengrass + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrass.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrass.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + expectURL: aws.String("https://env-greengrass.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrass.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + expectURL: aws.String("http://config-greengrass.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrass.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrass.dev", + clientEndpoint: aws.String("https://client-greengrass.dev"), + expectURL: aws.String("https://client-greengrass.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GREENGRASS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/greengrass/generated.json b/service/greengrass/generated.json index d91c0e69be5..3db0f6fb90f 100644 --- a/service/greengrass/generated.json +++ b/service/greengrass/generated.json @@ -104,6 +104,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/greengrass/go.mod b/service/greengrass/go.mod index c22b962cfdc..264862ef8f3 100644 --- a/service/greengrass/go.mod +++ b/service/greengrass/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/greengrass/go.sum b/service/greengrass/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/greengrass/go.sum +++ b/service/greengrass/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/greengrassv2/api_client.go b/service/greengrassv2/api_client.go index 2bcbe7828a5..737f2d3c5af 100644 --- a/service/greengrassv2/api_client.go +++ b/service/greengrassv2/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/greengrassv2/endpoints.go b/service/greengrassv2/endpoints.go index 46e793c61a6..5620119d470 100644 --- a/service/greengrassv2/endpoints.go +++ b/service/greengrassv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/greengrassv2/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GREENGRASSV2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "GreengrassV2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/greengrassv2/endpoints_config_test.go b/service/greengrassv2/endpoints_config_test.go new file mode 100644 index 00000000000..b45f47975e0 --- /dev/null +++ b/service/greengrassv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package greengrassv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrassv2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrassv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + expectURL: aws.String("https://env-greengrassv2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrassv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + expectURL: aws.String("http://config-greengrassv2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-greengrassv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-greengrassv2.dev", + clientEndpoint: aws.String("https://client-greengrassv2.dev"), + expectURL: aws.String("https://client-greengrassv2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GREENGRASSV2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/greengrassv2/generated.json b/service/greengrassv2/generated.json index 35fba6ea3da..2fef692effe 100644 --- a/service/greengrassv2/generated.json +++ b/service/greengrassv2/generated.json @@ -41,6 +41,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/greengrassv2/go.mod b/service/greengrassv2/go.mod index 95df9160056..d830bdf7780 100644 --- a/service/greengrassv2/go.mod +++ b/service/greengrassv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/greengrassv2/go.sum b/service/greengrassv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/greengrassv2/go.sum +++ b/service/greengrassv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/groundstation/api_client.go b/service/groundstation/api_client.go index 6d6744daafe..1420425f619 100644 --- a/service/groundstation/api_client.go +++ b/service/groundstation/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/groundstation/endpoints.go b/service/groundstation/endpoints.go index 16afe537e0d..cdbaecfd233 100644 --- a/service/groundstation/endpoints.go +++ b/service/groundstation/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/groundstation/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GROUNDSTATION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "GroundStation", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/groundstation/endpoints_config_test.go b/service/groundstation/endpoints_config_test.go new file mode 100644 index 00000000000..dee5d52975d --- /dev/null +++ b/service/groundstation/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package groundstation + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-groundstation.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-groundstation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + expectURL: aws.String("https://env-groundstation.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-groundstation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + expectURL: aws.String("http://config-groundstation.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-groundstation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-groundstation.dev", + clientEndpoint: aws.String("https://client-groundstation.dev"), + expectURL: aws.String("https://client-groundstation.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GROUNDSTATION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/groundstation/generated.json b/service/groundstation/generated.json index b7536899cb5..72a873c9361 100644 --- a/service/groundstation/generated.json +++ b/service/groundstation/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/groundstation/go.mod b/service/groundstation/go.mod index dd4495085cc..1202db8e846 100644 --- a/service/groundstation/go.mod +++ b/service/groundstation/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/groundstation/go.sum b/service/groundstation/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/groundstation/go.sum +++ b/service/groundstation/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/guardduty/api_client.go b/service/guardduty/api_client.go index 87cd8bd0df8..b48f99bdcde 100644 --- a/service/guardduty/api_client.go +++ b/service/guardduty/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/guardduty/endpoints.go b/service/guardduty/endpoints.go index 373d6d9433c..31f1299a40c 100644 --- a/service/guardduty/endpoints.go +++ b/service/guardduty/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/guardduty/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_GUARDDUTY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "GuardDuty", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/guardduty/endpoints_config_test.go b/service/guardduty/endpoints_config_test.go new file mode 100644 index 00000000000..fcb29a47b4f --- /dev/null +++ b/service/guardduty/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package guardduty + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-guardduty.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-guardduty.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + expectURL: aws.String("https://env-guardduty.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-guardduty.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + expectURL: aws.String("http://config-guardduty.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-guardduty.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-guardduty.dev", + clientEndpoint: aws.String("https://client-guardduty.dev"), + expectURL: aws.String("https://client-guardduty.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_GUARDDUTY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/guardduty/generated.json b/service/guardduty/generated.json index 1b6c58bc01f..64db5c8c599 100644 --- a/service/guardduty/generated.json +++ b/service/guardduty/generated.json @@ -80,6 +80,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/guardduty/go.mod b/service/guardduty/go.mod index eb5d626b825..6f085a3a037 100644 --- a/service/guardduty/go.mod +++ b/service/guardduty/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/guardduty/go.sum b/service/guardduty/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/guardduty/go.sum +++ b/service/guardduty/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/health/api_client.go b/service/health/api_client.go index 4cdb8d44d13..fd8e0f26f11 100644 --- a/service/health/api_client.go +++ b/service/health/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/health/endpoints.go b/service/health/endpoints.go index 9733941000c..5ac13b9f3cf 100644 --- a/service/health/endpoints.go +++ b/service/health/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/health/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_HEALTH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Health", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/health/endpoints_config_test.go b/service/health/endpoints_config_test.go new file mode 100644 index 00000000000..953a86403f8 --- /dev/null +++ b/service/health/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package health + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-health.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-health.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + expectURL: aws.String("https://env-health.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-health.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + expectURL: aws.String("http://config-health.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-health.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-health.dev", + clientEndpoint: aws.String("https://client-health.dev"), + expectURL: aws.String("https://client-health.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_HEALTH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/health/generated.json b/service/health/generated.json index 1e26dc8d4ed..f2aac35af27 100644 --- a/service/health/generated.json +++ b/service/health/generated.json @@ -26,6 +26,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/health/go.mod b/service/health/go.mod index c80d5498a3e..4fdece59843 100644 --- a/service/health/go.mod +++ b/service/health/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/health/go.sum b/service/health/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/health/go.sum +++ b/service/health/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/healthlake/api_client.go b/service/healthlake/api_client.go index 4bedec486aa..0598f27e415 100644 --- a/service/healthlake/api_client.go +++ b/service/healthlake/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/healthlake/endpoints.go b/service/healthlake/endpoints.go index 5ce0904035c..8503bded452 100644 --- a/service/healthlake/endpoints.go +++ b/service/healthlake/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/healthlake/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_HEALTHLAKE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "HealthLake", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/healthlake/endpoints_config_test.go b/service/healthlake/endpoints_config_test.go new file mode 100644 index 00000000000..5737ec10555 --- /dev/null +++ b/service/healthlake/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package healthlake + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-healthlake.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-healthlake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + expectURL: aws.String("https://env-healthlake.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-healthlake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + expectURL: aws.String("http://config-healthlake.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-healthlake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-healthlake.dev", + clientEndpoint: aws.String("https://client-healthlake.dev"), + expectURL: aws.String("https://client-healthlake.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_HEALTHLAKE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/healthlake/generated.json b/service/healthlake/generated.json index e9813c68fd7..fc72af8b921 100644 --- a/service/healthlake/generated.json +++ b/service/healthlake/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/healthlake/go.mod b/service/healthlake/go.mod index dee1bb9700c..71cfa3917ec 100644 --- a/service/healthlake/go.mod +++ b/service/healthlake/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/healthlake/go.sum b/service/healthlake/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/healthlake/go.sum +++ b/service/healthlake/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/honeycode/api_client.go b/service/honeycode/api_client.go index ca1062c7a99..41a87766dda 100644 --- a/service/honeycode/api_client.go +++ b/service/honeycode/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/honeycode/endpoints.go b/service/honeycode/endpoints.go index 061ac2b2f6d..34e889394e6 100644 --- a/service/honeycode/endpoints.go +++ b/service/honeycode/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/honeycode/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_HONEYCODE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Honeycode", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/honeycode/endpoints_config_test.go b/service/honeycode/endpoints_config_test.go new file mode 100644 index 00000000000..65bf17efb33 --- /dev/null +++ b/service/honeycode/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package honeycode + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-honeycode.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-honeycode.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + expectURL: aws.String("https://env-honeycode.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-honeycode.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + expectURL: aws.String("http://config-honeycode.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-honeycode.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-honeycode.dev", + clientEndpoint: aws.String("https://client-honeycode.dev"), + expectURL: aws.String("https://client-honeycode.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_HONEYCODE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/honeycode/generated.json b/service/honeycode/generated.json index 48cf662e137..3cb7b9f2314 100644 --- a/service/honeycode/generated.json +++ b/service/honeycode/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/honeycode/go.mod b/service/honeycode/go.mod index ebe318f78a4..868fda3ea29 100644 --- a/service/honeycode/go.mod +++ b/service/honeycode/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/honeycode/go.sum b/service/honeycode/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/honeycode/go.sum +++ b/service/honeycode/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iam/api_client.go b/service/iam/api_client.go index 39e61c92137..2e2a7b77299 100644 --- a/service/iam/api_client.go +++ b/service/iam/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iam/endpoints.go b/service/iam/endpoints.go index d6b91bc2c02..ab4d0e77b41 100644 --- a/service/iam/endpoints.go +++ b/service/iam/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iam/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IAM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IAM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iam/endpoints_config_test.go b/service/iam/endpoints_config_test.go new file mode 100644 index 00000000000..c427a73b62e --- /dev/null +++ b/service/iam/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iam + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iam.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + expectURL: aws.String("https://env-iam.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + expectURL: aws.String("http://config-iam.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iam.dev", + clientEndpoint: aws.String("https://client-iam.dev"), + expectURL: aws.String("https://client-iam.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IAM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iam/generated.json b/service/iam/generated.json index 6e2babccecd..29dead3e3e7 100644 --- a/service/iam/generated.json +++ b/service/iam/generated.json @@ -171,6 +171,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iam/go.mod b/service/iam/go.mod index 2114f6e33e5..e390c58bfa6 100644 --- a/service/iam/go.mod +++ b/service/iam/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iam/go.sum b/service/iam/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iam/go.sum +++ b/service/iam/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/identitystore/api_client.go b/service/identitystore/api_client.go index 190750b9df1..97638192193 100644 --- a/service/identitystore/api_client.go +++ b/service/identitystore/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/identitystore/endpoints.go b/service/identitystore/endpoints.go index 93fe0de64d2..eac59fe5c65 100644 --- a/service/identitystore/endpoints.go +++ b/service/identitystore/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/identitystore/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IDENTITYSTORE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "identitystore", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/identitystore/endpoints_config_test.go b/service/identitystore/endpoints_config_test.go new file mode 100644 index 00000000000..142ac28a06e --- /dev/null +++ b/service/identitystore/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package identitystore + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-identitystore.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-identitystore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + expectURL: aws.String("https://env-identitystore.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-identitystore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + expectURL: aws.String("http://config-identitystore.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-identitystore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-identitystore.dev", + clientEndpoint: aws.String("https://client-identitystore.dev"), + expectURL: aws.String("https://client-identitystore.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IDENTITYSTORE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/identitystore/generated.json b/service/identitystore/generated.json index 5dc16cc4c1b..3c5a20b15df 100644 --- a/service/identitystore/generated.json +++ b/service/identitystore/generated.json @@ -33,6 +33,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/identitystore/go.mod b/service/identitystore/go.mod index d069ade8001..6dd0876d481 100644 --- a/service/identitystore/go.mod +++ b/service/identitystore/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/identitystore/go.sum b/service/identitystore/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/identitystore/go.sum +++ b/service/identitystore/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/imagebuilder/api_client.go b/service/imagebuilder/api_client.go index 80d2220c4d9..4d1f9aa1a2f 100644 --- a/service/imagebuilder/api_client.go +++ b/service/imagebuilder/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/imagebuilder/endpoints.go b/service/imagebuilder/endpoints.go index cbae1884240..a42f0229967 100644 --- a/service/imagebuilder/endpoints.go +++ b/service/imagebuilder/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/imagebuilder/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IMAGEBUILDER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "imagebuilder", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/imagebuilder/endpoints_config_test.go b/service/imagebuilder/endpoints_config_test.go new file mode 100644 index 00000000000..b4fdf9bc39d --- /dev/null +++ b/service/imagebuilder/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package imagebuilder + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-imagebuilder.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-imagebuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + expectURL: aws.String("https://env-imagebuilder.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-imagebuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + expectURL: aws.String("http://config-imagebuilder.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-imagebuilder.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-imagebuilder.dev", + clientEndpoint: aws.String("https://client-imagebuilder.dev"), + expectURL: aws.String("https://client-imagebuilder.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IMAGEBUILDER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/imagebuilder/generated.json b/service/imagebuilder/generated.json index 63f9f8602f1..523d3c80ebf 100644 --- a/service/imagebuilder/generated.json +++ b/service/imagebuilder/generated.json @@ -68,6 +68,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/imagebuilder/go.mod b/service/imagebuilder/go.mod index 6b7aab9db6e..6a3e6c9e6d4 100644 --- a/service/imagebuilder/go.mod +++ b/service/imagebuilder/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/imagebuilder/go.sum b/service/imagebuilder/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/imagebuilder/go.sum +++ b/service/imagebuilder/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/inspector/api_client.go b/service/inspector/api_client.go index 5658ddc3f11..caf103398e7 100644 --- a/service/inspector/api_client.go +++ b/service/inspector/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/inspector/endpoints.go b/service/inspector/endpoints.go index 0f346f5bf0a..a4ecdad97a4 100644 --- a/service/inspector/endpoints.go +++ b/service/inspector/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/inspector/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_INSPECTOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Inspector", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/inspector/endpoints_config_test.go b/service/inspector/endpoints_config_test.go new file mode 100644 index 00000000000..450e3ec3293 --- /dev/null +++ b/service/inspector/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package inspector + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + expectURL: aws.String("https://env-inspector.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + expectURL: aws.String("http://config-inspector.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector.dev", + clientEndpoint: aws.String("https://client-inspector.dev"), + expectURL: aws.String("https://client-inspector.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_INSPECTOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/inspector/generated.json b/service/inspector/generated.json index f4ec5bb737d..bed77a4e99c 100644 --- a/service/inspector/generated.json +++ b/service/inspector/generated.json @@ -49,6 +49,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/inspector/go.mod b/service/inspector/go.mod index babf65cbe09..ed8f911c340 100644 --- a/service/inspector/go.mod +++ b/service/inspector/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/inspector/go.sum b/service/inspector/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/inspector/go.sum +++ b/service/inspector/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/inspector2/api_client.go b/service/inspector2/api_client.go index 6ce998bf675..31a80108cae 100644 --- a/service/inspector2/api_client.go +++ b/service/inspector2/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/inspector2/endpoints.go b/service/inspector2/endpoints.go index f6eb6af8f17..1add4536b45 100644 --- a/service/inspector2/endpoints.go +++ b/service/inspector2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/inspector2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_INSPECTOR2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Inspector2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/inspector2/endpoints_config_test.go b/service/inspector2/endpoints_config_test.go new file mode 100644 index 00000000000..11059bafca4 --- /dev/null +++ b/service/inspector2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package inspector2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + expectURL: aws.String("https://env-inspector2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + expectURL: aws.String("http://config-inspector2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-inspector2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-inspector2.dev", + clientEndpoint: aws.String("https://client-inspector2.dev"), + expectURL: aws.String("https://client-inspector2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_INSPECTOR2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/inspector2/generated.json b/service/inspector2/generated.json index 768aff79412..4773b8d9dd9 100644 --- a/service/inspector2/generated.json +++ b/service/inspector2/generated.json @@ -58,6 +58,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/inspector2/go.mod b/service/inspector2/go.mod index 814eb5a4df2..20af5f8c0e7 100644 --- a/service/inspector2/go.mod +++ b/service/inspector2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/inspector2/go.sum b/service/inspector2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/inspector2/go.sum +++ b/service/inspector2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/internal/benchmark/go.mod b/service/internal/benchmark/go.mod index c56e0d49fb9..a84c2557efb 100644 --- a/service/internal/benchmark/go.mod +++ b/service/internal/benchmark/go.mod @@ -16,10 +16,20 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/v4a => ../../../internal/v4a/ replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/ @@ -39,3 +49,9 @@ replace github.com/aws/aws-sdk-go-v2/service/lexruntimeservice => ../../../servi replace github.com/aws/aws-sdk-go-v2/service/s3 => ../../../service/s3/ replace github.com/aws/aws-sdk-go-v2/service/schemas => ../../../service/schemas/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../../service/sts/ diff --git a/service/internal/eventstreamtesting/go.mod b/service/internal/eventstreamtesting/go.mod index f54f110a15a..d45034ee43c 100644 --- a/service/internal/eventstreamtesting/go.mod +++ b/service/internal/eventstreamtesting/go.mod @@ -13,14 +13,20 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ + replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/sso => ../../../service/sso/ diff --git a/service/internal/eventstreamtesting/go.sum b/service/internal/eventstreamtesting/go.sum index 0b535230803..dbda5ff858e 100644 --- a/service/internal/eventstreamtesting/go.sum +++ b/service/internal/eventstreamtesting/go.sum @@ -1,3 +1,6 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/internal/integrationtest/go.mod b/service/internal/integrationtest/go.mod index 0dc2bb7ab1b..6c540b61c0e 100644 --- a/service/internal/integrationtest/go.mod +++ b/service/internal/integrationtest/go.mod @@ -103,6 +103,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/im replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ diff --git a/service/internetmonitor/api_client.go b/service/internetmonitor/api_client.go index d83c236f7bf..f12011df8d4 100644 --- a/service/internetmonitor/api_client.go +++ b/service/internetmonitor/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/internetmonitor/endpoints.go b/service/internetmonitor/endpoints.go index 53ac31e9801..840e8c51663 100644 --- a/service/internetmonitor/endpoints.go +++ b/service/internetmonitor/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/internetmonitor/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_INTERNETMONITOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "InternetMonitor", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/internetmonitor/endpoints_config_test.go b/service/internetmonitor/endpoints_config_test.go new file mode 100644 index 00000000000..8b520173482 --- /dev/null +++ b/service/internetmonitor/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package internetmonitor + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-internetmonitor.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-internetmonitor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + expectURL: aws.String("https://env-internetmonitor.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-internetmonitor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + expectURL: aws.String("http://config-internetmonitor.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-internetmonitor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-internetmonitor.dev", + clientEndpoint: aws.String("https://client-internetmonitor.dev"), + expectURL: aws.String("https://client-internetmonitor.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_INTERNETMONITOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/internetmonitor/generated.json b/service/internetmonitor/generated.json index f5f73e20d8e..e1b5ff57a1f 100644 --- a/service/internetmonitor/generated.json +++ b/service/internetmonitor/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/internetmonitor/go.mod b/service/internetmonitor/go.mod index 96377cbdd03..60251107f9a 100644 --- a/service/internetmonitor/go.mod +++ b/service/internetmonitor/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/internetmonitor/go.sum b/service/internetmonitor/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/internetmonitor/go.sum +++ b/service/internetmonitor/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iot/api_client.go b/service/iot/api_client.go index b3c580f22bf..f5ccbf23304 100644 --- a/service/iot/api_client.go +++ b/service/iot/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iot/endpoints.go b/service/iot/endpoints.go index ce27f89d6f6..d9647d0fdfe 100644 --- a/service/iot/endpoints.go +++ b/service/iot/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iot/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iot/endpoints_config_test.go b/service/iot/endpoints_config_test.go new file mode 100644 index 00000000000..b9e70280e22 --- /dev/null +++ b/service/iot/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iot + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + expectURL: aws.String("https://env-iot.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + expectURL: aws.String("http://config-iot.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot.dev", + clientEndpoint: aws.String("https://client-iot.dev"), + expectURL: aws.String("https://client-iot.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iot/generated.json b/service/iot/generated.json index b821f9dcbc0..f2bf3ec9822 100644 --- a/service/iot/generated.json +++ b/service/iot/generated.json @@ -262,6 +262,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iot/go.mod b/service/iot/go.mod index 2b22a98e324..08109fee757 100644 --- a/service/iot/go.mod +++ b/service/iot/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iot/go.sum b/service/iot/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iot/go.sum +++ b/service/iot/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iot1clickdevicesservice/api_client.go b/service/iot1clickdevicesservice/api_client.go index e8b13405939..e166296473a 100644 --- a/service/iot1clickdevicesservice/api_client.go +++ b/service/iot1clickdevicesservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iot1clickdevicesservice/endpoints.go b/service/iot1clickdevicesservice/endpoints.go index 55dd30034de..03283fec933 100644 --- a/service/iot1clickdevicesservice/endpoints.go +++ b/service/iot1clickdevicesservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iot1clickdevicesservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_1CLICK_DEVICES_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT 1Click Devices Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iot1clickdevicesservice/endpoints_config_test.go b/service/iot1clickdevicesservice/endpoints_config_test.go new file mode 100644 index 00000000000..59dedc27efd --- /dev/null +++ b/service/iot1clickdevicesservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iot1clickdevicesservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-devices-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-devices-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + expectURL: aws.String("https://env-iot-1click-devices-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-devices-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + expectURL: aws.String("http://config-iot-1click-devices-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-devices-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-devices-service.dev", + clientEndpoint: aws.String("https://client-iot-1click-devices-service.dev"), + expectURL: aws.String("https://client-iot-1click-devices-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_1CLICK_DEVICES_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iot1clickdevicesservice/generated.json b/service/iot1clickdevicesservice/generated.json index 87008c3044c..be1384c946a 100644 --- a/service/iot1clickdevicesservice/generated.json +++ b/service/iot1clickdevicesservice/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iot1clickdevicesservice/go.mod b/service/iot1clickdevicesservice/go.mod index 25e750d6982..e6a380f7282 100644 --- a/service/iot1clickdevicesservice/go.mod +++ b/service/iot1clickdevicesservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iot1clickdevicesservice/go.sum b/service/iot1clickdevicesservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iot1clickdevicesservice/go.sum +++ b/service/iot1clickdevicesservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iot1clickprojects/api_client.go b/service/iot1clickprojects/api_client.go index 2aff1a0f97d..488ac625f1b 100644 --- a/service/iot1clickprojects/api_client.go +++ b/service/iot1clickprojects/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iot1clickprojects/endpoints.go b/service/iot1clickprojects/endpoints.go index 9d8b3c0de05..f69cf69bf57 100644 --- a/service/iot1clickprojects/endpoints.go +++ b/service/iot1clickprojects/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iot1clickprojects/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_1CLICK_PROJECTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT 1Click Projects", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iot1clickprojects/endpoints_config_test.go b/service/iot1clickprojects/endpoints_config_test.go new file mode 100644 index 00000000000..0fad2be145a --- /dev/null +++ b/service/iot1clickprojects/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iot1clickprojects + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-projects.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-projects.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + expectURL: aws.String("https://env-iot-1click-projects.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-projects.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + expectURL: aws.String("http://config-iot-1click-projects.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-1click-projects.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-1click-projects.dev", + clientEndpoint: aws.String("https://client-iot-1click-projects.dev"), + expectURL: aws.String("https://client-iot-1click-projects.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_1CLICK_PROJECTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iot1clickprojects/generated.json b/service/iot1clickprojects/generated.json index 8a57ad6d3d9..2ede1aa2ea6 100644 --- a/service/iot1clickprojects/generated.json +++ b/service/iot1clickprojects/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iot1clickprojects/go.mod b/service/iot1clickprojects/go.mod index e9b252f70d2..8d4b9eef9b0 100644 --- a/service/iot1clickprojects/go.mod +++ b/service/iot1clickprojects/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iot1clickprojects/go.sum b/service/iot1clickprojects/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iot1clickprojects/go.sum +++ b/service/iot1clickprojects/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotanalytics/api_client.go b/service/iotanalytics/api_client.go index 5724a8d7050..6703b7030b8 100644 --- a/service/iotanalytics/api_client.go +++ b/service/iotanalytics/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotanalytics/endpoints.go b/service/iotanalytics/endpoints.go index c9dd38a46ed..19d4f8d47c3 100644 --- a/service/iotanalytics/endpoints.go +++ b/service/iotanalytics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotanalytics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTANALYTICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTAnalytics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotanalytics/endpoints_config_test.go b/service/iotanalytics/endpoints_config_test.go new file mode 100644 index 00000000000..a45958b3f40 --- /dev/null +++ b/service/iotanalytics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotanalytics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotanalytics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotanalytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + expectURL: aws.String("https://env-iotanalytics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotanalytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + expectURL: aws.String("http://config-iotanalytics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotanalytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotanalytics.dev", + clientEndpoint: aws.String("https://client-iotanalytics.dev"), + expectURL: aws.String("https://client-iotanalytics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTANALYTICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotanalytics/generated.json b/service/iotanalytics/generated.json index 2806ad6a8cc..91da436f905 100644 --- a/service/iotanalytics/generated.json +++ b/service/iotanalytics/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotanalytics/go.mod b/service/iotanalytics/go.mod index d690788bd30..14a337eb366 100644 --- a/service/iotanalytics/go.mod +++ b/service/iotanalytics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotanalytics/go.sum b/service/iotanalytics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotanalytics/go.sum +++ b/service/iotanalytics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotdataplane/api_client.go b/service/iotdataplane/api_client.go index dcd3ecd1238..ec1ee4315cf 100644 --- a/service/iotdataplane/api_client.go +++ b/service/iotdataplane/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotdataplane/endpoints.go b/service/iotdataplane/endpoints.go index 30d086dc368..cf7e335e8d8 100644 --- a/service/iotdataplane/endpoints.go +++ b/service/iotdataplane/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotdataplane/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_DATA_PLANE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT Data Plane", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotdataplane/endpoints_config_test.go b/service/iotdataplane/endpoints_config_test.go new file mode 100644 index 00000000000..6e1811507c6 --- /dev/null +++ b/service/iotdataplane/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotdataplane + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-data-plane.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + expectURL: aws.String("https://env-iot-data-plane.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + expectURL: aws.String("http://config-iot-data-plane.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-data-plane.dev", + clientEndpoint: aws.String("https://client-iot-data-plane.dev"), + expectURL: aws.String("https://client-iot-data-plane.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_DATA_PLANE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotdataplane/generated.json b/service/iotdataplane/generated.json index 5ce944a7092..16b76f58694 100644 --- a/service/iotdataplane/generated.json +++ b/service/iotdataplane/generated.json @@ -19,6 +19,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotdataplane/go.mod b/service/iotdataplane/go.mod index 57816a75af6..2434b80aadb 100644 --- a/service/iotdataplane/go.mod +++ b/service/iotdataplane/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotdataplane/go.sum b/service/iotdataplane/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotdataplane/go.sum +++ b/service/iotdataplane/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotdeviceadvisor/api_client.go b/service/iotdeviceadvisor/api_client.go index 03509e7b268..62af0b359d4 100644 --- a/service/iotdeviceadvisor/api_client.go +++ b/service/iotdeviceadvisor/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotdeviceadvisor/endpoints.go b/service/iotdeviceadvisor/endpoints.go index bcbd86e8683..a1255c07a0a 100644 --- a/service/iotdeviceadvisor/endpoints.go +++ b/service/iotdeviceadvisor/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotdeviceadvisor/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTDEVICEADVISOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IotDeviceAdvisor", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotdeviceadvisor/endpoints_config_test.go b/service/iotdeviceadvisor/endpoints_config_test.go new file mode 100644 index 00000000000..6522d6a6fca --- /dev/null +++ b/service/iotdeviceadvisor/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotdeviceadvisor + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotdeviceadvisor.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotdeviceadvisor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + expectURL: aws.String("https://env-iotdeviceadvisor.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotdeviceadvisor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + expectURL: aws.String("http://config-iotdeviceadvisor.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotdeviceadvisor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotdeviceadvisor.dev", + clientEndpoint: aws.String("https://client-iotdeviceadvisor.dev"), + expectURL: aws.String("https://client-iotdeviceadvisor.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTDEVICEADVISOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotdeviceadvisor/generated.json b/service/iotdeviceadvisor/generated.json index 27131570109..296f7e38d9a 100644 --- a/service/iotdeviceadvisor/generated.json +++ b/service/iotdeviceadvisor/generated.json @@ -26,6 +26,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotdeviceadvisor/go.mod b/service/iotdeviceadvisor/go.mod index 2e03adf007a..634248ffea9 100644 --- a/service/iotdeviceadvisor/go.mod +++ b/service/iotdeviceadvisor/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotdeviceadvisor/go.sum b/service/iotdeviceadvisor/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotdeviceadvisor/go.sum +++ b/service/iotdeviceadvisor/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotevents/api_client.go b/service/iotevents/api_client.go index 1703d622cfe..2753a0d4828 100644 --- a/service/iotevents/api_client.go +++ b/service/iotevents/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotevents/endpoints.go b/service/iotevents/endpoints.go index 2da30b7aa05..9a5998b394d 100644 --- a/service/iotevents/endpoints.go +++ b/service/iotevents/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotevents/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_EVENTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT Events", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotevents/endpoints_config_test.go b/service/iotevents/endpoints_config_test.go new file mode 100644 index 00000000000..8ba64183b21 --- /dev/null +++ b/service/iotevents/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotevents + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + expectURL: aws.String("https://env-iot-events.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + expectURL: aws.String("http://config-iot-events.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events.dev", + clientEndpoint: aws.String("https://client-iot-events.dev"), + expectURL: aws.String("https://client-iot-events.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_EVENTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotevents/generated.json b/service/iotevents/generated.json index 5e8eae4c5a5..6f9879371e9 100644 --- a/service/iotevents/generated.json +++ b/service/iotevents/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotevents/go.mod b/service/iotevents/go.mod index d46bedc4224..2e703419ae3 100644 --- a/service/iotevents/go.mod +++ b/service/iotevents/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotevents/go.sum b/service/iotevents/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotevents/go.sum +++ b/service/iotevents/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ioteventsdata/api_client.go b/service/ioteventsdata/api_client.go index 06115ddb312..c0c1cb5e4f5 100644 --- a/service/ioteventsdata/api_client.go +++ b/service/ioteventsdata/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ioteventsdata/endpoints.go b/service/ioteventsdata/endpoints.go index fa7a7a6d416..ae12542b44e 100644 --- a/service/ioteventsdata/endpoints.go +++ b/service/ioteventsdata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ioteventsdata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_EVENTS_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT Events Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ioteventsdata/endpoints_config_test.go b/service/ioteventsdata/endpoints_config_test.go new file mode 100644 index 00000000000..4a26f6c78b5 --- /dev/null +++ b/service/ioteventsdata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ioteventsdata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + expectURL: aws.String("https://env-iot-events-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + expectURL: aws.String("http://config-iot-events-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-events-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-events-data.dev", + clientEndpoint: aws.String("https://client-iot-events-data.dev"), + expectURL: aws.String("https://client-iot-events-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_EVENTS_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ioteventsdata/generated.json b/service/ioteventsdata/generated.json index beca05ddd99..c415eb2a804 100644 --- a/service/ioteventsdata/generated.json +++ b/service/ioteventsdata/generated.json @@ -24,6 +24,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ioteventsdata/go.mod b/service/ioteventsdata/go.mod index 58b0a29d98b..7cc9874a102 100644 --- a/service/ioteventsdata/go.mod +++ b/service/ioteventsdata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ioteventsdata/go.sum b/service/ioteventsdata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ioteventsdata/go.sum +++ b/service/ioteventsdata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotfleethub/api_client.go b/service/iotfleethub/api_client.go index bd6e3920bb6..fe9dc59c80e 100644 --- a/service/iotfleethub/api_client.go +++ b/service/iotfleethub/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotfleethub/endpoints.go b/service/iotfleethub/endpoints.go index 70cf8804bac..e608785e836 100644 --- a/service/iotfleethub/endpoints.go +++ b/service/iotfleethub/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotfleethub/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTFLEETHUB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTFleetHub", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotfleethub/endpoints_config_test.go b/service/iotfleethub/endpoints_config_test.go new file mode 100644 index 00000000000..90210c42470 --- /dev/null +++ b/service/iotfleethub/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotfleethub + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleethub.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleethub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + expectURL: aws.String("https://env-iotfleethub.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleethub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + expectURL: aws.String("http://config-iotfleethub.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleethub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleethub.dev", + clientEndpoint: aws.String("https://client-iotfleethub.dev"), + expectURL: aws.String("https://client-iotfleethub.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTFLEETHUB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotfleethub/generated.json b/service/iotfleethub/generated.json index 5c49a1908cf..55cfee35495 100644 --- a/service/iotfleethub/generated.json +++ b/service/iotfleethub/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotfleethub/go.mod b/service/iotfleethub/go.mod index 65827282b0a..e9115a9e9c0 100644 --- a/service/iotfleethub/go.mod +++ b/service/iotfleethub/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotfleethub/go.sum b/service/iotfleethub/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotfleethub/go.sum +++ b/service/iotfleethub/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotfleetwise/api_client.go b/service/iotfleetwise/api_client.go index 0f385c0768c..023f683aad4 100644 --- a/service/iotfleetwise/api_client.go +++ b/service/iotfleetwise/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotfleetwise/endpoints.go b/service/iotfleetwise/endpoints.go index f864c7caa41..fedc17663c3 100644 --- a/service/iotfleetwise/endpoints.go +++ b/service/iotfleetwise/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotfleetwise/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTFLEETWISE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTFleetWise", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotfleetwise/endpoints_config_test.go b/service/iotfleetwise/endpoints_config_test.go new file mode 100644 index 00000000000..aff50669ef2 --- /dev/null +++ b/service/iotfleetwise/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotfleetwise + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleetwise.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleetwise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + expectURL: aws.String("https://env-iotfleetwise.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleetwise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + expectURL: aws.String("http://config-iotfleetwise.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotfleetwise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotfleetwise.dev", + clientEndpoint: aws.String("https://client-iotfleetwise.dev"), + expectURL: aws.String("https://client-iotfleetwise.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTFLEETWISE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotfleetwise/generated.json b/service/iotfleetwise/generated.json index 17d49dc3916..78e73468706 100644 --- a/service/iotfleetwise/generated.json +++ b/service/iotfleetwise/generated.json @@ -64,6 +64,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotfleetwise/go.mod b/service/iotfleetwise/go.mod index fa0ae4718d7..8602f392f6b 100644 --- a/service/iotfleetwise/go.mod +++ b/service/iotfleetwise/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotfleetwise/go.sum b/service/iotfleetwise/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotfleetwise/go.sum +++ b/service/iotfleetwise/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotjobsdataplane/api_client.go b/service/iotjobsdataplane/api_client.go index 7ed9d3d77e7..fe459802c0a 100644 --- a/service/iotjobsdataplane/api_client.go +++ b/service/iotjobsdataplane/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotjobsdataplane/endpoints.go b/service/iotjobsdataplane/endpoints.go index 481fd3a089b..fc4897811be 100644 --- a/service/iotjobsdataplane/endpoints.go +++ b/service/iotjobsdataplane/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotjobsdataplane/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_JOBS_DATA_PLANE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT Jobs Data Plane", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotjobsdataplane/endpoints_config_test.go b/service/iotjobsdataplane/endpoints_config_test.go new file mode 100644 index 00000000000..7c020164c9a --- /dev/null +++ b/service/iotjobsdataplane/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotjobsdataplane + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-jobs-data-plane.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-jobs-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + expectURL: aws.String("https://env-iot-jobs-data-plane.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-jobs-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + expectURL: aws.String("http://config-iot-jobs-data-plane.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-jobs-data-plane.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-jobs-data-plane.dev", + clientEndpoint: aws.String("https://client-iot-jobs-data-plane.dev"), + expectURL: aws.String("https://client-iot-jobs-data-plane.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_JOBS_DATA_PLANE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotjobsdataplane/generated.json b/service/iotjobsdataplane/generated.json index 6cd614e6909..800de633d84 100644 --- a/service/iotjobsdataplane/generated.json +++ b/service/iotjobsdataplane/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotjobsdataplane/go.mod b/service/iotjobsdataplane/go.mod index 96ada393afc..106280ae8d4 100644 --- a/service/iotjobsdataplane/go.mod +++ b/service/iotjobsdataplane/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotjobsdataplane/go.sum b/service/iotjobsdataplane/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotjobsdataplane/go.sum +++ b/service/iotjobsdataplane/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotroborunner/api_client.go b/service/iotroborunner/api_client.go index 28992c2f20d..bb640b36afb 100644 --- a/service/iotroborunner/api_client.go +++ b/service/iotroborunner/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotroborunner/endpoints.go b/service/iotroborunner/endpoints.go index dcfa73cc17e..b66a68b696f 100644 --- a/service/iotroborunner/endpoints.go +++ b/service/iotroborunner/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotroborunner/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_ROBORUNNER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT RoboRunner", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotroborunner/endpoints_config_test.go b/service/iotroborunner/endpoints_config_test.go new file mode 100644 index 00000000000..e8dd0f41eee --- /dev/null +++ b/service/iotroborunner/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotroborunner + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-roborunner.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-roborunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + expectURL: aws.String("https://env-iot-roborunner.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-roborunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + expectURL: aws.String("http://config-iot-roborunner.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-roborunner.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-roborunner.dev", + clientEndpoint: aws.String("https://client-iot-roborunner.dev"), + expectURL: aws.String("https://client-iot-roborunner.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_ROBORUNNER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotroborunner/generated.json b/service/iotroborunner/generated.json index d0e360fc72f..aab8e7d2d40 100644 --- a/service/iotroborunner/generated.json +++ b/service/iotroborunner/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotroborunner/go.mod b/service/iotroborunner/go.mod index b3cbb7d9e32..d5944369807 100644 --- a/service/iotroborunner/go.mod +++ b/service/iotroborunner/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotroborunner/go.sum b/service/iotroborunner/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotroborunner/go.sum +++ b/service/iotroborunner/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotsecuretunneling/api_client.go b/service/iotsecuretunneling/api_client.go index be3de58d55a..34cbe0d2a3c 100644 --- a/service/iotsecuretunneling/api_client.go +++ b/service/iotsecuretunneling/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotsecuretunneling/endpoints.go b/service/iotsecuretunneling/endpoints.go index 431c94f4cce..fac53ab34ad 100644 --- a/service/iotsecuretunneling/endpoints.go +++ b/service/iotsecuretunneling/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotsecuretunneling/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTSECURETUNNELING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTSecureTunneling", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotsecuretunneling/endpoints_config_test.go b/service/iotsecuretunneling/endpoints_config_test.go new file mode 100644 index 00000000000..8c08eb8fa75 --- /dev/null +++ b/service/iotsecuretunneling/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotsecuretunneling + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsecuretunneling.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsecuretunneling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + expectURL: aws.String("https://env-iotsecuretunneling.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsecuretunneling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + expectURL: aws.String("http://config-iotsecuretunneling.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsecuretunneling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsecuretunneling.dev", + clientEndpoint: aws.String("https://client-iotsecuretunneling.dev"), + expectURL: aws.String("https://client-iotsecuretunneling.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTSECURETUNNELING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotsecuretunneling/generated.json b/service/iotsecuretunneling/generated.json index 32536e03d06..d69171fe064 100644 --- a/service/iotsecuretunneling/generated.json +++ b/service/iotsecuretunneling/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotsecuretunneling/go.mod b/service/iotsecuretunneling/go.mod index 219aee308ee..8bd4f1fd089 100644 --- a/service/iotsecuretunneling/go.mod +++ b/service/iotsecuretunneling/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotsecuretunneling/go.sum b/service/iotsecuretunneling/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotsecuretunneling/go.sum +++ b/service/iotsecuretunneling/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotsitewise/api_client.go b/service/iotsitewise/api_client.go index 7ab90e07ee8..244aeacc1ef 100644 --- a/service/iotsitewise/api_client.go +++ b/service/iotsitewise/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotsitewise/endpoints.go b/service/iotsitewise/endpoints.go index f5b5cff3b2a..448738a9643 100644 --- a/service/iotsitewise/endpoints.go +++ b/service/iotsitewise/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotsitewise/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTSITEWISE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTSiteWise", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotsitewise/endpoints_config_test.go b/service/iotsitewise/endpoints_config_test.go new file mode 100644 index 00000000000..1ebda63c37e --- /dev/null +++ b/service/iotsitewise/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotsitewise + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsitewise.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsitewise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + expectURL: aws.String("https://env-iotsitewise.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsitewise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + expectURL: aws.String("http://config-iotsitewise.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotsitewise.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotsitewise.dev", + clientEndpoint: aws.String("https://client-iotsitewise.dev"), + expectURL: aws.String("https://client-iotsitewise.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTSITEWISE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotsitewise/generated.json b/service/iotsitewise/generated.json index f6c16adaef0..a28c9ac6d14 100644 --- a/service/iotsitewise/generated.json +++ b/service/iotsitewise/generated.json @@ -86,6 +86,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotsitewise/go.mod b/service/iotsitewise/go.mod index 2eb5bdb1823..1c8052ce217 100644 --- a/service/iotsitewise/go.mod +++ b/service/iotsitewise/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotsitewise/go.sum b/service/iotsitewise/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/iotsitewise/go.sum +++ b/service/iotsitewise/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/iotthingsgraph/api_client.go b/service/iotthingsgraph/api_client.go index 8c8dda6c9fb..d3bddcd0857 100644 --- a/service/iotthingsgraph/api_client.go +++ b/service/iotthingsgraph/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotthingsgraph/endpoints.go b/service/iotthingsgraph/endpoints.go index 8626b866042..e3554a1dc60 100644 --- a/service/iotthingsgraph/endpoints.go +++ b/service/iotthingsgraph/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotthingsgraph/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTTHINGSGRAPH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTThingsGraph", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotthingsgraph/endpoints_config_test.go b/service/iotthingsgraph/endpoints_config_test.go new file mode 100644 index 00000000000..6595856c000 --- /dev/null +++ b/service/iotthingsgraph/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotthingsgraph + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotthingsgraph.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotthingsgraph.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + expectURL: aws.String("https://env-iotthingsgraph.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotthingsgraph.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + expectURL: aws.String("http://config-iotthingsgraph.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iotthingsgraph.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iotthingsgraph.dev", + clientEndpoint: aws.String("https://client-iotthingsgraph.dev"), + expectURL: aws.String("https://client-iotthingsgraph.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTTHINGSGRAPH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotthingsgraph/generated.json b/service/iotthingsgraph/generated.json index 3a90b5be9f3..6d5594cfd54 100644 --- a/service/iotthingsgraph/generated.json +++ b/service/iotthingsgraph/generated.json @@ -47,6 +47,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotthingsgraph/go.mod b/service/iotthingsgraph/go.mod index 470f402b6ff..7ae9ab8402b 100644 --- a/service/iotthingsgraph/go.mod +++ b/service/iotthingsgraph/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotthingsgraph/go.sum b/service/iotthingsgraph/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotthingsgraph/go.sum +++ b/service/iotthingsgraph/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iottwinmaker/api_client.go b/service/iottwinmaker/api_client.go index 1a1c7e6789c..ba6955f86f6 100644 --- a/service/iottwinmaker/api_client.go +++ b/service/iottwinmaker/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iottwinmaker/endpoints.go b/service/iottwinmaker/endpoints.go index 5076f219db2..2157e240866 100644 --- a/service/iottwinmaker/endpoints.go +++ b/service/iottwinmaker/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iottwinmaker/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOTTWINMAKER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoTTwinMaker", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iottwinmaker/endpoints_config_test.go b/service/iottwinmaker/endpoints_config_test.go new file mode 100644 index 00000000000..f0615a0486c --- /dev/null +++ b/service/iottwinmaker/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iottwinmaker + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iottwinmaker.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iottwinmaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + expectURL: aws.String("https://env-iottwinmaker.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iottwinmaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + expectURL: aws.String("http://config-iottwinmaker.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iottwinmaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iottwinmaker.dev", + clientEndpoint: aws.String("https://client-iottwinmaker.dev"), + expectURL: aws.String("https://client-iottwinmaker.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOTTWINMAKER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iottwinmaker/generated.json b/service/iottwinmaker/generated.json index 6b68fc2280a..5a446f6f4ad 100644 --- a/service/iottwinmaker/generated.json +++ b/service/iottwinmaker/generated.json @@ -48,6 +48,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/iottwinmaker/go.mod b/service/iottwinmaker/go.mod index 9b350cbff60..67b884a8a9a 100644 --- a/service/iottwinmaker/go.mod +++ b/service/iottwinmaker/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iottwinmaker/go.sum b/service/iottwinmaker/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iottwinmaker/go.sum +++ b/service/iottwinmaker/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/iotwireless/api_client.go b/service/iotwireless/api_client.go index 2ba6144b8dc..e0a665f359f 100644 --- a/service/iotwireless/api_client.go +++ b/service/iotwireless/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/iotwireless/endpoints.go b/service/iotwireless/endpoints.go index bc63f638359..283f0fc79c0 100644 --- a/service/iotwireless/endpoints.go +++ b/service/iotwireless/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/iotwireless/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IOT_WIRELESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IoT Wireless", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/iotwireless/endpoints_config_test.go b/service/iotwireless/endpoints_config_test.go new file mode 100644 index 00000000000..76573238b6a --- /dev/null +++ b/service/iotwireless/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package iotwireless + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-wireless.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-wireless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + expectURL: aws.String("https://env-iot-wireless.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-wireless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + expectURL: aws.String("http://config-iot-wireless.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-iot-wireless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-iot-wireless.dev", + clientEndpoint: aws.String("https://client-iot-wireless.dev"), + expectURL: aws.String("https://client-iot-wireless.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IOT_WIRELESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/iotwireless/generated.json b/service/iotwireless/generated.json index 24884ceb4ba..5e7795ae236 100644 --- a/service/iotwireless/generated.json +++ b/service/iotwireless/generated.json @@ -121,6 +121,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/iotwireless/go.mod b/service/iotwireless/go.mod index 6853c095055..e135f2d2ef4 100644 --- a/service/iotwireless/go.mod +++ b/service/iotwireless/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/iotwireless/go.sum b/service/iotwireless/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/iotwireless/go.sum +++ b/service/iotwireless/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ivs/api_client.go b/service/ivs/api_client.go index c6b9848cd54..235f42a3209 100644 --- a/service/ivs/api_client.go +++ b/service/ivs/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ivs/endpoints.go b/service/ivs/endpoints.go index 6bc65ebd05d..2875f57dd28 100644 --- a/service/ivs/endpoints.go +++ b/service/ivs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ivs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IVS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ivs", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ivs/endpoints_config_test.go b/service/ivs/endpoints_config_test.go new file mode 100644 index 00000000000..abf39f9edd7 --- /dev/null +++ b/service/ivs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ivs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + expectURL: aws.String("https://env-ivs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + expectURL: aws.String("http://config-ivs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs.dev", + clientEndpoint: aws.String("https://client-ivs.dev"), + expectURL: aws.String("https://client-ivs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IVS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ivs/generated.json b/service/ivs/generated.json index c4605d18c95..163b644f63e 100644 --- a/service/ivs/generated.json +++ b/service/ivs/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ivs/go.mod b/service/ivs/go.mod index 8b49be05f0e..1b23aaf9c92 100644 --- a/service/ivs/go.mod +++ b/service/ivs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ivs/go.sum b/service/ivs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ivs/go.sum +++ b/service/ivs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ivschat/api_client.go b/service/ivschat/api_client.go index 1bff9a33f11..3551db82386 100644 --- a/service/ivschat/api_client.go +++ b/service/ivschat/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ivschat/endpoints.go b/service/ivschat/endpoints.go index 5caf4adbee2..e68d4fa1a0a 100644 --- a/service/ivschat/endpoints.go +++ b/service/ivschat/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ivschat/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IVSCHAT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ivschat", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ivschat/endpoints_config_test.go b/service/ivschat/endpoints_config_test.go new file mode 100644 index 00000000000..a7c0ab67947 --- /dev/null +++ b/service/ivschat/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ivschat + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivschat.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivschat.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + expectURL: aws.String("https://env-ivschat.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivschat.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + expectURL: aws.String("http://config-ivschat.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivschat.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivschat.dev", + clientEndpoint: aws.String("https://client-ivschat.dev"), + expectURL: aws.String("https://client-ivschat.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IVSCHAT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ivschat/generated.json b/service/ivschat/generated.json index 9beeb7e2708..4ca60dd9cad 100644 --- a/service/ivschat/generated.json +++ b/service/ivschat/generated.json @@ -29,6 +29,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ivschat/go.mod b/service/ivschat/go.mod index c80ea2b8081..3fe47ffd745 100644 --- a/service/ivschat/go.mod +++ b/service/ivschat/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ivschat/go.sum b/service/ivschat/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ivschat/go.sum +++ b/service/ivschat/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ivsrealtime/api_client.go b/service/ivsrealtime/api_client.go index 5c4cdfc0bb0..85012f37b88 100644 --- a/service/ivsrealtime/api_client.go +++ b/service/ivsrealtime/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ivsrealtime/endpoints.go b/service/ivsrealtime/endpoints.go index 78285cf2e71..22becc7ea76 100644 --- a/service/ivsrealtime/endpoints.go +++ b/service/ivsrealtime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ivsrealtime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_IVS_REALTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "IVS RealTime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ivsrealtime/endpoints_config_test.go b/service/ivsrealtime/endpoints_config_test.go new file mode 100644 index 00000000000..d7408db5543 --- /dev/null +++ b/service/ivsrealtime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ivsrealtime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs-realtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs-realtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + expectURL: aws.String("https://env-ivs-realtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs-realtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + expectURL: aws.String("http://config-ivs-realtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ivs-realtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ivs-realtime.dev", + clientEndpoint: aws.String("https://client-ivs-realtime.dev"), + expectURL: aws.String("https://client-ivs-realtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_IVS_REALTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ivsrealtime/generated.json b/service/ivsrealtime/generated.json index 327c58aea84..a867f67e745 100644 --- a/service/ivsrealtime/generated.json +++ b/service/ivsrealtime/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ivsrealtime/go.mod b/service/ivsrealtime/go.mod index 63c216ae20d..8b73e2c94d4 100644 --- a/service/ivsrealtime/go.mod +++ b/service/ivsrealtime/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ivsrealtime/go.sum b/service/ivsrealtime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ivsrealtime/go.sum +++ b/service/ivsrealtime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kafka/api_client.go b/service/kafka/api_client.go index 8c3dfe449f8..45393dae33f 100644 --- a/service/kafka/api_client.go +++ b/service/kafka/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kafka/endpoints.go b/service/kafka/endpoints.go index 30a021a687a..e747032a6bb 100644 --- a/service/kafka/endpoints.go +++ b/service/kafka/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kafka/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KAFKA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kafka", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kafka/endpoints_config_test.go b/service/kafka/endpoints_config_test.go new file mode 100644 index 00000000000..c45ac1f39fa --- /dev/null +++ b/service/kafka/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kafka + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafka.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafka.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + expectURL: aws.String("https://env-kafka.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafka.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + expectURL: aws.String("http://config-kafka.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafka.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafka.dev", + clientEndpoint: aws.String("https://client-kafka.dev"), + expectURL: aws.String("https://client-kafka.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KAFKA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kafka/generated.json b/service/kafka/generated.json index 20ecb24dc5d..af31a0629e1 100644 --- a/service/kafka/generated.json +++ b/service/kafka/generated.json @@ -64,6 +64,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kafka/go.mod b/service/kafka/go.mod index 88cb0fba27a..8d2b4807c93 100644 --- a/service/kafka/go.mod +++ b/service/kafka/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kafka/go.sum b/service/kafka/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kafka/go.sum +++ b/service/kafka/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kafkaconnect/api_client.go b/service/kafkaconnect/api_client.go index b5bedf532cb..c41b8dc9a29 100644 --- a/service/kafkaconnect/api_client.go +++ b/service/kafkaconnect/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kafkaconnect/endpoints.go b/service/kafkaconnect/endpoints.go index 56fa0f151fc..3b4bdd56157 100644 --- a/service/kafkaconnect/endpoints.go +++ b/service/kafkaconnect/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kafkaconnect/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KAFKACONNECT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "KafkaConnect", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kafkaconnect/endpoints_config_test.go b/service/kafkaconnect/endpoints_config_test.go new file mode 100644 index 00000000000..c8b6a33a69f --- /dev/null +++ b/service/kafkaconnect/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kafkaconnect + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafkaconnect.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafkaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + expectURL: aws.String("https://env-kafkaconnect.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafkaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + expectURL: aws.String("http://config-kafkaconnect.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kafkaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kafkaconnect.dev", + clientEndpoint: aws.String("https://client-kafkaconnect.dev"), + expectURL: aws.String("https://client-kafkaconnect.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KAFKACONNECT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kafkaconnect/generated.json b/service/kafkaconnect/generated.json index d9e8a0316ea..b892345381e 100644 --- a/service/kafkaconnect/generated.json +++ b/service/kafkaconnect/generated.json @@ -24,6 +24,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kafkaconnect/go.mod b/service/kafkaconnect/go.mod index 2a705f6d06a..097dbaa6c6a 100644 --- a/service/kafkaconnect/go.mod +++ b/service/kafkaconnect/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kafkaconnect/go.sum b/service/kafkaconnect/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kafkaconnect/go.sum +++ b/service/kafkaconnect/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kendra/api_client.go b/service/kendra/api_client.go index 5a5f5ebda1d..c181dc0e30d 100644 --- a/service/kendra/api_client.go +++ b/service/kendra/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kendra/endpoints.go b/service/kendra/endpoints.go index f9fc1068c49..e3061343e04 100644 --- a/service/kendra/endpoints.go +++ b/service/kendra/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kendra/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KENDRA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "kendra", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kendra/endpoints_config_test.go b/service/kendra/endpoints_config_test.go new file mode 100644 index 00000000000..3e12dd6bb1f --- /dev/null +++ b/service/kendra/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kendra + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + expectURL: aws.String("https://env-kendra.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + expectURL: aws.String("http://config-kendra.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra.dev", + clientEndpoint: aws.String("https://client-kendra.dev"), + expectURL: aws.String("https://client-kendra.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KENDRA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kendra/generated.json b/service/kendra/generated.json index ac4de74ca0e..4506e889109 100644 --- a/service/kendra/generated.json +++ b/service/kendra/generated.json @@ -80,6 +80,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/kendra/go.mod b/service/kendra/go.mod index 75396028679..03e640811aa 100644 --- a/service/kendra/go.mod +++ b/service/kendra/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kendra/go.sum b/service/kendra/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kendra/go.sum +++ b/service/kendra/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kendraranking/api_client.go b/service/kendraranking/api_client.go index 4631ee10c84..689d55898b9 100644 --- a/service/kendraranking/api_client.go +++ b/service/kendraranking/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kendraranking/endpoints.go b/service/kendraranking/endpoints.go index 8aefb402d6d..12e1b09b9d9 100644 --- a/service/kendraranking/endpoints.go +++ b/service/kendraranking/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kendraranking/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KENDRA_RANKING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kendra Ranking", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kendraranking/endpoints_config_test.go b/service/kendraranking/endpoints_config_test.go new file mode 100644 index 00000000000..06204bf3b62 --- /dev/null +++ b/service/kendraranking/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kendraranking + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra-ranking.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra-ranking.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + expectURL: aws.String("https://env-kendra-ranking.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra-ranking.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + expectURL: aws.String("http://config-kendra-ranking.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kendra-ranking.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kendra-ranking.dev", + clientEndpoint: aws.String("https://client-kendra-ranking.dev"), + expectURL: aws.String("https://client-kendra-ranking.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KENDRA_RANKING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kendraranking/generated.json b/service/kendraranking/generated.json index 09ee2053229..60c3bda6920 100644 --- a/service/kendraranking/generated.json +++ b/service/kendraranking/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kendraranking/go.mod b/service/kendraranking/go.mod index d2d0344780f..6b891e2b666 100644 --- a/service/kendraranking/go.mod +++ b/service/kendraranking/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kendraranking/go.sum b/service/kendraranking/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kendraranking/go.sum +++ b/service/kendraranking/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/keyspaces/api_client.go b/service/keyspaces/api_client.go index 2b38d3b80d9..1c568eea248 100644 --- a/service/keyspaces/api_client.go +++ b/service/keyspaces/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/keyspaces/endpoints.go b/service/keyspaces/endpoints.go index 9b4db0aee82..31582009596 100644 --- a/service/keyspaces/endpoints.go +++ b/service/keyspaces/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/keyspaces/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KEYSPACES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Keyspaces", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/keyspaces/endpoints_config_test.go b/service/keyspaces/endpoints_config_test.go new file mode 100644 index 00000000000..2876ca10a0e --- /dev/null +++ b/service/keyspaces/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package keyspaces + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-keyspaces.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-keyspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + expectURL: aws.String("https://env-keyspaces.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-keyspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + expectURL: aws.String("http://config-keyspaces.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-keyspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-keyspaces.dev", + clientEndpoint: aws.String("https://client-keyspaces.dev"), + expectURL: aws.String("https://client-keyspaces.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KEYSPACES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/keyspaces/generated.json b/service/keyspaces/generated.json index f5919cb1d76..13c8645d86b 100644 --- a/service/keyspaces/generated.json +++ b/service/keyspaces/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/keyspaces/go.mod b/service/keyspaces/go.mod index 9652cd2e5f9..928464277db 100644 --- a/service/keyspaces/go.mod +++ b/service/keyspaces/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/keyspaces/go.sum b/service/keyspaces/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/keyspaces/go.sum +++ b/service/keyspaces/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesis/api_client.go b/service/kinesis/api_client.go index 4da9762bd17..6b8c9fa6e03 100644 --- a/service/kinesis/api_client.go +++ b/service/kinesis/api_client.go @@ -297,6 +297,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesis/endpoints.go b/service/kinesis/endpoints.go index 8e46c766ca1..e1c7c271569 100644 --- a/service/kinesis/endpoints.go +++ b/service/kinesis/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesis/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/endpoints/private/rulesfn" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesis/endpoints_config_test.go b/service/kinesis/endpoints_config_test.go new file mode 100644 index 00000000000..923ba4a79cf --- /dev/null +++ b/service/kinesis/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesis + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + expectURL: aws.String("https://env-kinesis.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + expectURL: aws.String("http://config-kinesis.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis.dev", + clientEndpoint: aws.String("https://client-kinesis.dev"), + expectURL: aws.String("https://client-kinesis.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesis/generated.json b/service/kinesis/generated.json index 595853ba20b..8f654555f95 100644 --- a/service/kinesis/generated.json +++ b/service/kinesis/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/kinesis/go.mod b/service/kinesis/go.mod index 22903fa18f0..a5bd86a341a 100644 --- a/service/kinesis/go.mod +++ b/service/kinesis/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -16,6 +17,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesis/go.sum b/service/kinesis/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/kinesis/go.sum +++ b/service/kinesis/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/kinesis/internal/testing/go.mod b/service/kinesis/internal/testing/go.mod index d91cfba465f..edb8347a6d7 100644 --- a/service/kinesis/internal/testing/go.mod +++ b/service/kinesis/internal/testing/go.mod @@ -15,14 +15,20 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../../../config/ + replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/eventstreamtesting => ../../../../service/internal/eventstreamtesting/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ diff --git a/service/kinesis/internal/testing/go.sum b/service/kinesis/internal/testing/go.sum index f3d4399b815..526818a008c 100644 --- a/service/kinesis/internal/testing/go.sum +++ b/service/kinesis/internal/testing/go.sum @@ -1,3 +1,9 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/kinesisanalytics/api_client.go b/service/kinesisanalytics/api_client.go index c3ce95298ed..06beaf96566 100644 --- a/service/kinesisanalytics/api_client.go +++ b/service/kinesisanalytics/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisanalytics/endpoints.go b/service/kinesisanalytics/endpoints.go index b5ba1939da0..c10941a4dd6 100644 --- a/service/kinesisanalytics/endpoints.go +++ b/service/kinesisanalytics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisanalytics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_ANALYTICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Analytics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisanalytics/endpoints_config_test.go b/service/kinesisanalytics/endpoints_config_test.go new file mode 100644 index 00000000000..1dd3d9ffcd4 --- /dev/null +++ b/service/kinesisanalytics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisanalytics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + expectURL: aws.String("https://env-kinesis-analytics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + expectURL: aws.String("http://config-kinesis-analytics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics.dev", + clientEndpoint: aws.String("https://client-kinesis-analytics.dev"), + expectURL: aws.String("https://client-kinesis-analytics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_ANALYTICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisanalytics/generated.json b/service/kinesisanalytics/generated.json index 19874ed417b..31a5a3068de 100644 --- a/service/kinesisanalytics/generated.json +++ b/service/kinesisanalytics/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisanalytics/go.mod b/service/kinesisanalytics/go.mod index 087a11cd74a..cec00f05ae3 100644 --- a/service/kinesisanalytics/go.mod +++ b/service/kinesisanalytics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisanalytics/go.sum b/service/kinesisanalytics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisanalytics/go.sum +++ b/service/kinesisanalytics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisanalyticsv2/api_client.go b/service/kinesisanalyticsv2/api_client.go index a48325cda92..25d157042c4 100644 --- a/service/kinesisanalyticsv2/api_client.go +++ b/service/kinesisanalyticsv2/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisanalyticsv2/endpoints.go b/service/kinesisanalyticsv2/endpoints.go index 9a346735b3f..d2a31219749 100644 --- a/service/kinesisanalyticsv2/endpoints.go +++ b/service/kinesisanalyticsv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_ANALYTICS_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Analytics V2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisanalyticsv2/endpoints_config_test.go b/service/kinesisanalyticsv2/endpoints_config_test.go new file mode 100644 index 00000000000..31e5bd3e1d1 --- /dev/null +++ b/service/kinesisanalyticsv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisanalyticsv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + expectURL: aws.String("https://env-kinesis-analytics-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + expectURL: aws.String("http://config-kinesis-analytics-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-analytics-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-analytics-v2.dev", + clientEndpoint: aws.String("https://client-kinesis-analytics-v2.dev"), + expectURL: aws.String("https://client-kinesis-analytics-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_ANALYTICS_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisanalyticsv2/generated.json b/service/kinesisanalyticsv2/generated.json index 0e9853e3ce8..a35ba5472e9 100644 --- a/service/kinesisanalyticsv2/generated.json +++ b/service/kinesisanalyticsv2/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisanalyticsv2/go.mod b/service/kinesisanalyticsv2/go.mod index 0cd72ccf219..b304086b26a 100644 --- a/service/kinesisanalyticsv2/go.mod +++ b/service/kinesisanalyticsv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisanalyticsv2/go.sum b/service/kinesisanalyticsv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisanalyticsv2/go.sum +++ b/service/kinesisanalyticsv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisvideo/api_client.go b/service/kinesisvideo/api_client.go index 8149da2c706..6f5d26b8ec6 100644 --- a/service/kinesisvideo/api_client.go +++ b/service/kinesisvideo/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisvideo/endpoints.go b/service/kinesisvideo/endpoints.go index fd6b3fc59c2..edfe0891bbb 100644 --- a/service/kinesisvideo/endpoints.go +++ b/service/kinesisvideo/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisvideo/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_VIDEO") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Video", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisvideo/endpoints_config_test.go b/service/kinesisvideo/endpoints_config_test.go new file mode 100644 index 00000000000..e387f9a7a29 --- /dev/null +++ b/service/kinesisvideo/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisvideo + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + expectURL: aws.String("https://env-kinesis-video.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + expectURL: aws.String("http://config-kinesis-video.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video.dev", + clientEndpoint: aws.String("https://client-kinesis-video.dev"), + expectURL: aws.String("https://client-kinesis-video.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_VIDEO", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisvideo/generated.json b/service/kinesisvideo/generated.json index 8f920da0c69..efc25aa2e89 100644 --- a/service/kinesisvideo/generated.json +++ b/service/kinesisvideo/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisvideo/go.mod b/service/kinesisvideo/go.mod index 86a5a158c4a..52f250f2f0a 100644 --- a/service/kinesisvideo/go.mod +++ b/service/kinesisvideo/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisvideo/go.sum b/service/kinesisvideo/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisvideo/go.sum +++ b/service/kinesisvideo/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisvideoarchivedmedia/api_client.go b/service/kinesisvideoarchivedmedia/api_client.go index f5472e62bc6..b587a6e9a54 100644 --- a/service/kinesisvideoarchivedmedia/api_client.go +++ b/service/kinesisvideoarchivedmedia/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisvideoarchivedmedia/endpoints.go b/service/kinesisvideoarchivedmedia/endpoints.go index daacdff8159..25e9aa75e06 100644 --- a/service/kinesisvideoarchivedmedia/endpoints.go +++ b/service/kinesisvideoarchivedmedia/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisvideoarchivedmedia/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_VIDEO_ARCHIVED_MEDIA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Video Archived Media", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisvideoarchivedmedia/endpoints_config_test.go b/service/kinesisvideoarchivedmedia/endpoints_config_test.go new file mode 100644 index 00000000000..3f87d468d7d --- /dev/null +++ b/service/kinesisvideoarchivedmedia/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisvideoarchivedmedia + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-archived-media.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-archived-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + expectURL: aws.String("https://env-kinesis-video-archived-media.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-archived-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + expectURL: aws.String("http://config-kinesis-video-archived-media.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-archived-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-archived-media.dev", + clientEndpoint: aws.String("https://client-kinesis-video-archived-media.dev"), + expectURL: aws.String("https://client-kinesis-video-archived-media.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_VIDEO_ARCHIVED_MEDIA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisvideoarchivedmedia/generated.json b/service/kinesisvideoarchivedmedia/generated.json index b7fa45f2125..1c618013cb2 100644 --- a/service/kinesisvideoarchivedmedia/generated.json +++ b/service/kinesisvideoarchivedmedia/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisvideoarchivedmedia/go.mod b/service/kinesisvideoarchivedmedia/go.mod index 3aabaae6eef..8c0ea11da1e 100644 --- a/service/kinesisvideoarchivedmedia/go.mod +++ b/service/kinesisvideoarchivedmedia/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisvideoarchivedmedia/go.sum b/service/kinesisvideoarchivedmedia/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisvideoarchivedmedia/go.sum +++ b/service/kinesisvideoarchivedmedia/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisvideomedia/api_client.go b/service/kinesisvideomedia/api_client.go index 875cb7b4205..10eb52e7e97 100644 --- a/service/kinesisvideomedia/api_client.go +++ b/service/kinesisvideomedia/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisvideomedia/endpoints.go b/service/kinesisvideomedia/endpoints.go index a71ef9401df..f269923a364 100644 --- a/service/kinesisvideomedia/endpoints.go +++ b/service/kinesisvideomedia/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisvideomedia/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_VIDEO_MEDIA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Video Media", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisvideomedia/endpoints_config_test.go b/service/kinesisvideomedia/endpoints_config_test.go new file mode 100644 index 00000000000..ee6339cf562 --- /dev/null +++ b/service/kinesisvideomedia/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisvideomedia + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-media.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + expectURL: aws.String("https://env-kinesis-video-media.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + expectURL: aws.String("http://config-kinesis-video-media.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-media.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-media.dev", + clientEndpoint: aws.String("https://client-kinesis-video-media.dev"), + expectURL: aws.String("https://client-kinesis-video-media.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_VIDEO_MEDIA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisvideomedia/generated.json b/service/kinesisvideomedia/generated.json index d073569f2cd..6780eac64a9 100644 --- a/service/kinesisvideomedia/generated.json +++ b/service/kinesisvideomedia/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisvideomedia/go.mod b/service/kinesisvideomedia/go.mod index 7e4866b7129..5535aa31473 100644 --- a/service/kinesisvideomedia/go.mod +++ b/service/kinesisvideomedia/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisvideomedia/go.sum b/service/kinesisvideomedia/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisvideomedia/go.sum +++ b/service/kinesisvideomedia/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisvideosignaling/api_client.go b/service/kinesisvideosignaling/api_client.go index 01f441a8c41..53f05b3f102 100644 --- a/service/kinesisvideosignaling/api_client.go +++ b/service/kinesisvideosignaling/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisvideosignaling/endpoints.go b/service/kinesisvideosignaling/endpoints.go index 8d279eaad06..b00ae2ed677 100644 --- a/service/kinesisvideosignaling/endpoints.go +++ b/service/kinesisvideosignaling/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisvideosignaling/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_VIDEO_SIGNALING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Video Signaling", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisvideosignaling/endpoints_config_test.go b/service/kinesisvideosignaling/endpoints_config_test.go new file mode 100644 index 00000000000..969747b1699 --- /dev/null +++ b/service/kinesisvideosignaling/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisvideosignaling + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-signaling.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-signaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + expectURL: aws.String("https://env-kinesis-video-signaling.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-signaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + expectURL: aws.String("http://config-kinesis-video-signaling.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-signaling.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-signaling.dev", + clientEndpoint: aws.String("https://client-kinesis-video-signaling.dev"), + expectURL: aws.String("https://client-kinesis-video-signaling.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_VIDEO_SIGNALING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisvideosignaling/generated.json b/service/kinesisvideosignaling/generated.json index 9369c3a5ac7..ffdfa0015d7 100644 --- a/service/kinesisvideosignaling/generated.json +++ b/service/kinesisvideosignaling/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisvideosignaling/go.mod b/service/kinesisvideosignaling/go.mod index acf65d33a30..a98969b42be 100644 --- a/service/kinesisvideosignaling/go.mod +++ b/service/kinesisvideosignaling/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisvideosignaling/go.sum b/service/kinesisvideosignaling/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisvideosignaling/go.sum +++ b/service/kinesisvideosignaling/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kinesisvideowebrtcstorage/api_client.go b/service/kinesisvideowebrtcstorage/api_client.go index 39247d078be..f2dc570ff91 100644 --- a/service/kinesisvideowebrtcstorage/api_client.go +++ b/service/kinesisvideowebrtcstorage/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kinesisvideowebrtcstorage/endpoints.go b/service/kinesisvideowebrtcstorage/endpoints.go index d6f6d18adbe..ce67ceae56a 100644 --- a/service/kinesisvideowebrtcstorage/endpoints.go +++ b/service/kinesisvideowebrtcstorage/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kinesisvideowebrtcstorage/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KINESIS_VIDEO_WEBRTC_STORAGE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Kinesis Video WebRTC Storage", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kinesisvideowebrtcstorage/endpoints_config_test.go b/service/kinesisvideowebrtcstorage/endpoints_config_test.go new file mode 100644 index 00000000000..967499dc029 --- /dev/null +++ b/service/kinesisvideowebrtcstorage/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kinesisvideowebrtcstorage + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-webrtc-storage.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-webrtc-storage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + expectURL: aws.String("https://env-kinesis-video-webrtc-storage.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-webrtc-storage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + expectURL: aws.String("http://config-kinesis-video-webrtc-storage.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kinesis-video-webrtc-storage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kinesis-video-webrtc-storage.dev", + clientEndpoint: aws.String("https://client-kinesis-video-webrtc-storage.dev"), + expectURL: aws.String("https://client-kinesis-video-webrtc-storage.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KINESIS_VIDEO_WEBRTC_STORAGE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kinesisvideowebrtcstorage/generated.json b/service/kinesisvideowebrtcstorage/generated.json index 7a88f18a950..87246977e3d 100644 --- a/service/kinesisvideowebrtcstorage/generated.json +++ b/service/kinesisvideowebrtcstorage/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kinesisvideowebrtcstorage/go.mod b/service/kinesisvideowebrtcstorage/go.mod index f3407104d76..8be6fa8efe7 100644 --- a/service/kinesisvideowebrtcstorage/go.mod +++ b/service/kinesisvideowebrtcstorage/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kinesisvideowebrtcstorage/go.sum b/service/kinesisvideowebrtcstorage/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kinesisvideowebrtcstorage/go.sum +++ b/service/kinesisvideowebrtcstorage/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/kms/api_client.go b/service/kms/api_client.go index b82ba626793..fd4bf2f7139 100644 --- a/service/kms/api_client.go +++ b/service/kms/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/kms/endpoints.go b/service/kms/endpoints.go index d32d8865d19..147b4b139a3 100644 --- a/service/kms/endpoints.go +++ b/service/kms/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/kms/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_KMS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "KMS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/kms/endpoints_config_test.go b/service/kms/endpoints_config_test.go new file mode 100644 index 00000000000..a02c6c609c1 --- /dev/null +++ b/service/kms/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package kms + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kms.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-kms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + expectURL: aws.String("https://env-kms.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-kms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + expectURL: aws.String("http://config-kms.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-kms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-kms.dev", + clientEndpoint: aws.String("https://client-kms.dev"), + expectURL: aws.String("https://client-kms.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_KMS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/kms/generated.json b/service/kms/generated.json index 954824f6dc5..bb67155e791 100644 --- a/service/kms/generated.json +++ b/service/kms/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/kms/go.mod b/service/kms/go.mod index eb35d0f3119..7dc777c3524 100644 --- a/service/kms/go.mod +++ b/service/kms/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/kms/go.sum b/service/kms/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/kms/go.sum +++ b/service/kms/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lakeformation/api_client.go b/service/lakeformation/api_client.go index 93df6587b1e..b01edcbad96 100644 --- a/service/lakeformation/api_client.go +++ b/service/lakeformation/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lakeformation/endpoints.go b/service/lakeformation/endpoints.go index d8c84cb7d91..90cdf699dca 100644 --- a/service/lakeformation/endpoints.go +++ b/service/lakeformation/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lakeformation/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LAKEFORMATION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "LakeFormation", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lakeformation/endpoints_config_test.go b/service/lakeformation/endpoints_config_test.go new file mode 100644 index 00000000000..d9aaf83f356 --- /dev/null +++ b/service/lakeformation/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lakeformation + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lakeformation.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lakeformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + expectURL: aws.String("https://env-lakeformation.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lakeformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + expectURL: aws.String("http://config-lakeformation.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lakeformation.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lakeformation.dev", + clientEndpoint: aws.String("https://client-lakeformation.dev"), + expectURL: aws.String("https://client-lakeformation.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LAKEFORMATION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lakeformation/generated.json b/service/lakeformation/generated.json index c665863f0ff..e28c6cfcd5f 100644 --- a/service/lakeformation/generated.json +++ b/service/lakeformation/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lakeformation/go.mod b/service/lakeformation/go.mod index b67e5516b03..fe85522ed05 100644 --- a/service/lakeformation/go.mod +++ b/service/lakeformation/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lakeformation/go.sum b/service/lakeformation/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lakeformation/go.sum +++ b/service/lakeformation/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lambda/api_client.go b/service/lambda/api_client.go index 6f341d64312..77c5fbf0ca7 100644 --- a/service/lambda/api_client.go +++ b/service/lambda/api_client.go @@ -297,6 +297,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lambda/endpoints.go b/service/lambda/endpoints.go index 13462e3a879..71f3b021384 100644 --- a/service/lambda/endpoints.go +++ b/service/lambda/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lambda/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LAMBDA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lambda", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lambda/endpoints_config_test.go b/service/lambda/endpoints_config_test.go new file mode 100644 index 00000000000..b79d45339f8 --- /dev/null +++ b/service/lambda/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lambda + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lambda.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lambda.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + expectURL: aws.String("https://env-lambda.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lambda.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + expectURL: aws.String("http://config-lambda.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lambda.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lambda.dev", + clientEndpoint: aws.String("https://client-lambda.dev"), + expectURL: aws.String("https://client-lambda.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LAMBDA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lambda/generated.json b/service/lambda/generated.json index bcf3d73ac44..b5a254552eb 100644 --- a/service/lambda/generated.json +++ b/service/lambda/generated.json @@ -80,6 +80,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/lambda/go.mod b/service/lambda/go.mod index 945a2d646c5..b54716abc04 100644 --- a/service/lambda/go.mod +++ b/service/lambda/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -16,6 +17,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lambda/go.sum b/service/lambda/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/lambda/go.sum +++ b/service/lambda/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/lexmodelbuildingservice/api_client.go b/service/lexmodelbuildingservice/api_client.go index 9a3e1686079..589818614c4 100644 --- a/service/lexmodelbuildingservice/api_client.go +++ b/service/lexmodelbuildingservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lexmodelbuildingservice/endpoints.go b/service/lexmodelbuildingservice/endpoints.go index 1a384f2a2ea..82c5ad3da2f 100644 --- a/service/lexmodelbuildingservice/endpoints.go +++ b/service/lexmodelbuildingservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lexmodelbuildingservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LEX_MODEL_BUILDING_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lex Model Building Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lexmodelbuildingservice/endpoints_config_test.go b/service/lexmodelbuildingservice/endpoints_config_test.go new file mode 100644 index 00000000000..a5eac1135ea --- /dev/null +++ b/service/lexmodelbuildingservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lexmodelbuildingservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-model-building-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-model-building-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + expectURL: aws.String("https://env-lex-model-building-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-model-building-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + expectURL: aws.String("http://config-lex-model-building-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-model-building-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-model-building-service.dev", + clientEndpoint: aws.String("https://client-lex-model-building-service.dev"), + expectURL: aws.String("https://client-lex-model-building-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LEX_MODEL_BUILDING_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lexmodelbuildingservice/generated.json b/service/lexmodelbuildingservice/generated.json index 45616c2c8c2..3133cad0d77 100644 --- a/service/lexmodelbuildingservice/generated.json +++ b/service/lexmodelbuildingservice/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lexmodelbuildingservice/go.mod b/service/lexmodelbuildingservice/go.mod index 2e7647e751d..fa195c7e3e8 100644 --- a/service/lexmodelbuildingservice/go.mod +++ b/service/lexmodelbuildingservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lexmodelbuildingservice/go.sum b/service/lexmodelbuildingservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lexmodelbuildingservice/go.sum +++ b/service/lexmodelbuildingservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lexmodelsv2/api_client.go b/service/lexmodelsv2/api_client.go index b21a8b1a520..27fcc18689c 100644 --- a/service/lexmodelsv2/api_client.go +++ b/service/lexmodelsv2/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lexmodelsv2/endpoints.go b/service/lexmodelsv2/endpoints.go index ebacd0dd6dd..e5d749a9188 100644 --- a/service/lexmodelsv2/endpoints.go +++ b/service/lexmodelsv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LEX_MODELS_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lex Models V2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lexmodelsv2/endpoints_config_test.go b/service/lexmodelsv2/endpoints_config_test.go new file mode 100644 index 00000000000..9a384dcd6c9 --- /dev/null +++ b/service/lexmodelsv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lexmodelsv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-models-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-models-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + expectURL: aws.String("https://env-lex-models-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-models-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + expectURL: aws.String("http://config-lex-models-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-models-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-models-v2.dev", + clientEndpoint: aws.String("https://client-lex-models-v2.dev"), + expectURL: aws.String("https://client-lex-models-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LEX_MODELS_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lexmodelsv2/generated.json b/service/lexmodelsv2/generated.json index fac3ecb18f5..3fa95a76384 100644 --- a/service/lexmodelsv2/generated.json +++ b/service/lexmodelsv2/generated.json @@ -105,6 +105,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lexmodelsv2/go.mod b/service/lexmodelsv2/go.mod index 6f24e6b9c6a..ec2660c24cb 100644 --- a/service/lexmodelsv2/go.mod +++ b/service/lexmodelsv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lexmodelsv2/go.sum b/service/lexmodelsv2/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/lexmodelsv2/go.sum +++ b/service/lexmodelsv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/lexruntimeservice/api_client.go b/service/lexruntimeservice/api_client.go index 22892c42b84..d58192173dd 100644 --- a/service/lexruntimeservice/api_client.go +++ b/service/lexruntimeservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lexruntimeservice/endpoints.go b/service/lexruntimeservice/endpoints.go index 5a41699258d..92e323eb027 100644 --- a/service/lexruntimeservice/endpoints.go +++ b/service/lexruntimeservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lexruntimeservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LEX_RUNTIME_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lex Runtime Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lexruntimeservice/endpoints_config_test.go b/service/lexruntimeservice/endpoints_config_test.go new file mode 100644 index 00000000000..ec0f192f678 --- /dev/null +++ b/service/lexruntimeservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lexruntimeservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + expectURL: aws.String("https://env-lex-runtime-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + expectURL: aws.String("http://config-lex-runtime-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-service.dev", + clientEndpoint: aws.String("https://client-lex-runtime-service.dev"), + expectURL: aws.String("https://client-lex-runtime-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LEX_RUNTIME_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lexruntimeservice/generated.json b/service/lexruntimeservice/generated.json index cc0eafde1cb..7bcca5a3d21 100644 --- a/service/lexruntimeservice/generated.json +++ b/service/lexruntimeservice/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lexruntimeservice/go.mod b/service/lexruntimeservice/go.mod index ef9985d649e..d176d98ff7f 100644 --- a/service/lexruntimeservice/go.mod +++ b/service/lexruntimeservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lexruntimeservice/go.sum b/service/lexruntimeservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lexruntimeservice/go.sum +++ b/service/lexruntimeservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lexruntimev2/api_client.go b/service/lexruntimev2/api_client.go index edc7591b2c2..bd57c6368b7 100644 --- a/service/lexruntimev2/api_client.go +++ b/service/lexruntimev2/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lexruntimev2/endpoints.go b/service/lexruntimev2/endpoints.go index dc743d00be2..7208f679e0c 100644 --- a/service/lexruntimev2/endpoints.go +++ b/service/lexruntimev2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lexruntimev2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LEX_RUNTIME_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lex Runtime V2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lexruntimev2/endpoints_config_test.go b/service/lexruntimev2/endpoints_config_test.go new file mode 100644 index 00000000000..6afbfdb5be1 --- /dev/null +++ b/service/lexruntimev2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lexruntimev2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + expectURL: aws.String("https://env-lex-runtime-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + expectURL: aws.String("http://config-lex-runtime-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lex-runtime-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lex-runtime-v2.dev", + clientEndpoint: aws.String("https://client-lex-runtime-v2.dev"), + expectURL: aws.String("https://client-lex-runtime-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LEX_RUNTIME_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lexruntimev2/generated.json b/service/lexruntimev2/generated.json index 5768d9b9331..29c6c657bb6 100644 --- a/service/lexruntimev2/generated.json +++ b/service/lexruntimev2/generated.json @@ -19,6 +19,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/lexruntimev2/go.mod b/service/lexruntimev2/go.mod index 3ff54be0c86..77e6ebea738 100644 --- a/service/lexruntimev2/go.mod +++ b/service/lexruntimev2/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -15,6 +16,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lexruntimev2/go.sum b/service/lexruntimev2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lexruntimev2/go.sum +++ b/service/lexruntimev2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/licensemanager/api_client.go b/service/licensemanager/api_client.go index 326dfb5399e..62c043ddf87 100644 --- a/service/licensemanager/api_client.go +++ b/service/licensemanager/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/licensemanager/endpoints.go b/service/licensemanager/endpoints.go index 61474ca677f..df199e9bdbc 100644 --- a/service/licensemanager/endpoints.go +++ b/service/licensemanager/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/licensemanager/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LICENSE_MANAGER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "License Manager", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/licensemanager/endpoints_config_test.go b/service/licensemanager/endpoints_config_test.go new file mode 100644 index 00000000000..d8ac331a7ce --- /dev/null +++ b/service/licensemanager/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package licensemanager + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + expectURL: aws.String("https://env-license-manager.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + expectURL: aws.String("http://config-license-manager.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager.dev", + clientEndpoint: aws.String("https://client-license-manager.dev"), + expectURL: aws.String("https://client-license-manager.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LICENSE_MANAGER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/licensemanager/generated.json b/service/licensemanager/generated.json index bcef368ee29..10e3fd00c29 100644 --- a/service/licensemanager/generated.json +++ b/service/licensemanager/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/licensemanager/go.mod b/service/licensemanager/go.mod index e51b86bedd7..d2fa0338a75 100644 --- a/service/licensemanager/go.mod +++ b/service/licensemanager/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/licensemanager/go.sum b/service/licensemanager/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/licensemanager/go.sum +++ b/service/licensemanager/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/licensemanagerlinuxsubscriptions/api_client.go b/service/licensemanagerlinuxsubscriptions/api_client.go index b1d6f021ea8..18371673abd 100644 --- a/service/licensemanagerlinuxsubscriptions/api_client.go +++ b/service/licensemanagerlinuxsubscriptions/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/licensemanagerlinuxsubscriptions/endpoints.go b/service/licensemanagerlinuxsubscriptions/endpoints.go index f0c9323ae3f..593e0c5fe8d 100644 --- a/service/licensemanagerlinuxsubscriptions/endpoints.go +++ b/service/licensemanagerlinuxsubscriptions/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/licensemanagerlinuxsubscriptions/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LICENSE_MANAGER_LINUX_SUBSCRIPTIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "License Manager Linux Subscriptions", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/licensemanagerlinuxsubscriptions/endpoints_config_test.go b/service/licensemanagerlinuxsubscriptions/endpoints_config_test.go new file mode 100644 index 00000000000..0710d2d2004 --- /dev/null +++ b/service/licensemanagerlinuxsubscriptions/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package licensemanagerlinuxsubscriptions + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-linux-subscriptions.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-linux-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + expectURL: aws.String("https://env-license-manager-linux-subscriptions.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-linux-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + expectURL: aws.String("http://config-license-manager-linux-subscriptions.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-linux-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-linux-subscriptions.dev", + clientEndpoint: aws.String("https://client-license-manager-linux-subscriptions.dev"), + expectURL: aws.String("https://client-license-manager-linux-subscriptions.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LICENSE_MANAGER_LINUX_SUBSCRIPTIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/licensemanagerlinuxsubscriptions/generated.json b/service/licensemanagerlinuxsubscriptions/generated.json index fd7cdc43fb5..12e6daf0170 100644 --- a/service/licensemanagerlinuxsubscriptions/generated.json +++ b/service/licensemanagerlinuxsubscriptions/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/licensemanagerlinuxsubscriptions/go.mod b/service/licensemanagerlinuxsubscriptions/go.mod index d44a77ef56b..d094f2e048b 100644 --- a/service/licensemanagerlinuxsubscriptions/go.mod +++ b/service/licensemanagerlinuxsubscriptions/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/licensemanagerlinuxsubscriptions/go.sum b/service/licensemanagerlinuxsubscriptions/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/licensemanagerlinuxsubscriptions/go.sum +++ b/service/licensemanagerlinuxsubscriptions/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/licensemanagerusersubscriptions/api_client.go b/service/licensemanagerusersubscriptions/api_client.go index ebf793c7d1b..d842f127609 100644 --- a/service/licensemanagerusersubscriptions/api_client.go +++ b/service/licensemanagerusersubscriptions/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/licensemanagerusersubscriptions/endpoints.go b/service/licensemanagerusersubscriptions/endpoints.go index ff5ea807560..d3acec8634e 100644 --- a/service/licensemanagerusersubscriptions/endpoints.go +++ b/service/licensemanagerusersubscriptions/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/licensemanagerusersubscriptions/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LICENSE_MANAGER_USER_SUBSCRIPTIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "License Manager User Subscriptions", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/licensemanagerusersubscriptions/endpoints_config_test.go b/service/licensemanagerusersubscriptions/endpoints_config_test.go new file mode 100644 index 00000000000..5a9714a5e48 --- /dev/null +++ b/service/licensemanagerusersubscriptions/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package licensemanagerusersubscriptions + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-user-subscriptions.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-user-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + expectURL: aws.String("https://env-license-manager-user-subscriptions.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-user-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + expectURL: aws.String("http://config-license-manager-user-subscriptions.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-license-manager-user-subscriptions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-license-manager-user-subscriptions.dev", + clientEndpoint: aws.String("https://client-license-manager-user-subscriptions.dev"), + expectURL: aws.String("https://client-license-manager-user-subscriptions.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LICENSE_MANAGER_USER_SUBSCRIPTIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/licensemanagerusersubscriptions/generated.json b/service/licensemanagerusersubscriptions/generated.json index 781a2339917..460c22ee08a 100644 --- a/service/licensemanagerusersubscriptions/generated.json +++ b/service/licensemanagerusersubscriptions/generated.json @@ -23,6 +23,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/licensemanagerusersubscriptions/go.mod b/service/licensemanagerusersubscriptions/go.mod index b10da00a44c..5f81d2b0f77 100644 --- a/service/licensemanagerusersubscriptions/go.mod +++ b/service/licensemanagerusersubscriptions/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/licensemanagerusersubscriptions/go.sum b/service/licensemanagerusersubscriptions/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/licensemanagerusersubscriptions/go.sum +++ b/service/licensemanagerusersubscriptions/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lightsail/api_client.go b/service/lightsail/api_client.go index 4c583972571..7b9d7e2da3c 100644 --- a/service/lightsail/api_client.go +++ b/service/lightsail/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lightsail/endpoints.go b/service/lightsail/endpoints.go index 8319bd1717e..37cc872d066 100644 --- a/service/lightsail/endpoints.go +++ b/service/lightsail/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lightsail/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LIGHTSAIL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Lightsail", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lightsail/endpoints_config_test.go b/service/lightsail/endpoints_config_test.go new file mode 100644 index 00000000000..7bde0a285b3 --- /dev/null +++ b/service/lightsail/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lightsail + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lightsail.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lightsail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + expectURL: aws.String("https://env-lightsail.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lightsail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + expectURL: aws.String("http://config-lightsail.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lightsail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lightsail.dev", + clientEndpoint: aws.String("https://client-lightsail.dev"), + expectURL: aws.String("https://client-lightsail.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LIGHTSAIL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lightsail/generated.json b/service/lightsail/generated.json index b9603d9711e..2fd73868706 100644 --- a/service/lightsail/generated.json +++ b/service/lightsail/generated.json @@ -171,6 +171,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lightsail/go.mod b/service/lightsail/go.mod index b1e0a9c0016..d2bf95d738e 100644 --- a/service/lightsail/go.mod +++ b/service/lightsail/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lightsail/go.sum b/service/lightsail/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lightsail/go.sum +++ b/service/lightsail/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/location/api_client.go b/service/location/api_client.go index 4c112579ba3..b1144338067 100644 --- a/service/location/api_client.go +++ b/service/location/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/location/endpoints.go b/service/location/endpoints.go index bbc20bd63bf..206c195f94e 100644 --- a/service/location/endpoints.go +++ b/service/location/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/location/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LOCATION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Location", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/location/endpoints_config_test.go b/service/location/endpoints_config_test.go new file mode 100644 index 00000000000..663cd77d2af --- /dev/null +++ b/service/location/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package location + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-location.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-location.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + expectURL: aws.String("https://env-location.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-location.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + expectURL: aws.String("http://config-location.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-location.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-location.dev", + clientEndpoint: aws.String("https://client-location.dev"), + expectURL: aws.String("https://client-location.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LOCATION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/location/generated.json b/service/location/generated.json index d866f6e4c32..d0b0b6f4998 100644 --- a/service/location/generated.json +++ b/service/location/generated.json @@ -70,6 +70,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/location/go.mod b/service/location/go.mod index 13aa8f9728a..905143ec6b5 100644 --- a/service/location/go.mod +++ b/service/location/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/location/go.sum b/service/location/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/location/go.sum +++ b/service/location/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lookoutequipment/api_client.go b/service/lookoutequipment/api_client.go index 2af89695231..f5e0a056112 100644 --- a/service/lookoutequipment/api_client.go +++ b/service/lookoutequipment/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lookoutequipment/endpoints.go b/service/lookoutequipment/endpoints.go index bf2a4ec33ed..e7a0bbdcea3 100644 --- a/service/lookoutequipment/endpoints.go +++ b/service/lookoutequipment/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lookoutequipment/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LOOKOUTEQUIPMENT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "LookoutEquipment", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lookoutequipment/endpoints_config_test.go b/service/lookoutequipment/endpoints_config_test.go new file mode 100644 index 00000000000..f293ed8e70e --- /dev/null +++ b/service/lookoutequipment/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lookoutequipment + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutequipment.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutequipment.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + expectURL: aws.String("https://env-lookoutequipment.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutequipment.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + expectURL: aws.String("http://config-lookoutequipment.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutequipment.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutequipment.dev", + clientEndpoint: aws.String("https://client-lookoutequipment.dev"), + expectURL: aws.String("https://client-lookoutequipment.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LOOKOUTEQUIPMENT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lookoutequipment/generated.json b/service/lookoutequipment/generated.json index 55948c6fae1..fafa9b9dbda 100644 --- a/service/lookoutequipment/generated.json +++ b/service/lookoutequipment/generated.json @@ -61,6 +61,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lookoutequipment/go.mod b/service/lookoutequipment/go.mod index f221d8ee2f4..db87ea89979 100644 --- a/service/lookoutequipment/go.mod +++ b/service/lookoutequipment/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lookoutequipment/go.sum b/service/lookoutequipment/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lookoutequipment/go.sum +++ b/service/lookoutequipment/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lookoutmetrics/api_client.go b/service/lookoutmetrics/api_client.go index ba491f58c3d..f46bea4ee1c 100644 --- a/service/lookoutmetrics/api_client.go +++ b/service/lookoutmetrics/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lookoutmetrics/endpoints.go b/service/lookoutmetrics/endpoints.go index f3fcffd8ffe..f9d7a00ee2c 100644 --- a/service/lookoutmetrics/endpoints.go +++ b/service/lookoutmetrics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lookoutmetrics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LOOKOUTMETRICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "LookoutMetrics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lookoutmetrics/endpoints_config_test.go b/service/lookoutmetrics/endpoints_config_test.go new file mode 100644 index 00000000000..622b5932579 --- /dev/null +++ b/service/lookoutmetrics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lookoutmetrics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutmetrics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutmetrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + expectURL: aws.String("https://env-lookoutmetrics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutmetrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + expectURL: aws.String("http://config-lookoutmetrics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutmetrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutmetrics.dev", + clientEndpoint: aws.String("https://client-lookoutmetrics.dev"), + expectURL: aws.String("https://client-lookoutmetrics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LOOKOUTMETRICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lookoutmetrics/generated.json b/service/lookoutmetrics/generated.json index 59d8e82922b..5687c66ccc2 100644 --- a/service/lookoutmetrics/generated.json +++ b/service/lookoutmetrics/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lookoutmetrics/go.mod b/service/lookoutmetrics/go.mod index e83848d11b7..74986b683b4 100644 --- a/service/lookoutmetrics/go.mod +++ b/service/lookoutmetrics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lookoutmetrics/go.sum b/service/lookoutmetrics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lookoutmetrics/go.sum +++ b/service/lookoutmetrics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/lookoutvision/api_client.go b/service/lookoutvision/api_client.go index 252009fec91..688548f60c8 100644 --- a/service/lookoutvision/api_client.go +++ b/service/lookoutvision/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/lookoutvision/endpoints.go b/service/lookoutvision/endpoints.go index 7f6681a4094..a855927e0ed 100644 --- a/service/lookoutvision/endpoints.go +++ b/service/lookoutvision/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/lookoutvision/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_LOOKOUTVISION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "LookoutVision", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/lookoutvision/endpoints_config_test.go b/service/lookoutvision/endpoints_config_test.go new file mode 100644 index 00000000000..6665627b3c2 --- /dev/null +++ b/service/lookoutvision/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package lookoutvision + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutvision.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutvision.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + expectURL: aws.String("https://env-lookoutvision.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutvision.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + expectURL: aws.String("http://config-lookoutvision.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-lookoutvision.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-lookoutvision.dev", + clientEndpoint: aws.String("https://client-lookoutvision.dev"), + expectURL: aws.String("https://client-lookoutvision.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_LOOKOUTVISION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/lookoutvision/generated.json b/service/lookoutvision/generated.json index e718bf1c502..b0871cf2ebe 100644 --- a/service/lookoutvision/generated.json +++ b/service/lookoutvision/generated.json @@ -34,6 +34,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/lookoutvision/go.mod b/service/lookoutvision/go.mod index 372ac117e03..d6848c97d5d 100644 --- a/service/lookoutvision/go.mod +++ b/service/lookoutvision/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/lookoutvision/go.sum b/service/lookoutvision/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/lookoutvision/go.sum +++ b/service/lookoutvision/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/m2/api_client.go b/service/m2/api_client.go index 2fa6c211e48..4be89a7261d 100644 --- a/service/m2/api_client.go +++ b/service/m2/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/m2/endpoints.go b/service/m2/endpoints.go index 8fc7c1cf95c..16e8cb4a761 100644 --- a/service/m2/endpoints.go +++ b/service/m2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/m2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_M2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "m2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/m2/endpoints_config_test.go b/service/m2/endpoints_config_test.go new file mode 100644 index 00000000000..42c04c9f614 --- /dev/null +++ b/service/m2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package m2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-m2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-m2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + expectURL: aws.String("https://env-m2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-m2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + expectURL: aws.String("http://config-m2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-m2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-m2.dev", + clientEndpoint: aws.String("https://client-m2.dev"), + expectURL: aws.String("https://client-m2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_M2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/m2/generated.json b/service/m2/generated.json index 072905f8aa2..59cdeb9e7fe 100644 --- a/service/m2/generated.json +++ b/service/m2/generated.json @@ -45,6 +45,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/m2/go.mod b/service/m2/go.mod index c938e3d62b9..645291a1849 100644 --- a/service/m2/go.mod +++ b/service/m2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/m2/go.sum b/service/m2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/m2/go.sum +++ b/service/m2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/machinelearning/api_client.go b/service/machinelearning/api_client.go index 70e51ced13e..218c990af11 100644 --- a/service/machinelearning/api_client.go +++ b/service/machinelearning/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/machinelearning/endpoints.go b/service/machinelearning/endpoints.go index c3c5754370f..d81e447aba7 100644 --- a/service/machinelearning/endpoints.go +++ b/service/machinelearning/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/machinelearning/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MACHINE_LEARNING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Machine Learning", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/machinelearning/endpoints_config_test.go b/service/machinelearning/endpoints_config_test.go new file mode 100644 index 00000000000..41a3cd8c78c --- /dev/null +++ b/service/machinelearning/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package machinelearning + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-machine-learning.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-machine-learning.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + expectURL: aws.String("https://env-machine-learning.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-machine-learning.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + expectURL: aws.String("http://config-machine-learning.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-machine-learning.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-machine-learning.dev", + clientEndpoint: aws.String("https://client-machine-learning.dev"), + expectURL: aws.String("https://client-machine-learning.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MACHINE_LEARNING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/machinelearning/generated.json b/service/machinelearning/generated.json index 3645f56aeac..846c7274d01 100644 --- a/service/machinelearning/generated.json +++ b/service/machinelearning/generated.json @@ -41,6 +41,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/machinelearning/go.mod b/service/machinelearning/go.mod index 04e086344bb..47ec4914a3d 100644 --- a/service/machinelearning/go.mod +++ b/service/machinelearning/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/machinelearning/go.sum b/service/machinelearning/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/machinelearning/go.sum +++ b/service/machinelearning/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/macie/api_client.go b/service/macie/api_client.go index e1a13042f5d..c7d7650f819 100644 --- a/service/macie/api_client.go +++ b/service/macie/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/macie/endpoints.go b/service/macie/endpoints.go index 22cd323d018..42f8337f468 100644 --- a/service/macie/endpoints.go +++ b/service/macie/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/macie/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MACIE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Macie", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/macie/endpoints_config_test.go b/service/macie/endpoints_config_test.go new file mode 100644 index 00000000000..819eb8b0f2c --- /dev/null +++ b/service/macie/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package macie + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + expectURL: aws.String("https://env-macie.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + expectURL: aws.String("http://config-macie.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie.dev", + clientEndpoint: aws.String("https://client-macie.dev"), + expectURL: aws.String("https://client-macie.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MACIE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/macie/generated.json b/service/macie/generated.json index df980b8dad1..29dfd487141 100644 --- a/service/macie/generated.json +++ b/service/macie/generated.json @@ -19,6 +19,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/macie/go.mod b/service/macie/go.mod index d35c8f2ee53..a6c32b0e93f 100644 --- a/service/macie/go.mod +++ b/service/macie/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/macie/go.sum b/service/macie/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/macie/go.sum +++ b/service/macie/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/macie2/api_client.go b/service/macie2/api_client.go index cb66b6536b2..b9bea6962b6 100644 --- a/service/macie2/api_client.go +++ b/service/macie2/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/macie2/endpoints.go b/service/macie2/endpoints.go index b17afc8ba40..ffe590334b9 100644 --- a/service/macie2/endpoints.go +++ b/service/macie2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/macie2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MACIE2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Macie2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/macie2/endpoints_config_test.go b/service/macie2/endpoints_config_test.go new file mode 100644 index 00000000000..303d849efb6 --- /dev/null +++ b/service/macie2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package macie2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + expectURL: aws.String("https://env-macie2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + expectURL: aws.String("http://config-macie2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-macie2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-macie2.dev", + clientEndpoint: aws.String("https://client-macie2.dev"), + expectURL: aws.String("https://client-macie2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MACIE2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/macie2/generated.json b/service/macie2/generated.json index 99eb91d3134..b8f3e94d007 100644 --- a/service/macie2/generated.json +++ b/service/macie2/generated.json @@ -92,6 +92,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/macie2/go.mod b/service/macie2/go.mod index dadd3fae964..c892a0a1fef 100644 --- a/service/macie2/go.mod +++ b/service/macie2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/macie2/go.sum b/service/macie2/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/macie2/go.sum +++ b/service/macie2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/managedblockchain/api_client.go b/service/managedblockchain/api_client.go index 9793c1ff878..7c4003a3f1d 100644 --- a/service/managedblockchain/api_client.go +++ b/service/managedblockchain/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/managedblockchain/endpoints.go b/service/managedblockchain/endpoints.go index c9e2df24177..1b3a673816b 100644 --- a/service/managedblockchain/endpoints.go +++ b/service/managedblockchain/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/managedblockchain/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MANAGEDBLOCKCHAIN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ManagedBlockchain", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/managedblockchain/endpoints_config_test.go b/service/managedblockchain/endpoints_config_test.go new file mode 100644 index 00000000000..b5c2b1a8da6 --- /dev/null +++ b/service/managedblockchain/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package managedblockchain + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + expectURL: aws.String("https://env-managedblockchain.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + expectURL: aws.String("http://config-managedblockchain.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain.dev", + clientEndpoint: aws.String("https://client-managedblockchain.dev"), + expectURL: aws.String("https://client-managedblockchain.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MANAGEDBLOCKCHAIN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/managedblockchain/generated.json b/service/managedblockchain/generated.json index cec4e15bca5..8001aafc218 100644 --- a/service/managedblockchain/generated.json +++ b/service/managedblockchain/generated.json @@ -39,6 +39,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/managedblockchain/go.mod b/service/managedblockchain/go.mod index 267f3d4b255..4543168cf1b 100644 --- a/service/managedblockchain/go.mod +++ b/service/managedblockchain/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/managedblockchain/go.sum b/service/managedblockchain/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/managedblockchain/go.sum +++ b/service/managedblockchain/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/managedblockchainquery/api_client.go b/service/managedblockchainquery/api_client.go index a6a1636e72e..077ca7c6026 100644 --- a/service/managedblockchainquery/api_client.go +++ b/service/managedblockchainquery/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/managedblockchainquery/endpoints.go b/service/managedblockchainquery/endpoints.go index 581d6e83acb..e9fec75a221 100644 --- a/service/managedblockchainquery/endpoints.go +++ b/service/managedblockchainquery/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/managedblockchainquery/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MANAGEDBLOCKCHAIN_QUERY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ManagedBlockchain Query", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/managedblockchainquery/endpoints_config_test.go b/service/managedblockchainquery/endpoints_config_test.go new file mode 100644 index 00000000000..b872575597d --- /dev/null +++ b/service/managedblockchainquery/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package managedblockchainquery + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain-query.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + expectURL: aws.String("https://env-managedblockchain-query.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + expectURL: aws.String("http://config-managedblockchain-query.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-managedblockchain-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-managedblockchain-query.dev", + clientEndpoint: aws.String("https://client-managedblockchain-query.dev"), + expectURL: aws.String("https://client-managedblockchain-query.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MANAGEDBLOCKCHAIN_QUERY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/managedblockchainquery/generated.json b/service/managedblockchainquery/generated.json index 1f2b9595221..0a3183eccd7 100644 --- a/service/managedblockchainquery/generated.json +++ b/service/managedblockchainquery/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/managedblockchainquery/go.mod b/service/managedblockchainquery/go.mod index 044a71f6902..e2b4f33e820 100644 --- a/service/managedblockchainquery/go.mod +++ b/service/managedblockchainquery/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/managedblockchainquery/go.sum b/service/managedblockchainquery/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/managedblockchainquery/go.sum +++ b/service/managedblockchainquery/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/marketplacecatalog/api_client.go b/service/marketplacecatalog/api_client.go index d9018bf06a9..0b636dfb3cc 100644 --- a/service/marketplacecatalog/api_client.go +++ b/service/marketplacecatalog/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/marketplacecatalog/endpoints.go b/service/marketplacecatalog/endpoints.go index bf87297d9f6..ca5f50448f0 100644 --- a/service/marketplacecatalog/endpoints.go +++ b/service/marketplacecatalog/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/marketplacecatalog/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MARKETPLACE_CATALOG") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Marketplace Catalog", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/marketplacecatalog/endpoints_config_test.go b/service/marketplacecatalog/endpoints_config_test.go new file mode 100644 index 00000000000..30372472b8b --- /dev/null +++ b/service/marketplacecatalog/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package marketplacecatalog + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-catalog.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + expectURL: aws.String("https://env-marketplace-catalog.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + expectURL: aws.String("http://config-marketplace-catalog.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-catalog.dev", + clientEndpoint: aws.String("https://client-marketplace-catalog.dev"), + expectURL: aws.String("https://client-marketplace-catalog.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MARKETPLACE_CATALOG", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/marketplacecatalog/generated.json b/service/marketplacecatalog/generated.json index b149e4c27c7..65bdf01580e 100644 --- a/service/marketplacecatalog/generated.json +++ b/service/marketplacecatalog/generated.json @@ -26,6 +26,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/marketplacecatalog/go.mod b/service/marketplacecatalog/go.mod index d95b571e388..af08e8173e4 100644 --- a/service/marketplacecatalog/go.mod +++ b/service/marketplacecatalog/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/marketplacecatalog/go.sum b/service/marketplacecatalog/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/marketplacecatalog/go.sum +++ b/service/marketplacecatalog/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/marketplacecommerceanalytics/api_client.go b/service/marketplacecommerceanalytics/api_client.go index 3438fd39473..a1eff735de0 100644 --- a/service/marketplacecommerceanalytics/api_client.go +++ b/service/marketplacecommerceanalytics/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/marketplacecommerceanalytics/endpoints.go b/service/marketplacecommerceanalytics/endpoints.go index 1b8ac52c418..057afa420bc 100644 --- a/service/marketplacecommerceanalytics/endpoints.go +++ b/service/marketplacecommerceanalytics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/marketplacecommerceanalytics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MARKETPLACE_COMMERCE_ANALYTICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Marketplace Commerce Analytics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/marketplacecommerceanalytics/endpoints_config_test.go b/service/marketplacecommerceanalytics/endpoints_config_test.go new file mode 100644 index 00000000000..647fa096ca1 --- /dev/null +++ b/service/marketplacecommerceanalytics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package marketplacecommerceanalytics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-commerce-analytics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-commerce-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + expectURL: aws.String("https://env-marketplace-commerce-analytics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-commerce-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + expectURL: aws.String("http://config-marketplace-commerce-analytics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-commerce-analytics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-commerce-analytics.dev", + clientEndpoint: aws.String("https://client-marketplace-commerce-analytics.dev"), + expectURL: aws.String("https://client-marketplace-commerce-analytics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MARKETPLACE_COMMERCE_ANALYTICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/marketplacecommerceanalytics/generated.json b/service/marketplacecommerceanalytics/generated.json index 774097a1678..a9925e9ff3d 100644 --- a/service/marketplacecommerceanalytics/generated.json +++ b/service/marketplacecommerceanalytics/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/marketplacecommerceanalytics/go.mod b/service/marketplacecommerceanalytics/go.mod index 5bc02936037..d6a4fb73bd1 100644 --- a/service/marketplacecommerceanalytics/go.mod +++ b/service/marketplacecommerceanalytics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/marketplacecommerceanalytics/go.sum b/service/marketplacecommerceanalytics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/marketplacecommerceanalytics/go.sum +++ b/service/marketplacecommerceanalytics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/marketplaceentitlementservice/api_client.go b/service/marketplaceentitlementservice/api_client.go index df4887908e1..61035f9b238 100644 --- a/service/marketplaceentitlementservice/api_client.go +++ b/service/marketplaceentitlementservice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/marketplaceentitlementservice/endpoints.go b/service/marketplaceentitlementservice/endpoints.go index 5bfcc114473..fa2ae079a1b 100644 --- a/service/marketplaceentitlementservice/endpoints.go +++ b/service/marketplaceentitlementservice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/marketplaceentitlementservice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MARKETPLACE_ENTITLEMENT_SERVICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Marketplace Entitlement Service", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/marketplaceentitlementservice/endpoints_config_test.go b/service/marketplaceentitlementservice/endpoints_config_test.go new file mode 100644 index 00000000000..ff128d2d315 --- /dev/null +++ b/service/marketplaceentitlementservice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package marketplaceentitlementservice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-entitlement-service.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-entitlement-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + expectURL: aws.String("https://env-marketplace-entitlement-service.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-entitlement-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + expectURL: aws.String("http://config-marketplace-entitlement-service.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-entitlement-service.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-entitlement-service.dev", + clientEndpoint: aws.String("https://client-marketplace-entitlement-service.dev"), + expectURL: aws.String("https://client-marketplace-entitlement-service.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MARKETPLACE_ENTITLEMENT_SERVICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/marketplaceentitlementservice/generated.json b/service/marketplaceentitlementservice/generated.json index bc514c13b56..20a39e28d2b 100644 --- a/service/marketplaceentitlementservice/generated.json +++ b/service/marketplaceentitlementservice/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/marketplaceentitlementservice/go.mod b/service/marketplaceentitlementservice/go.mod index 7804c4959b0..a15b9b0a448 100644 --- a/service/marketplaceentitlementservice/go.mod +++ b/service/marketplaceentitlementservice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/marketplaceentitlementservice/go.sum b/service/marketplaceentitlementservice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/marketplaceentitlementservice/go.sum +++ b/service/marketplaceentitlementservice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/marketplacemetering/api_client.go b/service/marketplacemetering/api_client.go index 0cd34afaa33..e368201cef7 100644 --- a/service/marketplacemetering/api_client.go +++ b/service/marketplacemetering/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/marketplacemetering/endpoints.go b/service/marketplacemetering/endpoints.go index efa24cce1c3..18f48171c43 100644 --- a/service/marketplacemetering/endpoints.go +++ b/service/marketplacemetering/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/marketplacemetering/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MARKETPLACE_METERING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Marketplace Metering", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/marketplacemetering/endpoints_config_test.go b/service/marketplacemetering/endpoints_config_test.go new file mode 100644 index 00000000000..0197e723f56 --- /dev/null +++ b/service/marketplacemetering/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package marketplacemetering + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-metering.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-metering.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + expectURL: aws.String("https://env-marketplace-metering.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-metering.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + expectURL: aws.String("http://config-marketplace-metering.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-marketplace-metering.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-marketplace-metering.dev", + clientEndpoint: aws.String("https://client-marketplace-metering.dev"), + expectURL: aws.String("https://client-marketplace-metering.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MARKETPLACE_METERING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/marketplacemetering/generated.json b/service/marketplacemetering/generated.json index cc5f0472602..df4a6bc275b 100644 --- a/service/marketplacemetering/generated.json +++ b/service/marketplacemetering/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/marketplacemetering/go.mod b/service/marketplacemetering/go.mod index 45987f8ff12..ce2d3841e0d 100644 --- a/service/marketplacemetering/go.mod +++ b/service/marketplacemetering/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/marketplacemetering/go.sum b/service/marketplacemetering/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/marketplacemetering/go.sum +++ b/service/marketplacemetering/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediaconnect/api_client.go b/service/mediaconnect/api_client.go index 87c9ba6eea4..772e73a677a 100644 --- a/service/mediaconnect/api_client.go +++ b/service/mediaconnect/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediaconnect/endpoints.go b/service/mediaconnect/endpoints.go index 7e3723d0002..b91383cf28a 100644 --- a/service/mediaconnect/endpoints.go +++ b/service/mediaconnect/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediaconnect/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIACONNECT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaConnect", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediaconnect/endpoints_config_test.go b/service/mediaconnect/endpoints_config_test.go new file mode 100644 index 00000000000..58717261b6e --- /dev/null +++ b/service/mediaconnect/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediaconnect + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconnect.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + expectURL: aws.String("https://env-mediaconnect.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + expectURL: aws.String("http://config-mediaconnect.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconnect.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconnect.dev", + clientEndpoint: aws.String("https://client-mediaconnect.dev"), + expectURL: aws.String("https://client-mediaconnect.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIACONNECT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediaconnect/generated.json b/service/mediaconnect/generated.json index 5347d20e177..13ba7ec56a1 100644 --- a/service/mediaconnect/generated.json +++ b/service/mediaconnect/generated.json @@ -63,6 +63,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediaconnect/go.mod b/service/mediaconnect/go.mod index 71af6ac0ee1..fac8f25013b 100644 --- a/service/mediaconnect/go.mod +++ b/service/mediaconnect/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediaconnect/go.sum b/service/mediaconnect/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/mediaconnect/go.sum +++ b/service/mediaconnect/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/mediaconvert/api_client.go b/service/mediaconvert/api_client.go index b55886cc13b..3bf91c017ff 100644 --- a/service/mediaconvert/api_client.go +++ b/service/mediaconvert/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediaconvert/endpoints.go b/service/mediaconvert/endpoints.go index 48cb7e27a69..2bc032b5599 100644 --- a/service/mediaconvert/endpoints.go +++ b/service/mediaconvert/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediaconvert/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIACONVERT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaConvert", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediaconvert/endpoints_config_test.go b/service/mediaconvert/endpoints_config_test.go new file mode 100644 index 00000000000..d5b65ec21ac --- /dev/null +++ b/service/mediaconvert/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediaconvert + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconvert.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconvert.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + expectURL: aws.String("https://env-mediaconvert.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconvert.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + expectURL: aws.String("http://config-mediaconvert.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediaconvert.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediaconvert.dev", + clientEndpoint: aws.String("https://client-mediaconvert.dev"), + expectURL: aws.String("https://client-mediaconvert.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIACONVERT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediaconvert/generated.json b/service/mediaconvert/generated.json index f44afc08339..45166142a0d 100644 --- a/service/mediaconvert/generated.json +++ b/service/mediaconvert/generated.json @@ -40,6 +40,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediaconvert/go.mod b/service/mediaconvert/go.mod index 58c8b244210..6b389da3c31 100644 --- a/service/mediaconvert/go.mod +++ b/service/mediaconvert/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediaconvert/go.sum b/service/mediaconvert/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediaconvert/go.sum +++ b/service/mediaconvert/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/medialive/api_client.go b/service/medialive/api_client.go index 7d9b21e2c71..e5e8fef30c5 100644 --- a/service/medialive/api_client.go +++ b/service/medialive/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/medialive/endpoints.go b/service/medialive/endpoints.go index fe45330023b..9076ac5e09c 100644 --- a/service/medialive/endpoints.go +++ b/service/medialive/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/medialive/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIALIVE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaLive", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/medialive/endpoints_config_test.go b/service/medialive/endpoints_config_test.go new file mode 100644 index 00000000000..3a3d82530d6 --- /dev/null +++ b/service/medialive/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package medialive + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-medialive.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-medialive.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + expectURL: aws.String("https://env-medialive.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-medialive.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + expectURL: aws.String("http://config-medialive.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-medialive.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medialive.dev", + clientEndpoint: aws.String("https://client-medialive.dev"), + expectURL: aws.String("https://client-medialive.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIALIVE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/medialive/generated.json b/service/medialive/generated.json index abeadea01bd..5b1d12b573d 100644 --- a/service/medialive/generated.json +++ b/service/medialive/generated.json @@ -77,6 +77,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/medialive/go.mod b/service/medialive/go.mod index 4176c4b9af7..b3d05dc6f1d 100644 --- a/service/medialive/go.mod +++ b/service/medialive/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/medialive/go.sum b/service/medialive/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/medialive/go.sum +++ b/service/medialive/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/mediapackage/api_client.go b/service/mediapackage/api_client.go index 3b7f105dad8..e4944e10ada 100644 --- a/service/mediapackage/api_client.go +++ b/service/mediapackage/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediapackage/endpoints.go b/service/mediapackage/endpoints.go index 8376bd81f2d..100155cde8e 100644 --- a/service/mediapackage/endpoints.go +++ b/service/mediapackage/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediapackage/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIAPACKAGE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaPackage", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediapackage/endpoints_config_test.go b/service/mediapackage/endpoints_config_test.go new file mode 100644 index 00000000000..bbf45cace50 --- /dev/null +++ b/service/mediapackage/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediapackage + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + expectURL: aws.String("https://env-mediapackage.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + expectURL: aws.String("http://config-mediapackage.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage.dev", + clientEndpoint: aws.String("https://client-mediapackage.dev"), + expectURL: aws.String("https://client-mediapackage.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIAPACKAGE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediapackage/generated.json b/service/mediapackage/generated.json index ec0321a0003..4ace10c0d3c 100644 --- a/service/mediapackage/generated.json +++ b/service/mediapackage/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediapackage/go.mod b/service/mediapackage/go.mod index 3ff071f5123..ecc1ca2e1f4 100644 --- a/service/mediapackage/go.mod +++ b/service/mediapackage/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediapackage/go.sum b/service/mediapackage/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediapackage/go.sum +++ b/service/mediapackage/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediapackagev2/api_client.go b/service/mediapackagev2/api_client.go index 4f7f62f281e..a8802a55fc2 100644 --- a/service/mediapackagev2/api_client.go +++ b/service/mediapackagev2/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediapackagev2/endpoints.go b/service/mediapackagev2/endpoints.go index ff2abe38c83..f9c92323973 100644 --- a/service/mediapackagev2/endpoints.go +++ b/service/mediapackagev2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIAPACKAGEV2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaPackageV2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediapackagev2/endpoints_config_test.go b/service/mediapackagev2/endpoints_config_test.go new file mode 100644 index 00000000000..04ba602fe66 --- /dev/null +++ b/service/mediapackagev2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediapackagev2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackagev2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackagev2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + expectURL: aws.String("https://env-mediapackagev2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackagev2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + expectURL: aws.String("http://config-mediapackagev2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackagev2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackagev2.dev", + clientEndpoint: aws.String("https://client-mediapackagev2.dev"), + expectURL: aws.String("https://client-mediapackagev2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIAPACKAGEV2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediapackagev2/generated.json b/service/mediapackagev2/generated.json index 148f2d33674..2ca2a097865 100644 --- a/service/mediapackagev2/generated.json +++ b/service/mediapackagev2/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediapackagev2/go.mod b/service/mediapackagev2/go.mod index d79167aaa98..b31f5e6cad9 100644 --- a/service/mediapackagev2/go.mod +++ b/service/mediapackagev2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediapackagev2/go.sum b/service/mediapackagev2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediapackagev2/go.sum +++ b/service/mediapackagev2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediapackagevod/api_client.go b/service/mediapackagevod/api_client.go index 1e3aba51d7c..fcde3f4d255 100644 --- a/service/mediapackagevod/api_client.go +++ b/service/mediapackagevod/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediapackagevod/endpoints.go b/service/mediapackagevod/endpoints.go index 436f916d6ce..51b2d653cac 100644 --- a/service/mediapackagevod/endpoints.go +++ b/service/mediapackagevod/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediapackagevod/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIAPACKAGE_VOD") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaPackage Vod", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediapackagevod/endpoints_config_test.go b/service/mediapackagevod/endpoints_config_test.go new file mode 100644 index 00000000000..cbfdb1c19c8 --- /dev/null +++ b/service/mediapackagevod/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediapackagevod + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage-vod.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage-vod.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + expectURL: aws.String("https://env-mediapackage-vod.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage-vod.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + expectURL: aws.String("http://config-mediapackage-vod.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediapackage-vod.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediapackage-vod.dev", + clientEndpoint: aws.String("https://client-mediapackage-vod.dev"), + expectURL: aws.String("https://client-mediapackage-vod.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIAPACKAGE_VOD", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediapackagevod/generated.json b/service/mediapackagevod/generated.json index c59264a3f6d..e5e14722ebe 100644 --- a/service/mediapackagevod/generated.json +++ b/service/mediapackagevod/generated.json @@ -29,6 +29,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediapackagevod/go.mod b/service/mediapackagevod/go.mod index 1901ff9f5da..3ff748a9c81 100644 --- a/service/mediapackagevod/go.mod +++ b/service/mediapackagevod/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediapackagevod/go.sum b/service/mediapackagevod/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediapackagevod/go.sum +++ b/service/mediapackagevod/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediastore/api_client.go b/service/mediastore/api_client.go index bb4d6ad37d3..d21f1af88e1 100644 --- a/service/mediastore/api_client.go +++ b/service/mediastore/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediastore/endpoints.go b/service/mediastore/endpoints.go index 6828374d515..6d54bcd57f6 100644 --- a/service/mediastore/endpoints.go +++ b/service/mediastore/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediastore/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIASTORE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaStore", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediastore/endpoints_config_test.go b/service/mediastore/endpoints_config_test.go new file mode 100644 index 00000000000..90926e998ee --- /dev/null +++ b/service/mediastore/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediastore + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + expectURL: aws.String("https://env-mediastore.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + expectURL: aws.String("http://config-mediastore.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore.dev", + clientEndpoint: aws.String("https://client-mediastore.dev"), + expectURL: aws.String("https://client-mediastore.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIASTORE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediastore/generated.json b/service/mediastore/generated.json index df3f523054b..b0f2b733604 100644 --- a/service/mediastore/generated.json +++ b/service/mediastore/generated.json @@ -33,6 +33,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediastore/go.mod b/service/mediastore/go.mod index 845bdc047e9..412a1b93060 100644 --- a/service/mediastore/go.mod +++ b/service/mediastore/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediastore/go.sum b/service/mediastore/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediastore/go.sum +++ b/service/mediastore/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediastoredata/api_client.go b/service/mediastoredata/api_client.go index d50e3b411fd..770a535f05f 100644 --- a/service/mediastoredata/api_client.go +++ b/service/mediastoredata/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediastoredata/endpoints.go b/service/mediastoredata/endpoints.go index 23419044aff..95a0fb74ac8 100644 --- a/service/mediastoredata/endpoints.go +++ b/service/mediastoredata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediastoredata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIASTORE_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaStore Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediastoredata/endpoints_config_test.go b/service/mediastoredata/endpoints_config_test.go new file mode 100644 index 00000000000..31676f451b0 --- /dev/null +++ b/service/mediastoredata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediastoredata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + expectURL: aws.String("https://env-mediastore-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + expectURL: aws.String("http://config-mediastore-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediastore-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediastore-data.dev", + clientEndpoint: aws.String("https://client-mediastore-data.dev"), + expectURL: aws.String("https://client-mediastore-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIASTORE_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediastoredata/generated.json b/service/mediastoredata/generated.json index 372a14a0af4..a4288832bee 100644 --- a/service/mediastoredata/generated.json +++ b/service/mediastoredata/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediastoredata/go.mod b/service/mediastoredata/go.mod index 75f56dc5d23..465c4fbb086 100644 --- a/service/mediastoredata/go.mod +++ b/service/mediastoredata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediastoredata/go.sum b/service/mediastoredata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediastoredata/go.sum +++ b/service/mediastoredata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mediatailor/api_client.go b/service/mediatailor/api_client.go index 0ce47a3deaf..3e41901f16f 100644 --- a/service/mediatailor/api_client.go +++ b/service/mediatailor/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mediatailor/endpoints.go b/service/mediatailor/endpoints.go index 915130578bf..d5372229645 100644 --- a/service/mediatailor/endpoints.go +++ b/service/mediatailor/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mediatailor/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDIATAILOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MediaTailor", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mediatailor/endpoints_config_test.go b/service/mediatailor/endpoints_config_test.go new file mode 100644 index 00000000000..30c316cbe74 --- /dev/null +++ b/service/mediatailor/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mediatailor + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediatailor.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediatailor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + expectURL: aws.String("https://env-mediatailor.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediatailor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + expectURL: aws.String("http://config-mediatailor.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mediatailor.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mediatailor.dev", + clientEndpoint: aws.String("https://client-mediatailor.dev"), + expectURL: aws.String("https://client-mediatailor.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDIATAILOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mediatailor/generated.json b/service/mediatailor/generated.json index 1374d9701b0..0df03c748d1 100644 --- a/service/mediatailor/generated.json +++ b/service/mediatailor/generated.json @@ -56,6 +56,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mediatailor/go.mod b/service/mediatailor/go.mod index 9686a4f0d86..e89aabb3710 100644 --- a/service/mediatailor/go.mod +++ b/service/mediatailor/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mediatailor/go.sum b/service/mediatailor/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mediatailor/go.sum +++ b/service/mediatailor/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/medicalimaging/api_client.go b/service/medicalimaging/api_client.go index 8177aa1e88a..df474d33ac2 100644 --- a/service/medicalimaging/api_client.go +++ b/service/medicalimaging/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/medicalimaging/endpoints.go b/service/medicalimaging/endpoints.go index 7992c8f2689..915e3bcbdcd 100644 --- a/service/medicalimaging/endpoints.go +++ b/service/medicalimaging/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/medicalimaging/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEDICAL_IMAGING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Medical Imaging", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/medicalimaging/endpoints_config_test.go b/service/medicalimaging/endpoints_config_test.go new file mode 100644 index 00000000000..43f3f0bf6a0 --- /dev/null +++ b/service/medicalimaging/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package medicalimaging + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-medical-imaging.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-medical-imaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + expectURL: aws.String("https://env-medical-imaging.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-medical-imaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + expectURL: aws.String("http://config-medical-imaging.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-medical-imaging.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-medical-imaging.dev", + clientEndpoint: aws.String("https://client-medical-imaging.dev"), + expectURL: aws.String("https://client-medical-imaging.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEDICAL_IMAGING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/medicalimaging/generated.json b/service/medicalimaging/generated.json index b05bc079e91..03f4223f18c 100644 --- a/service/medicalimaging/generated.json +++ b/service/medicalimaging/generated.json @@ -30,6 +30,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/medicalimaging/go.mod b/service/medicalimaging/go.mod index 7b24f9a6355..bd70e229867 100644 --- a/service/medicalimaging/go.mod +++ b/service/medicalimaging/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/medicalimaging/go.sum b/service/medicalimaging/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/medicalimaging/go.sum +++ b/service/medicalimaging/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/memorydb/api_client.go b/service/memorydb/api_client.go index 11930364de9..1624b2168f3 100644 --- a/service/memorydb/api_client.go +++ b/service/memorydb/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/memorydb/endpoints.go b/service/memorydb/endpoints.go index b3e197ba71c..1f582e6f9a7 100644 --- a/service/memorydb/endpoints.go +++ b/service/memorydb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/memorydb/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MEMORYDB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MemoryDB", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/memorydb/endpoints_config_test.go b/service/memorydb/endpoints_config_test.go new file mode 100644 index 00000000000..c1670ab104a --- /dev/null +++ b/service/memorydb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package memorydb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-memorydb.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-memorydb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + expectURL: aws.String("https://env-memorydb.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-memorydb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + expectURL: aws.String("http://config-memorydb.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-memorydb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-memorydb.dev", + clientEndpoint: aws.String("https://client-memorydb.dev"), + expectURL: aws.String("https://client-memorydb.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MEMORYDB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/memorydb/generated.json b/service/memorydb/generated.json index febeb65758f..7b9157d351e 100644 --- a/service/memorydb/generated.json +++ b/service/memorydb/generated.json @@ -50,6 +50,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/memorydb/go.mod b/service/memorydb/go.mod index cba5221f1e1..f2d9772473c 100644 --- a/service/memorydb/go.mod +++ b/service/memorydb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/memorydb/go.sum b/service/memorydb/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/memorydb/go.sum +++ b/service/memorydb/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mgn/api_client.go b/service/mgn/api_client.go index ff7a43f3479..a5561bfb696 100644 --- a/service/mgn/api_client.go +++ b/service/mgn/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mgn/endpoints.go b/service/mgn/endpoints.go index 3d38952d8e4..2717362d06f 100644 --- a/service/mgn/endpoints.go +++ b/service/mgn/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mgn/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MGN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "mgn", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mgn/endpoints_config_test.go b/service/mgn/endpoints_config_test.go new file mode 100644 index 00000000000..89a3fd9cd59 --- /dev/null +++ b/service/mgn/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mgn + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mgn.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mgn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + expectURL: aws.String("https://env-mgn.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mgn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + expectURL: aws.String("http://config-mgn.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mgn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mgn.dev", + clientEndpoint: aws.String("https://client-mgn.dev"), + expectURL: aws.String("https://client-mgn.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MGN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mgn/generated.json b/service/mgn/generated.json index a08f00872ac..c183f054fab 100644 --- a/service/mgn/generated.json +++ b/service/mgn/generated.json @@ -82,6 +82,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mgn/go.mod b/service/mgn/go.mod index fdc224455f6..c498663e106 100644 --- a/service/mgn/go.mod +++ b/service/mgn/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mgn/go.sum b/service/mgn/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mgn/go.sum +++ b/service/mgn/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/migrationhub/api_client.go b/service/migrationhub/api_client.go index edf12a14583..9de88473ea4 100644 --- a/service/migrationhub/api_client.go +++ b/service/migrationhub/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/migrationhub/endpoints.go b/service/migrationhub/endpoints.go index 4ecd8a559ee..05b8fa7d7fd 100644 --- a/service/migrationhub/endpoints.go +++ b/service/migrationhub/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/migrationhub/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MIGRATION_HUB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Migration Hub", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/migrationhub/endpoints_config_test.go b/service/migrationhub/endpoints_config_test.go new file mode 100644 index 00000000000..45da58dfe7a --- /dev/null +++ b/service/migrationhub/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package migrationhub + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + expectURL: aws.String("https://env-migration-hub.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + expectURL: aws.String("http://config-migration-hub.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub.dev", + clientEndpoint: aws.String("https://client-migration-hub.dev"), + expectURL: aws.String("https://client-migration-hub.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MIGRATION_HUB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/migrationhub/generated.json b/service/migrationhub/generated.json index cc4f2e098e1..d67edeeeea2 100644 --- a/service/migrationhub/generated.json +++ b/service/migrationhub/generated.json @@ -29,6 +29,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/migrationhub/go.mod b/service/migrationhub/go.mod index 3c49571e419..7741c9ac37b 100644 --- a/service/migrationhub/go.mod +++ b/service/migrationhub/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/migrationhub/go.sum b/service/migrationhub/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/migrationhub/go.sum +++ b/service/migrationhub/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/migrationhubconfig/api_client.go b/service/migrationhubconfig/api_client.go index 56d39675b7f..b0916b23fe3 100644 --- a/service/migrationhubconfig/api_client.go +++ b/service/migrationhubconfig/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/migrationhubconfig/endpoints.go b/service/migrationhubconfig/endpoints.go index 0904571e2fd..dfdb7f5f00e 100644 --- a/service/migrationhubconfig/endpoints.go +++ b/service/migrationhubconfig/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/migrationhubconfig/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MIGRATIONHUB_CONFIG") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MigrationHub Config", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/migrationhubconfig/endpoints_config_test.go b/service/migrationhubconfig/endpoints_config_test.go new file mode 100644 index 00000000000..203875f5c98 --- /dev/null +++ b/service/migrationhubconfig/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package migrationhubconfig + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhub-config.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhub-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + expectURL: aws.String("https://env-migrationhub-config.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhub-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + expectURL: aws.String("http://config-migrationhub-config.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhub-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhub-config.dev", + clientEndpoint: aws.String("https://client-migrationhub-config.dev"), + expectURL: aws.String("https://client-migrationhub-config.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MIGRATIONHUB_CONFIG", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/migrationhubconfig/generated.json b/service/migrationhubconfig/generated.json index bae0751288d..1ea4b416931 100644 --- a/service/migrationhubconfig/generated.json +++ b/service/migrationhubconfig/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/migrationhubconfig/go.mod b/service/migrationhubconfig/go.mod index 658eb71ea39..1f8d7097c1e 100644 --- a/service/migrationhubconfig/go.mod +++ b/service/migrationhubconfig/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/migrationhubconfig/go.sum b/service/migrationhubconfig/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/migrationhubconfig/go.sum +++ b/service/migrationhubconfig/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/migrationhuborchestrator/api_client.go b/service/migrationhuborchestrator/api_client.go index f4bbba4b461..5a8af28e3eb 100644 --- a/service/migrationhuborchestrator/api_client.go +++ b/service/migrationhuborchestrator/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/migrationhuborchestrator/endpoints.go b/service/migrationhuborchestrator/endpoints.go index a9c557805e5..803d23493fe 100644 --- a/service/migrationhuborchestrator/endpoints.go +++ b/service/migrationhuborchestrator/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/migrationhuborchestrator/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MIGRATIONHUBORCHESTRATOR") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MigrationHubOrchestrator", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/migrationhuborchestrator/endpoints_config_test.go b/service/migrationhuborchestrator/endpoints_config_test.go new file mode 100644 index 00000000000..24db1f6a952 --- /dev/null +++ b/service/migrationhuborchestrator/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package migrationhuborchestrator + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhuborchestrator.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhuborchestrator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + expectURL: aws.String("https://env-migrationhuborchestrator.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhuborchestrator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + expectURL: aws.String("http://config-migrationhuborchestrator.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhuborchestrator.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhuborchestrator.dev", + clientEndpoint: aws.String("https://client-migrationhuborchestrator.dev"), + expectURL: aws.String("https://client-migrationhuborchestrator.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MIGRATIONHUBORCHESTRATOR", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/migrationhuborchestrator/generated.json b/service/migrationhuborchestrator/generated.json index b5d77d7dbc9..566a0055370 100644 --- a/service/migrationhuborchestrator/generated.json +++ b/service/migrationhuborchestrator/generated.json @@ -40,6 +40,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/migrationhuborchestrator/go.mod b/service/migrationhuborchestrator/go.mod index 29fd7c56396..52571540fe2 100644 --- a/service/migrationhuborchestrator/go.mod +++ b/service/migrationhuborchestrator/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/migrationhuborchestrator/go.sum b/service/migrationhuborchestrator/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/migrationhuborchestrator/go.sum +++ b/service/migrationhuborchestrator/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/migrationhubrefactorspaces/api_client.go b/service/migrationhubrefactorspaces/api_client.go index c7627b2eadb..f154b7b7463 100644 --- a/service/migrationhubrefactorspaces/api_client.go +++ b/service/migrationhubrefactorspaces/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/migrationhubrefactorspaces/endpoints.go b/service/migrationhubrefactorspaces/endpoints.go index ed73a582ba8..fd2a7f4076b 100644 --- a/service/migrationhubrefactorspaces/endpoints.go +++ b/service/migrationhubrefactorspaces/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/migrationhubrefactorspaces/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MIGRATION_HUB_REFACTOR_SPACES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Migration Hub Refactor Spaces", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/migrationhubrefactorspaces/endpoints_config_test.go b/service/migrationhubrefactorspaces/endpoints_config_test.go new file mode 100644 index 00000000000..ac3c4052258 --- /dev/null +++ b/service/migrationhubrefactorspaces/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package migrationhubrefactorspaces + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub-refactor-spaces.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub-refactor-spaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + expectURL: aws.String("https://env-migration-hub-refactor-spaces.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub-refactor-spaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + expectURL: aws.String("http://config-migration-hub-refactor-spaces.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-migration-hub-refactor-spaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migration-hub-refactor-spaces.dev", + clientEndpoint: aws.String("https://client-migration-hub-refactor-spaces.dev"), + expectURL: aws.String("https://client-migration-hub-refactor-spaces.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MIGRATION_HUB_REFACTOR_SPACES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/migrationhubrefactorspaces/generated.json b/service/migrationhubrefactorspaces/generated.json index e92bd9a705f..ad261b7d7b4 100644 --- a/service/migrationhubrefactorspaces/generated.json +++ b/service/migrationhubrefactorspaces/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/migrationhubrefactorspaces/go.mod b/service/migrationhubrefactorspaces/go.mod index 0480f2fce05..2bfecee65b5 100644 --- a/service/migrationhubrefactorspaces/go.mod +++ b/service/migrationhubrefactorspaces/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/migrationhubrefactorspaces/go.sum b/service/migrationhubrefactorspaces/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/migrationhubrefactorspaces/go.sum +++ b/service/migrationhubrefactorspaces/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/migrationhubstrategy/api_client.go b/service/migrationhubstrategy/api_client.go index 7c077d9832d..bd06fddcffb 100644 --- a/service/migrationhubstrategy/api_client.go +++ b/service/migrationhubstrategy/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/migrationhubstrategy/endpoints.go b/service/migrationhubstrategy/endpoints.go index a62ef844f72..b4f088da0e2 100644 --- a/service/migrationhubstrategy/endpoints.go +++ b/service/migrationhubstrategy/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/migrationhubstrategy/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MIGRATIONHUBSTRATEGY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MigrationHubStrategy", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/migrationhubstrategy/endpoints_config_test.go b/service/migrationhubstrategy/endpoints_config_test.go new file mode 100644 index 00000000000..94a0a36870c --- /dev/null +++ b/service/migrationhubstrategy/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package migrationhubstrategy + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhubstrategy.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhubstrategy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + expectURL: aws.String("https://env-migrationhubstrategy.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhubstrategy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + expectURL: aws.String("http://config-migrationhubstrategy.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-migrationhubstrategy.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-migrationhubstrategy.dev", + clientEndpoint: aws.String("https://client-migrationhubstrategy.dev"), + expectURL: aws.String("https://client-migrationhubstrategy.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MIGRATIONHUBSTRATEGY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/migrationhubstrategy/generated.json b/service/migrationhubstrategy/generated.json index a0a0dfa6b69..15a245c9f43 100644 --- a/service/migrationhubstrategy/generated.json +++ b/service/migrationhubstrategy/generated.json @@ -34,6 +34,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/migrationhubstrategy/go.mod b/service/migrationhubstrategy/go.mod index 4b300fabc1a..13ff593a667 100644 --- a/service/migrationhubstrategy/go.mod +++ b/service/migrationhubstrategy/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/migrationhubstrategy/go.sum b/service/migrationhubstrategy/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/migrationhubstrategy/go.sum +++ b/service/migrationhubstrategy/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mobile/api_client.go b/service/mobile/api_client.go index 91cf2d80e9e..3cbf8fdfd55 100644 --- a/service/mobile/api_client.go +++ b/service/mobile/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mobile/endpoints.go b/service/mobile/endpoints.go index 1449a7e0d1b..c86e12b4708 100644 --- a/service/mobile/endpoints.go +++ b/service/mobile/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mobile/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MOBILE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Mobile", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mobile/endpoints_config_test.go b/service/mobile/endpoints_config_test.go new file mode 100644 index 00000000000..e47527a468e --- /dev/null +++ b/service/mobile/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mobile + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mobile.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mobile.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + expectURL: aws.String("https://env-mobile.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mobile.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + expectURL: aws.String("http://config-mobile.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mobile.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mobile.dev", + clientEndpoint: aws.String("https://client-mobile.dev"), + expectURL: aws.String("https://client-mobile.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MOBILE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mobile/generated.json b/service/mobile/generated.json index da65acf107a..c15a09b1490 100644 --- a/service/mobile/generated.json +++ b/service/mobile/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mobile/go.mod b/service/mobile/go.mod index 7d0c65d7e30..4914bf228ba 100644 --- a/service/mobile/go.mod +++ b/service/mobile/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mobile/go.sum b/service/mobile/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mobile/go.sum +++ b/service/mobile/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mq/api_client.go b/service/mq/api_client.go index 969703b70b7..500763a2737 100644 --- a/service/mq/api_client.go +++ b/service/mq/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mq/endpoints.go b/service/mq/endpoints.go index a18d2380116..113d95631c7 100644 --- a/service/mq/endpoints.go +++ b/service/mq/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mq/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MQ") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "mq", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mq/endpoints_config_test.go b/service/mq/endpoints_config_test.go new file mode 100644 index 00000000000..a2946f20855 --- /dev/null +++ b/service/mq/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mq + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mq.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mq.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + expectURL: aws.String("https://env-mq.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mq.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + expectURL: aws.String("http://config-mq.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mq.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mq.dev", + clientEndpoint: aws.String("https://client-mq.dev"), + expectURL: aws.String("https://client-mq.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MQ", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mq/generated.json b/service/mq/generated.json index 4c938968783..91fb903e0a5 100644 --- a/service/mq/generated.json +++ b/service/mq/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mq/go.mod b/service/mq/go.mod index 8840a0f8605..17cadac969e 100644 --- a/service/mq/go.mod +++ b/service/mq/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mq/go.sum b/service/mq/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mq/go.sum +++ b/service/mq/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mturk/api_client.go b/service/mturk/api_client.go index 1bcd35288b1..8b0b31e198c 100644 --- a/service/mturk/api_client.go +++ b/service/mturk/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mturk/endpoints.go b/service/mturk/endpoints.go index a0ece64452a..6fc5dfd5e2a 100644 --- a/service/mturk/endpoints.go +++ b/service/mturk/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mturk/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MTURK") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MTurk", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mturk/endpoints_config_test.go b/service/mturk/endpoints_config_test.go new file mode 100644 index 00000000000..b53de29dd8f --- /dev/null +++ b/service/mturk/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mturk + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mturk.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mturk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + expectURL: aws.String("https://env-mturk.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mturk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + expectURL: aws.String("http://config-mturk.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mturk.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mturk.dev", + clientEndpoint: aws.String("https://client-mturk.dev"), + expectURL: aws.String("https://client-mturk.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MTURK", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mturk/generated.json b/service/mturk/generated.json index 43397f2af13..37640a3a37c 100644 --- a/service/mturk/generated.json +++ b/service/mturk/generated.json @@ -51,6 +51,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mturk/go.mod b/service/mturk/go.mod index 76daaf56461..a7c5471abfd 100644 --- a/service/mturk/go.mod +++ b/service/mturk/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mturk/go.sum b/service/mturk/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mturk/go.sum +++ b/service/mturk/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/mwaa/api_client.go b/service/mwaa/api_client.go index 42bb3af1579..d67c36b394d 100644 --- a/service/mwaa/api_client.go +++ b/service/mwaa/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/mwaa/endpoints.go b/service/mwaa/endpoints.go index 83fd95bb35e..976c7592f9e 100644 --- a/service/mwaa/endpoints.go +++ b/service/mwaa/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/mwaa/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_MWAA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "MWAA", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/mwaa/endpoints_config_test.go b/service/mwaa/endpoints_config_test.go new file mode 100644 index 00000000000..7a9ed277dde --- /dev/null +++ b/service/mwaa/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package mwaa + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mwaa.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-mwaa.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + expectURL: aws.String("https://env-mwaa.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-mwaa.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + expectURL: aws.String("http://config-mwaa.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-mwaa.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-mwaa.dev", + clientEndpoint: aws.String("https://client-mwaa.dev"), + expectURL: aws.String("https://client-mwaa.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_MWAA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/mwaa/generated.json b/service/mwaa/generated.json index 037bb3d5300..ce72c0157c8 100644 --- a/service/mwaa/generated.json +++ b/service/mwaa/generated.json @@ -23,6 +23,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/mwaa/go.mod b/service/mwaa/go.mod index 648005af40e..1dd73ed231e 100644 --- a/service/mwaa/go.mod +++ b/service/mwaa/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/mwaa/go.sum b/service/mwaa/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/mwaa/go.sum +++ b/service/mwaa/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/neptune/api_client.go b/service/neptune/api_client.go index 2315f059004..e6a6cac0020 100644 --- a/service/neptune/api_client.go +++ b/service/neptune/api_client.go @@ -297,6 +297,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/neptune/endpoints.go b/service/neptune/endpoints.go index 2543ee9f01b..3427910b78d 100644 --- a/service/neptune/endpoints.go +++ b/service/neptune/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/neptune/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_NEPTUNE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Neptune", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/neptune/endpoints_config_test.go b/service/neptune/endpoints_config_test.go new file mode 100644 index 00000000000..513f725d93c --- /dev/null +++ b/service/neptune/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package neptune + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptune.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptune.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + expectURL: aws.String("https://env-neptune.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptune.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + expectURL: aws.String("http://config-neptune.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptune.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptune.dev", + clientEndpoint: aws.String("https://client-neptune.dev"), + expectURL: aws.String("https://client-neptune.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_NEPTUNE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/neptune/generated.json b/service/neptune/generated.json index 918b4c19d3e..f796f9c3b84 100644 --- a/service/neptune/generated.json +++ b/service/neptune/generated.json @@ -85,6 +85,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/neptune/go.mod b/service/neptune/go.mod index 77622faefa4..2e4f505332e 100644 --- a/service/neptune/go.mod +++ b/service/neptune/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -14,8 +15,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/neptune/go.sum b/service/neptune/go.sum index ef5982af332..c64803e87e7 100644 --- a/service/neptune/go.sum +++ b/service/neptune/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/neptunedata/api_client.go b/service/neptunedata/api_client.go index aa73d8b569b..6e87d6dc6a8 100644 --- a/service/neptunedata/api_client.go +++ b/service/neptunedata/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/neptunedata/endpoints.go b/service/neptunedata/endpoints.go index 8649995743d..51b698736e4 100644 --- a/service/neptunedata/endpoints.go +++ b/service/neptunedata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/neptunedata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_NEPTUNEDATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "neptunedata", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/neptunedata/endpoints_config_test.go b/service/neptunedata/endpoints_config_test.go new file mode 100644 index 00000000000..d7af057f74f --- /dev/null +++ b/service/neptunedata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package neptunedata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptunedata.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptunedata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + expectURL: aws.String("https://env-neptunedata.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptunedata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + expectURL: aws.String("http://config-neptunedata.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-neptunedata.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-neptunedata.dev", + clientEndpoint: aws.String("https://client-neptunedata.dev"), + expectURL: aws.String("https://client-neptunedata.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_NEPTUNEDATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/neptunedata/generated.json b/service/neptunedata/generated.json index 4282660fe3b..8dea67ec805 100644 --- a/service/neptunedata/generated.json +++ b/service/neptunedata/generated.json @@ -57,6 +57,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/neptunedata/go.mod b/service/neptunedata/go.mod index 951872a8431..8e532e8a423 100644 --- a/service/neptunedata/go.mod +++ b/service/neptunedata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/neptunedata/go.sum b/service/neptunedata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/neptunedata/go.sum +++ b/service/neptunedata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/networkfirewall/api_client.go b/service/networkfirewall/api_client.go index fc3283e21bf..58f9b37ad96 100644 --- a/service/networkfirewall/api_client.go +++ b/service/networkfirewall/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/networkfirewall/endpoints.go b/service/networkfirewall/endpoints.go index 32b67fe6155..9c47007e5c0 100644 --- a/service/networkfirewall/endpoints.go +++ b/service/networkfirewall/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/networkfirewall/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_NETWORK_FIREWALL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Network Firewall", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/networkfirewall/endpoints_config_test.go b/service/networkfirewall/endpoints_config_test.go new file mode 100644 index 00000000000..cb13d466785 --- /dev/null +++ b/service/networkfirewall/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package networkfirewall + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-network-firewall.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-network-firewall.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + expectURL: aws.String("https://env-network-firewall.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-network-firewall.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + expectURL: aws.String("http://config-network-firewall.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-network-firewall.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-network-firewall.dev", + clientEndpoint: aws.String("https://client-network-firewall.dev"), + expectURL: aws.String("https://client-network-firewall.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_NETWORK_FIREWALL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/networkfirewall/generated.json b/service/networkfirewall/generated.json index 82c82c68cea..cb7690dd1ea 100644 --- a/service/networkfirewall/generated.json +++ b/service/networkfirewall/generated.json @@ -48,6 +48,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/networkfirewall/go.mod b/service/networkfirewall/go.mod index 0f80a10d780..7e0aed73cad 100644 --- a/service/networkfirewall/go.mod +++ b/service/networkfirewall/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/networkfirewall/go.sum b/service/networkfirewall/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/networkfirewall/go.sum +++ b/service/networkfirewall/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/networkmanager/api_client.go b/service/networkmanager/api_client.go index 78c944a381f..98f2926526b 100644 --- a/service/networkmanager/api_client.go +++ b/service/networkmanager/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/networkmanager/endpoints.go b/service/networkmanager/endpoints.go index 095ab5cd084..05b7c6bf2ea 100644 --- a/service/networkmanager/endpoints.go +++ b/service/networkmanager/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/networkmanager/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_NETWORKMANAGER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "NetworkManager", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/networkmanager/endpoints_config_test.go b/service/networkmanager/endpoints_config_test.go new file mode 100644 index 00000000000..b94c5d0f0f1 --- /dev/null +++ b/service/networkmanager/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package networkmanager + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-networkmanager.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-networkmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + expectURL: aws.String("https://env-networkmanager.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-networkmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + expectURL: aws.String("http://config-networkmanager.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-networkmanager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-networkmanager.dev", + clientEndpoint: aws.String("https://client-networkmanager.dev"), + expectURL: aws.String("https://client-networkmanager.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_NETWORKMANAGER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/networkmanager/generated.json b/service/networkmanager/generated.json index ae8acdc2ad9..0f203aa81be 100644 --- a/service/networkmanager/generated.json +++ b/service/networkmanager/generated.json @@ -97,6 +97,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/networkmanager/go.mod b/service/networkmanager/go.mod index 0d2f4e3c225..66eca7810d9 100644 --- a/service/networkmanager/go.mod +++ b/service/networkmanager/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/networkmanager/go.sum b/service/networkmanager/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/networkmanager/go.sum +++ b/service/networkmanager/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/nimble/api_client.go b/service/nimble/api_client.go index 430c2d88493..a769a15de1a 100644 --- a/service/nimble/api_client.go +++ b/service/nimble/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/nimble/endpoints.go b/service/nimble/endpoints.go index 97cbe5f64de..3b8798eb516 100644 --- a/service/nimble/endpoints.go +++ b/service/nimble/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/nimble/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_NIMBLE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "nimble", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/nimble/endpoints_config_test.go b/service/nimble/endpoints_config_test.go new file mode 100644 index 00000000000..8c280477725 --- /dev/null +++ b/service/nimble/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package nimble + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-nimble.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-nimble.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + expectURL: aws.String("https://env-nimble.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-nimble.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + expectURL: aws.String("http://config-nimble.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-nimble.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-nimble.dev", + clientEndpoint: aws.String("https://client-nimble.dev"), + expectURL: aws.String("https://client-nimble.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_NIMBLE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/nimble/generated.json b/service/nimble/generated.json index 47877218b52..d712c38365f 100644 --- a/service/nimble/generated.json +++ b/service/nimble/generated.json @@ -62,6 +62,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/nimble/go.mod b/service/nimble/go.mod index 29715d72300..55e6ffa4919 100644 --- a/service/nimble/go.mod +++ b/service/nimble/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/nimble/go.sum b/service/nimble/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/nimble/go.sum +++ b/service/nimble/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/oam/api_client.go b/service/oam/api_client.go index d0d9e8f3198..348db13503c 100644 --- a/service/oam/api_client.go +++ b/service/oam/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/oam/endpoints.go b/service/oam/endpoints.go index 5b991847524..1ffc68fdd61 100644 --- a/service/oam/endpoints.go +++ b/service/oam/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/oam/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OAM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OAM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/oam/endpoints_config_test.go b/service/oam/endpoints_config_test.go new file mode 100644 index 00000000000..e42cccd06d0 --- /dev/null +++ b/service/oam/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package oam + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-oam.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-oam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + expectURL: aws.String("https://env-oam.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-oam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + expectURL: aws.String("http://config-oam.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-oam.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-oam.dev", + clientEndpoint: aws.String("https://client-oam.dev"), + expectURL: aws.String("https://client-oam.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OAM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/oam/generated.json b/service/oam/generated.json index a9bc284b81e..fb9c770f382 100644 --- a/service/oam/generated.json +++ b/service/oam/generated.json @@ -27,6 +27,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/oam/go.mod b/service/oam/go.mod index 1463b280be1..4d30690f5be 100644 --- a/service/oam/go.mod +++ b/service/oam/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/oam/go.sum b/service/oam/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/oam/go.sum +++ b/service/oam/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/omics/api_client.go b/service/omics/api_client.go index 7c14cd0bfb1..63840452947 100644 --- a/service/omics/api_client.go +++ b/service/omics/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/omics/endpoints.go b/service/omics/endpoints.go index 2a7862a878b..edc52c9cd9c 100644 --- a/service/omics/endpoints.go +++ b/service/omics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/omics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OMICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Omics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/omics/endpoints_config_test.go b/service/omics/endpoints_config_test.go new file mode 100644 index 00000000000..a23d9701809 --- /dev/null +++ b/service/omics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package omics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-omics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-omics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + expectURL: aws.String("https://env-omics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-omics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + expectURL: aws.String("http://config-omics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-omics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-omics.dev", + clientEndpoint: aws.String("https://client-omics.dev"), + expectURL: aws.String("https://client-omics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OMICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/omics/generated.json b/service/omics/generated.json index 31bb950b922..4d4d2885d11 100644 --- a/service/omics/generated.json +++ b/service/omics/generated.json @@ -97,6 +97,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/omics/go.mod b/service/omics/go.mod index 2266506d8ee..1d34a93ab0e 100644 --- a/service/omics/go.mod +++ b/service/omics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/omics/go.sum b/service/omics/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/omics/go.sum +++ b/service/omics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/opensearch/api_client.go b/service/opensearch/api_client.go index 6a29854fc1d..4e0d425f86c 100644 --- a/service/opensearch/api_client.go +++ b/service/opensearch/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/opensearch/endpoints.go b/service/opensearch/endpoints.go index 70a78d4a8de..d2f30dacf8b 100644 --- a/service/opensearch/endpoints.go +++ b/service/opensearch/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/opensearch/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OPENSEARCH") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OpenSearch", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/opensearch/endpoints_config_test.go b/service/opensearch/endpoints_config_test.go new file mode 100644 index 00000000000..73c93b0a235 --- /dev/null +++ b/service/opensearch/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package opensearch + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearch.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + expectURL: aws.String("https://env-opensearch.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + expectURL: aws.String("http://config-opensearch.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearch.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearch.dev", + clientEndpoint: aws.String("https://client-opensearch.dev"), + expectURL: aws.String("https://client-opensearch.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OPENSEARCH", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/opensearch/generated.json b/service/opensearch/generated.json index 7943a4a1643..3af4a30602a 100644 --- a/service/opensearch/generated.json +++ b/service/opensearch/generated.json @@ -69,6 +69,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/opensearch/go.mod b/service/opensearch/go.mod index d0603759f62..565bee478c6 100644 --- a/service/opensearch/go.mod +++ b/service/opensearch/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/opensearch/go.sum b/service/opensearch/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/opensearch/go.sum +++ b/service/opensearch/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/opensearchserverless/api_client.go b/service/opensearchserverless/api_client.go index 0771d28ec7f..2ac88b05179 100644 --- a/service/opensearchserverless/api_client.go +++ b/service/opensearchserverless/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/opensearchserverless/endpoints.go b/service/opensearchserverless/endpoints.go index 0adc5094f35..e3e235643cc 100644 --- a/service/opensearchserverless/endpoints.go +++ b/service/opensearchserverless/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/opensearchserverless/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OPENSEARCHSERVERLESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OpenSearchServerless", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/opensearchserverless/endpoints_config_test.go b/service/opensearchserverless/endpoints_config_test.go new file mode 100644 index 00000000000..7eb1c19337d --- /dev/null +++ b/service/opensearchserverless/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package opensearchserverless + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearchserverless.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearchserverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + expectURL: aws.String("https://env-opensearchserverless.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearchserverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + expectURL: aws.String("http://config-opensearchserverless.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-opensearchserverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opensearchserverless.dev", + clientEndpoint: aws.String("https://client-opensearchserverless.dev"), + expectURL: aws.String("https://client-opensearchserverless.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OPENSEARCHSERVERLESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/opensearchserverless/generated.json b/service/opensearchserverless/generated.json index b62fb2a149c..b978c922028 100644 --- a/service/opensearchserverless/generated.json +++ b/service/opensearchserverless/generated.json @@ -51,6 +51,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/opensearchserverless/go.mod b/service/opensearchserverless/go.mod index 124df350062..dc8a5ba89be 100644 --- a/service/opensearchserverless/go.mod +++ b/service/opensearchserverless/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/opensearchserverless/go.sum b/service/opensearchserverless/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/opensearchserverless/go.sum +++ b/service/opensearchserverless/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/opsworks/api_client.go b/service/opsworks/api_client.go index 309b2a072ca..ef4776eb1f7 100644 --- a/service/opsworks/api_client.go +++ b/service/opsworks/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/opsworks/endpoints.go b/service/opsworks/endpoints.go index 9d71475acb9..b1a5890748c 100644 --- a/service/opsworks/endpoints.go +++ b/service/opsworks/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/opsworks/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OPSWORKS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OpsWorks", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/opsworks/endpoints_config_test.go b/service/opsworks/endpoints_config_test.go new file mode 100644 index 00000000000..669468635b2 --- /dev/null +++ b/service/opsworks/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package opsworks + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworks.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + expectURL: aws.String("https://env-opsworks.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + expectURL: aws.String("http://config-opsworks.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworks.dev", + clientEndpoint: aws.String("https://client-opsworks.dev"), + expectURL: aws.String("https://client-opsworks.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OPSWORKS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/opsworks/generated.json b/service/opsworks/generated.json index 03cf30fcc37..cee42de6f22 100644 --- a/service/opsworks/generated.json +++ b/service/opsworks/generated.json @@ -87,6 +87,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/opsworks/go.mod b/service/opsworks/go.mod index 0b1557755d1..2f8a8e198dd 100644 --- a/service/opsworks/go.mod +++ b/service/opsworks/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/opsworks/go.sum b/service/opsworks/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/opsworks/go.sum +++ b/service/opsworks/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/opsworkscm/api_client.go b/service/opsworkscm/api_client.go index 083c327e831..ec032aa172a 100644 --- a/service/opsworkscm/api_client.go +++ b/service/opsworkscm/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/opsworkscm/endpoints.go b/service/opsworkscm/endpoints.go index 38eade5efb6..bd9d899ea31 100644 --- a/service/opsworkscm/endpoints.go +++ b/service/opsworkscm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/opsworkscm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OPSWORKSCM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OpsWorksCM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/opsworkscm/endpoints_config_test.go b/service/opsworkscm/endpoints_config_test.go new file mode 100644 index 00000000000..0296f661d7f --- /dev/null +++ b/service/opsworkscm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package opsworkscm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworkscm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworkscm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + expectURL: aws.String("https://env-opsworkscm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworkscm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + expectURL: aws.String("http://config-opsworkscm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-opsworkscm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-opsworkscm.dev", + clientEndpoint: aws.String("https://client-opsworkscm.dev"), + expectURL: aws.String("https://client-opsworkscm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OPSWORKSCM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/opsworkscm/generated.json b/service/opsworkscm/generated.json index 3c2eaa73090..427951f0ea9 100644 --- a/service/opsworkscm/generated.json +++ b/service/opsworkscm/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/opsworkscm/go.mod b/service/opsworkscm/go.mod index 637bba920c3..fa55c2ba492 100644 --- a/service/opsworkscm/go.mod +++ b/service/opsworkscm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/opsworkscm/go.sum b/service/opsworkscm/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/opsworkscm/go.sum +++ b/service/opsworkscm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/organizations/api_client.go b/service/organizations/api_client.go index 57b309171b4..649f0e18340 100644 --- a/service/organizations/api_client.go +++ b/service/organizations/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/organizations/endpoints.go b/service/organizations/endpoints.go index ae6431159df..656347170e0 100644 --- a/service/organizations/endpoints.go +++ b/service/organizations/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/organizations/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ORGANIZATIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Organizations", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/organizations/endpoints_config_test.go b/service/organizations/endpoints_config_test.go new file mode 100644 index 00000000000..6bf57b4c6b9 --- /dev/null +++ b/service/organizations/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package organizations + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-organizations.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-organizations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + expectURL: aws.String("https://env-organizations.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-organizations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + expectURL: aws.String("http://config-organizations.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-organizations.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-organizations.dev", + clientEndpoint: aws.String("https://client-organizations.dev"), + expectURL: aws.String("https://client-organizations.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ORGANIZATIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/organizations/generated.json b/service/organizations/generated.json index 1b22f47bbc6..0725f81f96f 100644 --- a/service/organizations/generated.json +++ b/service/organizations/generated.json @@ -67,6 +67,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/organizations/go.mod b/service/organizations/go.mod index 22d18c6719d..74b1bcbb376 100644 --- a/service/organizations/go.mod +++ b/service/organizations/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/organizations/go.sum b/service/organizations/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/organizations/go.sum +++ b/service/organizations/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/osis/api_client.go b/service/osis/api_client.go index 625d953234b..7ae2fa19359 100644 --- a/service/osis/api_client.go +++ b/service/osis/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/osis/endpoints.go b/service/osis/endpoints.go index 5c789d84d67..79e4e5fbae9 100644 --- a/service/osis/endpoints.go +++ b/service/osis/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/osis/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OSIS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "OSIS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/osis/endpoints_config_test.go b/service/osis/endpoints_config_test.go new file mode 100644 index 00000000000..8e719806206 --- /dev/null +++ b/service/osis/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package osis + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-osis.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-osis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + expectURL: aws.String("https://env-osis.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-osis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + expectURL: aws.String("http://config-osis.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-osis.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-osis.dev", + clientEndpoint: aws.String("https://client-osis.dev"), + expectURL: aws.String("https://client-osis.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OSIS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/osis/generated.json b/service/osis/generated.json index 96edbc34e85..1026c528f8a 100644 --- a/service/osis/generated.json +++ b/service/osis/generated.json @@ -26,6 +26,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/osis/go.mod b/service/osis/go.mod index b576212d66d..bfd1d9aa7ef 100644 --- a/service/osis/go.mod +++ b/service/osis/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/osis/go.sum b/service/osis/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/osis/go.sum +++ b/service/osis/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/outposts/api_client.go b/service/outposts/api_client.go index 713145265cc..3e30ec6bfb4 100644 --- a/service/outposts/api_client.go +++ b/service/outposts/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/outposts/endpoints.go b/service/outposts/endpoints.go index 94ee44d248e..1741031eeae 100644 --- a/service/outposts/endpoints.go +++ b/service/outposts/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/outposts/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_OUTPOSTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Outposts", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/outposts/endpoints_config_test.go b/service/outposts/endpoints_config_test.go new file mode 100644 index 00000000000..d0c4ae86afc --- /dev/null +++ b/service/outposts/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package outposts + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-outposts.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + expectURL: aws.String("https://env-outposts.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + expectURL: aws.String("http://config-outposts.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-outposts.dev", + clientEndpoint: aws.String("https://client-outposts.dev"), + expectURL: aws.String("https://client-outposts.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_OUTPOSTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/outposts/generated.json b/service/outposts/generated.json index 7697eb50c24..5f24b16a5d0 100644 --- a/service/outposts/generated.json +++ b/service/outposts/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/outposts/go.mod b/service/outposts/go.mod index 28cabe16e73..0f917ee5c02 100644 --- a/service/outposts/go.mod +++ b/service/outposts/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/outposts/go.sum b/service/outposts/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/outposts/go.sum +++ b/service/outposts/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/panorama/api_client.go b/service/panorama/api_client.go index 30af036705a..2c95c51638d 100644 --- a/service/panorama/api_client.go +++ b/service/panorama/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/panorama/endpoints.go b/service/panorama/endpoints.go index 0b780ed593f..0a8300df8ad 100644 --- a/service/panorama/endpoints.go +++ b/service/panorama/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/panorama/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PANORAMA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Panorama", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/panorama/endpoints_config_test.go b/service/panorama/endpoints_config_test.go new file mode 100644 index 00000000000..6d485572a7a --- /dev/null +++ b/service/panorama/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package panorama + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-panorama.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-panorama.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + expectURL: aws.String("https://env-panorama.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-panorama.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + expectURL: aws.String("http://config-panorama.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-panorama.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-panorama.dev", + clientEndpoint: aws.String("https://client-panorama.dev"), + expectURL: aws.String("https://client-panorama.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PANORAMA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/panorama/generated.json b/service/panorama/generated.json index 38bf538c0cb..f3be107a84b 100644 --- a/service/panorama/generated.json +++ b/service/panorama/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/panorama/go.mod b/service/panorama/go.mod index 3ee1780c2a3..c548e61902e 100644 --- a/service/panorama/go.mod +++ b/service/panorama/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/panorama/go.sum b/service/panorama/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/panorama/go.sum +++ b/service/panorama/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/paymentcryptography/api_client.go b/service/paymentcryptography/api_client.go index 680beaab6c3..03a6842132e 100644 --- a/service/paymentcryptography/api_client.go +++ b/service/paymentcryptography/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/paymentcryptography/endpoints.go b/service/paymentcryptography/endpoints.go index fe2a7fc97a1..774ce0e7db0 100644 --- a/service/paymentcryptography/endpoints.go +++ b/service/paymentcryptography/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/paymentcryptography/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PAYMENT_CRYPTOGRAPHY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Payment Cryptography", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/paymentcryptography/endpoints_config_test.go b/service/paymentcryptography/endpoints_config_test.go new file mode 100644 index 00000000000..d8d0bc5cca8 --- /dev/null +++ b/service/paymentcryptography/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package paymentcryptography + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + expectURL: aws.String("https://env-payment-cryptography.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + expectURL: aws.String("http://config-payment-cryptography.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography.dev", + clientEndpoint: aws.String("https://client-payment-cryptography.dev"), + expectURL: aws.String("https://client-payment-cryptography.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PAYMENT_CRYPTOGRAPHY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/paymentcryptography/generated.json b/service/paymentcryptography/generated.json index 1b8ce0a9290..8aae4598a59 100644 --- a/service/paymentcryptography/generated.json +++ b/service/paymentcryptography/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/paymentcryptography/go.mod b/service/paymentcryptography/go.mod index 7516054e055..82d02ef102a 100644 --- a/service/paymentcryptography/go.mod +++ b/service/paymentcryptography/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/paymentcryptography/go.sum b/service/paymentcryptography/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/paymentcryptography/go.sum +++ b/service/paymentcryptography/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/paymentcryptographydata/api_client.go b/service/paymentcryptographydata/api_client.go index 06086960877..291f919dacf 100644 --- a/service/paymentcryptographydata/api_client.go +++ b/service/paymentcryptographydata/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/paymentcryptographydata/endpoints.go b/service/paymentcryptographydata/endpoints.go index ed1289c298d..a46b2ad1546 100644 --- a/service/paymentcryptographydata/endpoints.go +++ b/service/paymentcryptographydata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/paymentcryptographydata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PAYMENT_CRYPTOGRAPHY_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Payment Cryptography Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/paymentcryptographydata/endpoints_config_test.go b/service/paymentcryptographydata/endpoints_config_test.go new file mode 100644 index 00000000000..1b7073e53ea --- /dev/null +++ b/service/paymentcryptographydata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package paymentcryptographydata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + expectURL: aws.String("https://env-payment-cryptography-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + expectURL: aws.String("http://config-payment-cryptography-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-payment-cryptography-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-payment-cryptography-data.dev", + clientEndpoint: aws.String("https://client-payment-cryptography-data.dev"), + expectURL: aws.String("https://client-payment-cryptography-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PAYMENT_CRYPTOGRAPHY_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/paymentcryptographydata/generated.json b/service/paymentcryptographydata/generated.json index dfe692398ad..925cec4109c 100644 --- a/service/paymentcryptographydata/generated.json +++ b/service/paymentcryptographydata/generated.json @@ -23,6 +23,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/paymentcryptographydata/go.mod b/service/paymentcryptographydata/go.mod index 0af307e12ec..3ba06cb1ae1 100644 --- a/service/paymentcryptographydata/go.mod +++ b/service/paymentcryptographydata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/paymentcryptographydata/go.sum b/service/paymentcryptographydata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/paymentcryptographydata/go.sum +++ b/service/paymentcryptographydata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pcaconnectorad/api_client.go b/service/pcaconnectorad/api_client.go index a673be15eb2..08af0182e21 100644 --- a/service/pcaconnectorad/api_client.go +++ b/service/pcaconnectorad/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pcaconnectorad/endpoints.go b/service/pcaconnectorad/endpoints.go index 158065a60a8..d734a341e59 100644 --- a/service/pcaconnectorad/endpoints.go +++ b/service/pcaconnectorad/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pcaconnectorad/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PCA_CONNECTOR_AD") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pca Connector Ad", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pcaconnectorad/endpoints_config_test.go b/service/pcaconnectorad/endpoints_config_test.go new file mode 100644 index 00000000000..ab46330ae1e --- /dev/null +++ b/service/pcaconnectorad/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pcaconnectorad + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pca-connector-ad.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pca-connector-ad.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + expectURL: aws.String("https://env-pca-connector-ad.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pca-connector-ad.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + expectURL: aws.String("http://config-pca-connector-ad.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pca-connector-ad.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pca-connector-ad.dev", + clientEndpoint: aws.String("https://client-pca-connector-ad.dev"), + expectURL: aws.String("https://client-pca-connector-ad.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PCA_CONNECTOR_AD", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pcaconnectorad/generated.json b/service/pcaconnectorad/generated.json index 869654340e3..639ae264a1f 100644 --- a/service/pcaconnectorad/generated.json +++ b/service/pcaconnectorad/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pcaconnectorad/go.mod b/service/pcaconnectorad/go.mod index 1279c62ac35..76ad87aaac8 100644 --- a/service/pcaconnectorad/go.mod +++ b/service/pcaconnectorad/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pcaconnectorad/go.sum b/service/pcaconnectorad/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pcaconnectorad/go.sum +++ b/service/pcaconnectorad/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/personalize/api_client.go b/service/personalize/api_client.go index 2c33cad1e6f..e8738c2859a 100644 --- a/service/personalize/api_client.go +++ b/service/personalize/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/personalize/endpoints.go b/service/personalize/endpoints.go index a0007d1154c..5e028a2a924 100644 --- a/service/personalize/endpoints.go +++ b/service/personalize/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/personalize/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PERSONALIZE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Personalize", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/personalize/endpoints_config_test.go b/service/personalize/endpoints_config_test.go new file mode 100644 index 00000000000..686d4d1956c --- /dev/null +++ b/service/personalize/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package personalize + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + expectURL: aws.String("https://env-personalize.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + expectURL: aws.String("http://config-personalize.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize.dev", + clientEndpoint: aws.String("https://client-personalize.dev"), + expectURL: aws.String("https://client-personalize.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PERSONALIZE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/personalize/generated.json b/service/personalize/generated.json index 2a5785eb161..3dea04132d7 100644 --- a/service/personalize/generated.json +++ b/service/personalize/generated.json @@ -79,6 +79,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/personalize/go.mod b/service/personalize/go.mod index 89e5db3b4b2..8dcf13d7f60 100644 --- a/service/personalize/go.mod +++ b/service/personalize/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/personalize/go.sum b/service/personalize/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/personalize/go.sum +++ b/service/personalize/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/personalizeevents/api_client.go b/service/personalizeevents/api_client.go index 9d8a561c4ed..6f08d530245 100644 --- a/service/personalizeevents/api_client.go +++ b/service/personalizeevents/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/personalizeevents/endpoints.go b/service/personalizeevents/endpoints.go index f1ef174a4f3..2518e3b1f18 100644 --- a/service/personalizeevents/endpoints.go +++ b/service/personalizeevents/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/personalizeevents/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PERSONALIZE_EVENTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Personalize Events", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/personalizeevents/endpoints_config_test.go b/service/personalizeevents/endpoints_config_test.go new file mode 100644 index 00000000000..5031472ce28 --- /dev/null +++ b/service/personalizeevents/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package personalizeevents + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-events.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + expectURL: aws.String("https://env-personalize-events.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + expectURL: aws.String("http://config-personalize-events.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-events.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-events.dev", + clientEndpoint: aws.String("https://client-personalize-events.dev"), + expectURL: aws.String("https://client-personalize-events.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PERSONALIZE_EVENTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/personalizeevents/generated.json b/service/personalizeevents/generated.json index 21ec33f0aae..0252be4cf48 100644 --- a/service/personalizeevents/generated.json +++ b/service/personalizeevents/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/personalizeevents/go.mod b/service/personalizeevents/go.mod index b540a086eaa..3d2d7aa42cb 100644 --- a/service/personalizeevents/go.mod +++ b/service/personalizeevents/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/personalizeevents/go.sum b/service/personalizeevents/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/personalizeevents/go.sum +++ b/service/personalizeevents/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/personalizeruntime/api_client.go b/service/personalizeruntime/api_client.go index 93b54dded25..650f5726ec7 100644 --- a/service/personalizeruntime/api_client.go +++ b/service/personalizeruntime/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/personalizeruntime/endpoints.go b/service/personalizeruntime/endpoints.go index a21136f31d2..1b45393d7b3 100644 --- a/service/personalizeruntime/endpoints.go +++ b/service/personalizeruntime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/personalizeruntime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PERSONALIZE_RUNTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Personalize Runtime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/personalizeruntime/endpoints_config_test.go b/service/personalizeruntime/endpoints_config_test.go new file mode 100644 index 00000000000..fead705b9c0 --- /dev/null +++ b/service/personalizeruntime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package personalizeruntime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-runtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + expectURL: aws.String("https://env-personalize-runtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + expectURL: aws.String("http://config-personalize-runtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-personalize-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-personalize-runtime.dev", + clientEndpoint: aws.String("https://client-personalize-runtime.dev"), + expectURL: aws.String("https://client-personalize-runtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PERSONALIZE_RUNTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/personalizeruntime/generated.json b/service/personalizeruntime/generated.json index fc203a223c7..aac06546537 100644 --- a/service/personalizeruntime/generated.json +++ b/service/personalizeruntime/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/personalizeruntime/go.mod b/service/personalizeruntime/go.mod index f43fa52630a..c42ce7ed497 100644 --- a/service/personalizeruntime/go.mod +++ b/service/personalizeruntime/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/personalizeruntime/go.sum b/service/personalizeruntime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/personalizeruntime/go.sum +++ b/service/personalizeruntime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pi/api_client.go b/service/pi/api_client.go index 62e7ca1bfd0..8b8371e229b 100644 --- a/service/pi/api_client.go +++ b/service/pi/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pi/endpoints.go b/service/pi/endpoints.go index 01bfa8b577b..75f1d467a99 100644 --- a/service/pi/endpoints.go +++ b/service/pi/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pi/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PI") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "PI", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pi/endpoints_config_test.go b/service/pi/endpoints_config_test.go new file mode 100644 index 00000000000..a7c1dae904a --- /dev/null +++ b/service/pi/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pi + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pi.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + expectURL: aws.String("https://env-pi.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + expectURL: aws.String("http://config-pi.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pi.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pi.dev", + clientEndpoint: aws.String("https://client-pi.dev"), + expectURL: aws.String("https://client-pi.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PI", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pi/generated.json b/service/pi/generated.json index de6877d1c74..c6ed4170b48 100644 --- a/service/pi/generated.json +++ b/service/pi/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pi/go.mod b/service/pi/go.mod index 615ae55e016..a945f9acca6 100644 --- a/service/pi/go.mod +++ b/service/pi/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pi/go.sum b/service/pi/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pi/go.sum +++ b/service/pi/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pinpoint/api_client.go b/service/pinpoint/api_client.go index 7ac7cc7fa2f..ddbc20e2202 100644 --- a/service/pinpoint/api_client.go +++ b/service/pinpoint/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pinpoint/endpoints.go b/service/pinpoint/endpoints.go index 9608665fc51..deb2662149c 100644 --- a/service/pinpoint/endpoints.go +++ b/service/pinpoint/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pinpoint/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PINPOINT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pinpoint", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pinpoint/endpoints_config_test.go b/service/pinpoint/endpoints_config_test.go new file mode 100644 index 00000000000..24cf5d0aef9 --- /dev/null +++ b/service/pinpoint/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pinpoint + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + expectURL: aws.String("https://env-pinpoint.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + expectURL: aws.String("http://config-pinpoint.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint.dev", + clientEndpoint: aws.String("https://client-pinpoint.dev"), + expectURL: aws.String("https://client-pinpoint.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PINPOINT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pinpoint/generated.json b/service/pinpoint/generated.json index dc4b1285eaa..f675d24996f 100644 --- a/service/pinpoint/generated.json +++ b/service/pinpoint/generated.json @@ -134,6 +134,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pinpoint/go.mod b/service/pinpoint/go.mod index b6201c3c2fb..03822372ffa 100644 --- a/service/pinpoint/go.mod +++ b/service/pinpoint/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pinpoint/go.sum b/service/pinpoint/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pinpoint/go.sum +++ b/service/pinpoint/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pinpointemail/api_client.go b/service/pinpointemail/api_client.go index 54c3bd30b52..f2daa01ceb0 100644 --- a/service/pinpointemail/api_client.go +++ b/service/pinpointemail/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pinpointemail/endpoints.go b/service/pinpointemail/endpoints.go index b0e0a5c40d4..3d9b1931e35 100644 --- a/service/pinpointemail/endpoints.go +++ b/service/pinpointemail/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pinpointemail/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PINPOINT_EMAIL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pinpoint Email", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pinpointemail/endpoints_config_test.go b/service/pinpointemail/endpoints_config_test.go new file mode 100644 index 00000000000..df6e1329f01 --- /dev/null +++ b/service/pinpointemail/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pinpointemail + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-email.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-email.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + expectURL: aws.String("https://env-pinpoint-email.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-email.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + expectURL: aws.String("http://config-pinpoint-email.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-email.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-email.dev", + clientEndpoint: aws.String("https://client-pinpoint-email.dev"), + expectURL: aws.String("https://client-pinpoint-email.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PINPOINT_EMAIL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pinpointemail/generated.json b/service/pinpointemail/generated.json index be034b2dd2c..5fd10361518 100644 --- a/service/pinpointemail/generated.json +++ b/service/pinpointemail/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pinpointemail/go.mod b/service/pinpointemail/go.mod index 939a41b4a98..bd4c7be5953 100644 --- a/service/pinpointemail/go.mod +++ b/service/pinpointemail/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pinpointemail/go.sum b/service/pinpointemail/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pinpointemail/go.sum +++ b/service/pinpointemail/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pinpointsmsvoice/api_client.go b/service/pinpointsmsvoice/api_client.go index 07544dbdbf7..8aaad49306c 100644 --- a/service/pinpointsmsvoice/api_client.go +++ b/service/pinpointsmsvoice/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pinpointsmsvoice/endpoints.go b/service/pinpointsmsvoice/endpoints.go index ca5c9c0650d..45b2179144a 100644 --- a/service/pinpointsmsvoice/endpoints.go +++ b/service/pinpointsmsvoice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pinpointsmsvoice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PINPOINT_SMS_VOICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pinpoint SMS Voice", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pinpointsmsvoice/endpoints_config_test.go b/service/pinpointsmsvoice/endpoints_config_test.go new file mode 100644 index 00000000000..3970bfba64b --- /dev/null +++ b/service/pinpointsmsvoice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pinpointsmsvoice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + expectURL: aws.String("https://env-pinpoint-sms-voice.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + expectURL: aws.String("http://config-pinpoint-sms-voice.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice.dev", + clientEndpoint: aws.String("https://client-pinpoint-sms-voice.dev"), + expectURL: aws.String("https://client-pinpoint-sms-voice.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PINPOINT_SMS_VOICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pinpointsmsvoice/generated.json b/service/pinpointsmsvoice/generated.json index 6290455ba3d..8bc2eb894cd 100644 --- a/service/pinpointsmsvoice/generated.json +++ b/service/pinpointsmsvoice/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pinpointsmsvoice/go.mod b/service/pinpointsmsvoice/go.mod index 83e23851cb3..3940eafc92e 100644 --- a/service/pinpointsmsvoice/go.mod +++ b/service/pinpointsmsvoice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pinpointsmsvoice/go.sum b/service/pinpointsmsvoice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pinpointsmsvoice/go.sum +++ b/service/pinpointsmsvoice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pinpointsmsvoicev2/api_client.go b/service/pinpointsmsvoicev2/api_client.go index a5c164fb4fc..02cbb700723 100644 --- a/service/pinpointsmsvoicev2/api_client.go +++ b/service/pinpointsmsvoicev2/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pinpointsmsvoicev2/endpoints.go b/service/pinpointsmsvoicev2/endpoints.go index 0b349262cdf..fa8d95478e1 100644 --- a/service/pinpointsmsvoicev2/endpoints.go +++ b/service/pinpointsmsvoicev2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pinpointsmsvoicev2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PINPOINT_SMS_VOICE_V2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pinpoint SMS Voice V2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pinpointsmsvoicev2/endpoints_config_test.go b/service/pinpointsmsvoicev2/endpoints_config_test.go new file mode 100644 index 00000000000..0618830670a --- /dev/null +++ b/service/pinpointsmsvoicev2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pinpointsmsvoicev2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice-v2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + expectURL: aws.String("https://env-pinpoint-sms-voice-v2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + expectURL: aws.String("http://config-pinpoint-sms-voice-v2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pinpoint-sms-voice-v2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pinpoint-sms-voice-v2.dev", + clientEndpoint: aws.String("https://client-pinpoint-sms-voice-v2.dev"), + expectURL: aws.String("https://client-pinpoint-sms-voice-v2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PINPOINT_SMS_VOICE_V2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pinpointsmsvoicev2/generated.json b/service/pinpointsmsvoicev2/generated.json index b561a430272..2ce2c78ad47 100644 --- a/service/pinpointsmsvoicev2/generated.json +++ b/service/pinpointsmsvoicev2/generated.json @@ -55,6 +55,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pinpointsmsvoicev2/go.mod b/service/pinpointsmsvoicev2/go.mod index 115042f14e1..49be7fdfc88 100644 --- a/service/pinpointsmsvoicev2/go.mod +++ b/service/pinpointsmsvoicev2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pinpointsmsvoicev2/go.sum b/service/pinpointsmsvoicev2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pinpointsmsvoicev2/go.sum +++ b/service/pinpointsmsvoicev2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pipes/api_client.go b/service/pipes/api_client.go index e2cbd9f559e..3918d261679 100644 --- a/service/pipes/api_client.go +++ b/service/pipes/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pipes/endpoints.go b/service/pipes/endpoints.go index 9c95aa50f20..35e5ba21c61 100644 --- a/service/pipes/endpoints.go +++ b/service/pipes/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pipes/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PIPES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pipes", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pipes/endpoints_config_test.go b/service/pipes/endpoints_config_test.go new file mode 100644 index 00000000000..dbc8773bc3f --- /dev/null +++ b/service/pipes/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pipes + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pipes.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pipes.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + expectURL: aws.String("https://env-pipes.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pipes.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + expectURL: aws.String("http://config-pipes.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pipes.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pipes.dev", + clientEndpoint: aws.String("https://client-pipes.dev"), + expectURL: aws.String("https://client-pipes.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PIPES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pipes/generated.json b/service/pipes/generated.json index 96346beb930..a77e041b35d 100644 --- a/service/pipes/generated.json +++ b/service/pipes/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pipes/go.mod b/service/pipes/go.mod index c604901b773..57db84d7e05 100644 --- a/service/pipes/go.mod +++ b/service/pipes/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pipes/go.sum b/service/pipes/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pipes/go.sum +++ b/service/pipes/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/polly/api_client.go b/service/polly/api_client.go index 2a9e67f8b2e..d2c70808625 100644 --- a/service/polly/api_client.go +++ b/service/polly/api_client.go @@ -297,6 +297,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/polly/endpoints.go b/service/polly/endpoints.go index 1ada8abf174..c2ac43c04a6 100644 --- a/service/polly/endpoints.go +++ b/service/polly/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/polly/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_POLLY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Polly", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/polly/endpoints_config_test.go b/service/polly/endpoints_config_test.go new file mode 100644 index 00000000000..85490046c48 --- /dev/null +++ b/service/polly/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package polly + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-polly.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-polly.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + expectURL: aws.String("https://env-polly.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-polly.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + expectURL: aws.String("http://config-polly.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-polly.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-polly.dev", + clientEndpoint: aws.String("https://client-polly.dev"), + expectURL: aws.String("https://client-polly.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_POLLY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/polly/generated.json b/service/polly/generated.json index c99a5aad061..c8ede7fd340 100644 --- a/service/polly/generated.json +++ b/service/polly/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/polly/go.mod b/service/polly/go.mod index b1699f7136b..74a9240c65a 100644 --- a/service/polly/go.mod +++ b/service/polly/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -13,8 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/polly/go.sum b/service/polly/go.sum index a646f1d3099..f46582b3ef9 100644 --- a/service/polly/go.sum +++ b/service/polly/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/pricing/api_client.go b/service/pricing/api_client.go index c87fe28d3a4..8e997195339 100644 --- a/service/pricing/api_client.go +++ b/service/pricing/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/pricing/endpoints.go b/service/pricing/endpoints.go index 24ddb0ac038..25a1c4c5194 100644 --- a/service/pricing/endpoints.go +++ b/service/pricing/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/pricing/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PRICING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Pricing", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/pricing/endpoints_config_test.go b/service/pricing/endpoints_config_test.go new file mode 100644 index 00000000000..7d4161ecc21 --- /dev/null +++ b/service/pricing/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package pricing + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pricing.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-pricing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + expectURL: aws.String("https://env-pricing.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-pricing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + expectURL: aws.String("http://config-pricing.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-pricing.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-pricing.dev", + clientEndpoint: aws.String("https://client-pricing.dev"), + expectURL: aws.String("https://client-pricing.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PRICING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/pricing/generated.json b/service/pricing/generated.json index 42569732e0f..3f17b61b1b8 100644 --- a/service/pricing/generated.json +++ b/service/pricing/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/pricing/go.mod b/service/pricing/go.mod index e20c5123ae6..60281a9bf5f 100644 --- a/service/pricing/go.mod +++ b/service/pricing/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/pricing/go.sum b/service/pricing/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/pricing/go.sum +++ b/service/pricing/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/privatenetworks/api_client.go b/service/privatenetworks/api_client.go index ce4fcb82884..1d9ba25bff5 100644 --- a/service/privatenetworks/api_client.go +++ b/service/privatenetworks/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/privatenetworks/endpoints.go b/service/privatenetworks/endpoints.go index 46e223d5bc7..e891f58a579 100644 --- a/service/privatenetworks/endpoints.go +++ b/service/privatenetworks/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/privatenetworks/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PRIVATENETWORKS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "PrivateNetworks", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/privatenetworks/endpoints_config_test.go b/service/privatenetworks/endpoints_config_test.go new file mode 100644 index 00000000000..948256712d5 --- /dev/null +++ b/service/privatenetworks/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package privatenetworks + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-privatenetworks.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-privatenetworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + expectURL: aws.String("https://env-privatenetworks.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-privatenetworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + expectURL: aws.String("http://config-privatenetworks.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-privatenetworks.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-privatenetworks.dev", + clientEndpoint: aws.String("https://client-privatenetworks.dev"), + expectURL: aws.String("https://client-privatenetworks.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PRIVATENETWORKS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/privatenetworks/generated.json b/service/privatenetworks/generated.json index a7dc4a815f0..3fa93cedf2f 100644 --- a/service/privatenetworks/generated.json +++ b/service/privatenetworks/generated.json @@ -38,6 +38,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/privatenetworks/go.mod b/service/privatenetworks/go.mod index 6cdcd13c5a5..b74d0c4417c 100644 --- a/service/privatenetworks/go.mod +++ b/service/privatenetworks/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/privatenetworks/go.sum b/service/privatenetworks/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/privatenetworks/go.sum +++ b/service/privatenetworks/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/proton/api_client.go b/service/proton/api_client.go index 02e589a7f48..34000473074 100644 --- a/service/proton/api_client.go +++ b/service/proton/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/proton/endpoints.go b/service/proton/endpoints.go index 0188e841b4c..c211c87c94a 100644 --- a/service/proton/endpoints.go +++ b/service/proton/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/proton/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_PROTON") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Proton", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/proton/endpoints_config_test.go b/service/proton/endpoints_config_test.go new file mode 100644 index 00000000000..dd405f46666 --- /dev/null +++ b/service/proton/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package proton + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-proton.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-proton.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + expectURL: aws.String("https://env-proton.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-proton.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + expectURL: aws.String("http://config-proton.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-proton.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-proton.dev", + clientEndpoint: aws.String("https://client-proton.dev"), + expectURL: aws.String("https://client-proton.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_PROTON", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/proton/generated.json b/service/proton/generated.json index 31448225c25..474828c351d 100644 --- a/service/proton/generated.json +++ b/service/proton/generated.json @@ -100,6 +100,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/proton/go.mod b/service/proton/go.mod index 12fcd10262f..77558ad8f6a 100644 --- a/service/proton/go.mod +++ b/service/proton/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/proton/go.sum b/service/proton/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/proton/go.sum +++ b/service/proton/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/qldb/api_client.go b/service/qldb/api_client.go index ad2581ed764..fdd99f97e03 100644 --- a/service/qldb/api_client.go +++ b/service/qldb/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/qldb/endpoints.go b/service/qldb/endpoints.go index 9cb47049ccc..3a27ca1b157 100644 --- a/service/qldb/endpoints.go +++ b/service/qldb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/qldb/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_QLDB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "QLDB", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/qldb/endpoints_config_test.go b/service/qldb/endpoints_config_test.go new file mode 100644 index 00000000000..15f7e8b5e9f --- /dev/null +++ b/service/qldb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package qldb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + expectURL: aws.String("https://env-qldb.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + expectURL: aws.String("http://config-qldb.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb.dev", + clientEndpoint: aws.String("https://client-qldb.dev"), + expectURL: aws.String("https://client-qldb.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_QLDB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/qldb/generated.json b/service/qldb/generated.json index 1caca946e4d..1b1675f9fcf 100644 --- a/service/qldb/generated.json +++ b/service/qldb/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/qldb/go.mod b/service/qldb/go.mod index a87ad34e8f7..cbc654b6de4 100644 --- a/service/qldb/go.mod +++ b/service/qldb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/qldb/go.sum b/service/qldb/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/qldb/go.sum +++ b/service/qldb/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/qldbsession/api_client.go b/service/qldbsession/api_client.go index 3b64fb9bd97..89eb69e98d3 100644 --- a/service/qldbsession/api_client.go +++ b/service/qldbsession/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/qldbsession/endpoints.go b/service/qldbsession/endpoints.go index decbeee614c..bfaef83f5d6 100644 --- a/service/qldbsession/endpoints.go +++ b/service/qldbsession/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/qldbsession/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_QLDB_SESSION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "QLDB Session", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/qldbsession/endpoints_config_test.go b/service/qldbsession/endpoints_config_test.go new file mode 100644 index 00000000000..e263518ac2c --- /dev/null +++ b/service/qldbsession/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package qldbsession + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb-session.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb-session.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + expectURL: aws.String("https://env-qldb-session.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb-session.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + expectURL: aws.String("http://config-qldb-session.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-qldb-session.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-qldb-session.dev", + clientEndpoint: aws.String("https://client-qldb-session.dev"), + expectURL: aws.String("https://client-qldb-session.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_QLDB_SESSION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/qldbsession/generated.json b/service/qldbsession/generated.json index d3afd24cd62..93648ce3048 100644 --- a/service/qldbsession/generated.json +++ b/service/qldbsession/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/qldbsession/go.mod b/service/qldbsession/go.mod index c1901e67673..5983a7984bd 100644 --- a/service/qldbsession/go.mod +++ b/service/qldbsession/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/qldbsession/go.sum b/service/qldbsession/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/qldbsession/go.sum +++ b/service/qldbsession/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/quicksight/api_client.go b/service/quicksight/api_client.go index 49ff4d7b7c1..1e494b531b3 100644 --- a/service/quicksight/api_client.go +++ b/service/quicksight/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/quicksight/endpoints.go b/service/quicksight/endpoints.go index a6d24b5933a..a126dfae6a3 100644 --- a/service/quicksight/endpoints.go +++ b/service/quicksight/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/quicksight/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_QUICKSIGHT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "QuickSight", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/quicksight/endpoints_config_test.go b/service/quicksight/endpoints_config_test.go new file mode 100644 index 00000000000..47e59a83a44 --- /dev/null +++ b/service/quicksight/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package quicksight + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-quicksight.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-quicksight.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + expectURL: aws.String("https://env-quicksight.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-quicksight.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + expectURL: aws.String("http://config-quicksight.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-quicksight.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-quicksight.dev", + clientEndpoint: aws.String("https://client-quicksight.dev"), + expectURL: aws.String("https://client-quicksight.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_QUICKSIGHT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/quicksight/generated.json b/service/quicksight/generated.json index 3da249f88fb..cd418d61875 100644 --- a/service/quicksight/generated.json +++ b/service/quicksight/generated.json @@ -173,6 +173,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/quicksight/go.mod b/service/quicksight/go.mod index ccfec1a49f2..4d9474ab827 100644 --- a/service/quicksight/go.mod +++ b/service/quicksight/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/quicksight/go.sum b/service/quicksight/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/quicksight/go.sum +++ b/service/quicksight/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ram/api_client.go b/service/ram/api_client.go index d310dc9cded..97ece1db0de 100644 --- a/service/ram/api_client.go +++ b/service/ram/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ram/endpoints.go b/service/ram/endpoints.go index 965ba670636..1f6769e231c 100644 --- a/service/ram/endpoints.go +++ b/service/ram/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ram/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RAM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RAM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ram/endpoints_config_test.go b/service/ram/endpoints_config_test.go new file mode 100644 index 00000000000..cc16f5f2609 --- /dev/null +++ b/service/ram/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ram + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ram.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ram.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + expectURL: aws.String("https://env-ram.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ram.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + expectURL: aws.String("http://config-ram.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ram.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ram.dev", + clientEndpoint: aws.String("https://client-ram.dev"), + expectURL: aws.String("https://client-ram.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RAM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ram/generated.json b/service/ram/generated.json index a7ba840dd22..fc0e7858db7 100644 --- a/service/ram/generated.json +++ b/service/ram/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ram/go.mod b/service/ram/go.mod index d778e8dc6d9..909f61247e0 100644 --- a/service/ram/go.mod +++ b/service/ram/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ram/go.sum b/service/ram/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ram/go.sum +++ b/service/ram/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/rbin/api_client.go b/service/rbin/api_client.go index 3aa15fcfb2b..4dc0a1e7d7d 100644 --- a/service/rbin/api_client.go +++ b/service/rbin/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rbin/endpoints.go b/service/rbin/endpoints.go index 4a1cc711f77..a8f33e317bb 100644 --- a/service/rbin/endpoints.go +++ b/service/rbin/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rbin/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RBIN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "rbin", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rbin/endpoints_config_test.go b/service/rbin/endpoints_config_test.go new file mode 100644 index 00000000000..cd5a0f9f5c5 --- /dev/null +++ b/service/rbin/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rbin + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rbin.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rbin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + expectURL: aws.String("https://env-rbin.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rbin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + expectURL: aws.String("http://config-rbin.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rbin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rbin.dev", + clientEndpoint: aws.String("https://client-rbin.dev"), + expectURL: aws.String("https://client-rbin.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RBIN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rbin/generated.json b/service/rbin/generated.json index d96296e6994..6c50331bb7f 100644 --- a/service/rbin/generated.json +++ b/service/rbin/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rbin/go.mod b/service/rbin/go.mod index 8a5368cc82d..189c00fa5fc 100644 --- a/service/rbin/go.mod +++ b/service/rbin/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rbin/go.sum b/service/rbin/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/rbin/go.sum +++ b/service/rbin/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/rds/api_client.go b/service/rds/api_client.go index 82e369096b9..6d7cbe3eec4 100644 --- a/service/rds/api_client.go +++ b/service/rds/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rds/endpoints.go b/service/rds/endpoints.go index e68415723f7..f44800d5688 100644 --- a/service/rds/endpoints.go +++ b/service/rds/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rds/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RDS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RDS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rds/endpoints_config_test.go b/service/rds/endpoints_config_test.go new file mode 100644 index 00000000000..c9370187a69 --- /dev/null +++ b/service/rds/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rds + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + expectURL: aws.String("https://env-rds.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + expectURL: aws.String("http://config-rds.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds.dev", + clientEndpoint: aws.String("https://client-rds.dev"), + expectURL: aws.String("https://client-rds.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RDS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rds/generated.json b/service/rds/generated.json index 733a7c8ee85..73137c31f77 100644 --- a/service/rds/generated.json +++ b/service/rds/generated.json @@ -162,6 +162,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rds/go.mod b/service/rds/go.mod index af0d6578673..12918e909a3 100644 --- a/service/rds/go.mod +++ b/service/rds/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -14,8 +15,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rds/go.sum b/service/rds/go.sum index ef5982af332..c64803e87e7 100644 --- a/service/rds/go.sum +++ b/service/rds/go.sum @@ -1,3 +1,19 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/rdsdata/api_client.go b/service/rdsdata/api_client.go index c50668fd62d..0d8b5dc68f1 100644 --- a/service/rdsdata/api_client.go +++ b/service/rdsdata/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rdsdata/endpoints.go b/service/rdsdata/endpoints.go index ea0b54b9e02..15ef73e2ed4 100644 --- a/service/rdsdata/endpoints.go +++ b/service/rdsdata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rdsdata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RDS_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RDS Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rdsdata/endpoints_config_test.go b/service/rdsdata/endpoints_config_test.go new file mode 100644 index 00000000000..02656d5d863 --- /dev/null +++ b/service/rdsdata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rdsdata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + expectURL: aws.String("https://env-rds-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + expectURL: aws.String("http://config-rds-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rds-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rds-data.dev", + clientEndpoint: aws.String("https://client-rds-data.dev"), + expectURL: aws.String("https://client-rds-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RDS_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rdsdata/generated.json b/service/rdsdata/generated.json index 54f55ecce9a..6879b4cb3c2 100644 --- a/service/rdsdata/generated.json +++ b/service/rdsdata/generated.json @@ -18,6 +18,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rdsdata/go.mod b/service/rdsdata/go.mod index 27eed4fb56b..cd779c4ad37 100644 --- a/service/rdsdata/go.mod +++ b/service/rdsdata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rdsdata/go.sum b/service/rdsdata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/rdsdata/go.sum +++ b/service/rdsdata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/redshift/api_client.go b/service/redshift/api_client.go index bd54dfff34b..899956f6c15 100644 --- a/service/redshift/api_client.go +++ b/service/redshift/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/redshift/endpoints.go b/service/redshift/endpoints.go index 9ef320e18b3..a1005384907 100644 --- a/service/redshift/endpoints.go +++ b/service/redshift/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/redshift/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REDSHIFT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Redshift", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/redshift/endpoints_config_test.go b/service/redshift/endpoints_config_test.go new file mode 100644 index 00000000000..8a7a0c3918d --- /dev/null +++ b/service/redshift/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package redshift + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + expectURL: aws.String("https://env-redshift.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + expectURL: aws.String("http://config-redshift.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift.dev", + clientEndpoint: aws.String("https://client-redshift.dev"), + expectURL: aws.String("https://client-redshift.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REDSHIFT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/redshift/generated.json b/service/redshift/generated.json index ecb78be8626..f046a4f90df 100644 --- a/service/redshift/generated.json +++ b/service/redshift/generated.json @@ -136,6 +136,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/redshift/go.mod b/service/redshift/go.mod index 9db4e13a71f..f6dd7730c4c 100644 --- a/service/redshift/go.mod +++ b/service/redshift/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/redshift/go.sum b/service/redshift/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/redshift/go.sum +++ b/service/redshift/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/redshiftdata/api_client.go b/service/redshiftdata/api_client.go index 3be63eabd7a..d4befb97a69 100644 --- a/service/redshiftdata/api_client.go +++ b/service/redshiftdata/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/redshiftdata/endpoints.go b/service/redshiftdata/endpoints.go index 5d3d27a62aa..724a977c1e6 100644 --- a/service/redshiftdata/endpoints.go +++ b/service/redshiftdata/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/redshiftdata/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REDSHIFT_DATA") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Redshift Data", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/redshiftdata/endpoints_config_test.go b/service/redshiftdata/endpoints_config_test.go new file mode 100644 index 00000000000..d53e41a731e --- /dev/null +++ b/service/redshiftdata/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package redshiftdata + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-data.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + expectURL: aws.String("https://env-redshift-data.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + expectURL: aws.String("http://config-redshift-data.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-data.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-data.dev", + clientEndpoint: aws.String("https://client-redshift-data.dev"), + expectURL: aws.String("https://client-redshift-data.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REDSHIFT_DATA", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/redshiftdata/generated.json b/service/redshiftdata/generated.json index 37aa07481cf..7826174d8e0 100644 --- a/service/redshiftdata/generated.json +++ b/service/redshiftdata/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/redshiftdata/go.mod b/service/redshiftdata/go.mod index 84d4bad5f3e..4437ec93b27 100644 --- a/service/redshiftdata/go.mod +++ b/service/redshiftdata/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/redshiftdata/go.sum b/service/redshiftdata/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/redshiftdata/go.sum +++ b/service/redshiftdata/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/redshiftserverless/api_client.go b/service/redshiftserverless/api_client.go index e49227b33ab..df50da69b52 100644 --- a/service/redshiftserverless/api_client.go +++ b/service/redshiftserverless/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/redshiftserverless/endpoints.go b/service/redshiftserverless/endpoints.go index a4f573897c1..860b42c705d 100644 --- a/service/redshiftserverless/endpoints.go +++ b/service/redshiftserverless/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/redshiftserverless/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REDSHIFT_SERVERLESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Redshift Serverless", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/redshiftserverless/endpoints_config_test.go b/service/redshiftserverless/endpoints_config_test.go new file mode 100644 index 00000000000..e73d77b869f --- /dev/null +++ b/service/redshiftserverless/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package redshiftserverless + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-serverless.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + expectURL: aws.String("https://env-redshift-serverless.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + expectURL: aws.String("http://config-redshift-serverless.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-redshift-serverless.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-redshift-serverless.dev", + clientEndpoint: aws.String("https://client-redshift-serverless.dev"), + expectURL: aws.String("https://client-redshift-serverless.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REDSHIFT_SERVERLESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/redshiftserverless/generated.json b/service/redshiftserverless/generated.json index 002b9380cb3..d8070ac39fc 100644 --- a/service/redshiftserverless/generated.json +++ b/service/redshiftserverless/generated.json @@ -52,6 +52,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/redshiftserverless/go.mod b/service/redshiftserverless/go.mod index b66b032c9de..cb18ef50830 100644 --- a/service/redshiftserverless/go.mod +++ b/service/redshiftserverless/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/redshiftserverless/go.sum b/service/redshiftserverless/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/redshiftserverless/go.sum +++ b/service/redshiftserverless/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/rekognition/api_client.go b/service/rekognition/api_client.go index 8d283f7bbc3..86890c0e4e6 100644 --- a/service/rekognition/api_client.go +++ b/service/rekognition/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rekognition/endpoints.go b/service/rekognition/endpoints.go index be943ed725c..fc091058d77 100644 --- a/service/rekognition/endpoints.go +++ b/service/rekognition/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rekognition/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_REKOGNITION") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Rekognition", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rekognition/endpoints_config_test.go b/service/rekognition/endpoints_config_test.go new file mode 100644 index 00000000000..0ddfefc64f3 --- /dev/null +++ b/service/rekognition/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rekognition + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rekognition.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rekognition.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + expectURL: aws.String("https://env-rekognition.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rekognition.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + expectURL: aws.String("http://config-rekognition.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rekognition.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rekognition.dev", + clientEndpoint: aws.String("https://client-rekognition.dev"), + expectURL: aws.String("https://client-rekognition.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_REKOGNITION", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rekognition/generated.json b/service/rekognition/generated.json index c5c9dbc679a..3e8ae15a934 100644 --- a/service/rekognition/generated.json +++ b/service/rekognition/generated.json @@ -88,6 +88,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rekognition/go.mod b/service/rekognition/go.mod index e065d1561f3..e4799a2ed3a 100644 --- a/service/rekognition/go.mod +++ b/service/rekognition/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rekognition/go.sum b/service/rekognition/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/rekognition/go.sum +++ b/service/rekognition/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/resiliencehub/api_client.go b/service/resiliencehub/api_client.go index 401c39ace4c..58fae8784dc 100644 --- a/service/resiliencehub/api_client.go +++ b/service/resiliencehub/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/resiliencehub/endpoints.go b/service/resiliencehub/endpoints.go index 40f2fc3ebe1..5055ea3b4c9 100644 --- a/service/resiliencehub/endpoints.go +++ b/service/resiliencehub/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/resiliencehub/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RESILIENCEHUB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "resiliencehub", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/resiliencehub/endpoints_config_test.go b/service/resiliencehub/endpoints_config_test.go new file mode 100644 index 00000000000..57f01871899 --- /dev/null +++ b/service/resiliencehub/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package resiliencehub + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resiliencehub.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-resiliencehub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + expectURL: aws.String("https://env-resiliencehub.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resiliencehub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + expectURL: aws.String("http://config-resiliencehub.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-resiliencehub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resiliencehub.dev", + clientEndpoint: aws.String("https://client-resiliencehub.dev"), + expectURL: aws.String("https://client-resiliencehub.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RESILIENCEHUB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/resiliencehub/generated.json b/service/resiliencehub/generated.json index a3ca7d27954..635722642b5 100644 --- a/service/resiliencehub/generated.json +++ b/service/resiliencehub/generated.json @@ -66,6 +66,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/resiliencehub/go.mod b/service/resiliencehub/go.mod index 4325b8cdf24..ec693fea933 100644 --- a/service/resiliencehub/go.mod +++ b/service/resiliencehub/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/resiliencehub/go.sum b/service/resiliencehub/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/resiliencehub/go.sum +++ b/service/resiliencehub/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/resourceexplorer2/api_client.go b/service/resourceexplorer2/api_client.go index 93e49f27e16..c24a0e04f0e 100644 --- a/service/resourceexplorer2/api_client.go +++ b/service/resourceexplorer2/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/resourceexplorer2/endpoints.go b/service/resourceexplorer2/endpoints.go index 788193f4fc7..9a927177c7f 100644 --- a/service/resourceexplorer2/endpoints.go +++ b/service/resourceexplorer2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RESOURCE_EXPLORER_2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Resource Explorer 2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/resourceexplorer2/endpoints_config_test.go b/service/resourceexplorer2/endpoints_config_test.go new file mode 100644 index 00000000000..e7540fc169d --- /dev/null +++ b/service/resourceexplorer2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package resourceexplorer2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-explorer-2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-explorer-2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + expectURL: aws.String("https://env-resource-explorer-2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-explorer-2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + expectURL: aws.String("http://config-resource-explorer-2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-explorer-2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-explorer-2.dev", + clientEndpoint: aws.String("https://client-resource-explorer-2.dev"), + expectURL: aws.String("https://client-resource-explorer-2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RESOURCE_EXPLORER_2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/resourceexplorer2/generated.json b/service/resourceexplorer2/generated.json index d2e837fae62..a894f120975 100644 --- a/service/resourceexplorer2/generated.json +++ b/service/resourceexplorer2/generated.json @@ -33,6 +33,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/resourceexplorer2/go.mod b/service/resourceexplorer2/go.mod index e61bea2e470..79a83d53d79 100644 --- a/service/resourceexplorer2/go.mod +++ b/service/resourceexplorer2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/resourceexplorer2/go.sum b/service/resourceexplorer2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/resourceexplorer2/go.sum +++ b/service/resourceexplorer2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/resourcegroups/api_client.go b/service/resourcegroups/api_client.go index d5f4e14c744..30efaa3e997 100644 --- a/service/resourcegroups/api_client.go +++ b/service/resourcegroups/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/resourcegroups/endpoints.go b/service/resourcegroups/endpoints.go index 0fd79be6753..bf1b824e94b 100644 --- a/service/resourcegroups/endpoints.go +++ b/service/resourcegroups/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/resourcegroups/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RESOURCE_GROUPS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Resource Groups", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/resourcegroups/endpoints_config_test.go b/service/resourcegroups/endpoints_config_test.go new file mode 100644 index 00000000000..2c202f4da71 --- /dev/null +++ b/service/resourcegroups/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package resourcegroups + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + expectURL: aws.String("https://env-resource-groups.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + expectURL: aws.String("http://config-resource-groups.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups.dev", + clientEndpoint: aws.String("https://client-resource-groups.dev"), + expectURL: aws.String("https://client-resource-groups.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RESOURCE_GROUPS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/resourcegroups/generated.json b/service/resourcegroups/generated.json index 4908878089f..905e4658eac 100644 --- a/service/resourcegroups/generated.json +++ b/service/resourcegroups/generated.json @@ -30,6 +30,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/resourcegroups/go.mod b/service/resourcegroups/go.mod index 7413d907335..72d4b50c41e 100644 --- a/service/resourcegroups/go.mod +++ b/service/resourcegroups/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/resourcegroups/go.sum b/service/resourcegroups/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/resourcegroups/go.sum +++ b/service/resourcegroups/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/resourcegroupstaggingapi/api_client.go b/service/resourcegroupstaggingapi/api_client.go index ec0853fe37b..9fd753d3abb 100644 --- a/service/resourcegroupstaggingapi/api_client.go +++ b/service/resourcegroupstaggingapi/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/resourcegroupstaggingapi/endpoints.go b/service/resourcegroupstaggingapi/endpoints.go index cfff463d845..114341745e7 100644 --- a/service/resourcegroupstaggingapi/endpoints.go +++ b/service/resourcegroupstaggingapi/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RESOURCE_GROUPS_TAGGING_API") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Resource Groups Tagging API", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/resourcegroupstaggingapi/endpoints_config_test.go b/service/resourcegroupstaggingapi/endpoints_config_test.go new file mode 100644 index 00000000000..44de2ce6d7e --- /dev/null +++ b/service/resourcegroupstaggingapi/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package resourcegroupstaggingapi + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups-tagging-api.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups-tagging-api.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + expectURL: aws.String("https://env-resource-groups-tagging-api.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups-tagging-api.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + expectURL: aws.String("http://config-resource-groups-tagging-api.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-resource-groups-tagging-api.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-resource-groups-tagging-api.dev", + clientEndpoint: aws.String("https://client-resource-groups-tagging-api.dev"), + expectURL: aws.String("https://client-resource-groups-tagging-api.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RESOURCE_GROUPS_TAGGING_API", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/resourcegroupstaggingapi/generated.json b/service/resourcegroupstaggingapi/generated.json index 5c2fdb5485c..d8f45446942 100644 --- a/service/resourcegroupstaggingapi/generated.json +++ b/service/resourcegroupstaggingapi/generated.json @@ -20,6 +20,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/resourcegroupstaggingapi/go.mod b/service/resourcegroupstaggingapi/go.mod index 4bbfabc5d24..19560dce798 100644 --- a/service/resourcegroupstaggingapi/go.mod +++ b/service/resourcegroupstaggingapi/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/resourcegroupstaggingapi/go.sum b/service/resourcegroupstaggingapi/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/resourcegroupstaggingapi/go.sum +++ b/service/resourcegroupstaggingapi/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/robomaker/api_client.go b/service/robomaker/api_client.go index ff126c8fc89..6ad0b28082a 100644 --- a/service/robomaker/api_client.go +++ b/service/robomaker/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/robomaker/endpoints.go b/service/robomaker/endpoints.go index 110d72a3b70..8f8787e7a46 100644 --- a/service/robomaker/endpoints.go +++ b/service/robomaker/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/robomaker/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROBOMAKER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RoboMaker", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/robomaker/endpoints_config_test.go b/service/robomaker/endpoints_config_test.go new file mode 100644 index 00000000000..4c90eaadc14 --- /dev/null +++ b/service/robomaker/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package robomaker + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-robomaker.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-robomaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + expectURL: aws.String("https://env-robomaker.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-robomaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + expectURL: aws.String("http://config-robomaker.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-robomaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-robomaker.dev", + clientEndpoint: aws.String("https://client-robomaker.dev"), + expectURL: aws.String("https://client-robomaker.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROBOMAKER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/robomaker/generated.json b/service/robomaker/generated.json index a6382d96013..a09f64831e7 100644 --- a/service/robomaker/generated.json +++ b/service/robomaker/generated.json @@ -69,6 +69,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/robomaker/go.mod b/service/robomaker/go.mod index 1f688a64aa0..4018d131d48 100644 --- a/service/robomaker/go.mod +++ b/service/robomaker/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/robomaker/go.sum b/service/robomaker/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/robomaker/go.sum +++ b/service/robomaker/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/rolesanywhere/api_client.go b/service/rolesanywhere/api_client.go index 1fd6974335c..368937d9026 100644 --- a/service/rolesanywhere/api_client.go +++ b/service/rolesanywhere/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rolesanywhere/endpoints.go b/service/rolesanywhere/endpoints.go index 9eca41485e8..8155412652c 100644 --- a/service/rolesanywhere/endpoints.go +++ b/service/rolesanywhere/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rolesanywhere/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROLESANYWHERE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RolesAnywhere", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rolesanywhere/endpoints_config_test.go b/service/rolesanywhere/endpoints_config_test.go new file mode 100644 index 00000000000..38e05251f61 --- /dev/null +++ b/service/rolesanywhere/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rolesanywhere + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rolesanywhere.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rolesanywhere.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + expectURL: aws.String("https://env-rolesanywhere.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rolesanywhere.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + expectURL: aws.String("http://config-rolesanywhere.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rolesanywhere.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rolesanywhere.dev", + clientEndpoint: aws.String("https://client-rolesanywhere.dev"), + expectURL: aws.String("https://client-rolesanywhere.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROLESANYWHERE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rolesanywhere/generated.json b/service/rolesanywhere/generated.json index b5926c6ea38..13e360683dc 100644 --- a/service/rolesanywhere/generated.json +++ b/service/rolesanywhere/generated.json @@ -40,6 +40,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rolesanywhere/go.mod b/service/rolesanywhere/go.mod index 30cf8fb2f86..d26d09346e7 100644 --- a/service/rolesanywhere/go.mod +++ b/service/rolesanywhere/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rolesanywhere/go.sum b/service/rolesanywhere/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/rolesanywhere/go.sum +++ b/service/rolesanywhere/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/route53/api_client.go b/service/route53/api_client.go index 22da54027d8..6722b4d9b91 100644 --- a/service/route53/api_client.go +++ b/service/route53/api_client.go @@ -297,6 +297,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53/endpoints.go b/service/route53/endpoints.go index 8155ec89891..3a02eba2da3 100644 --- a/service/route53/endpoints.go +++ b/service/route53/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE_53") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route 53", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53/endpoints_config_test.go b/service/route53/endpoints_config_test.go new file mode 100644 index 00000000000..86ac42375c0 --- /dev/null +++ b/service/route53/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + expectURL: aws.String("https://env-route-53.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + expectURL: aws.String("http://config-route-53.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53.dev", + clientEndpoint: aws.String("https://client-route-53.dev"), + expectURL: aws.String("https://client-route-53.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE_53", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53/generated.json b/service/route53/generated.json index 5666b74732f..4933bb5b7f1 100644 --- a/service/route53/generated.json +++ b/service/route53/generated.json @@ -83,6 +83,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53/go.mod b/service/route53/go.mod index 921245a7d36..1cec4270e6e 100644 --- a/service/route53/go.mod +++ b/service/route53/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53/go.sum b/service/route53/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/route53/go.sum +++ b/service/route53/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/route53domains/api_client.go b/service/route53domains/api_client.go index 14e9a1f5332..9f98eba62ce 100644 --- a/service/route53domains/api_client.go +++ b/service/route53domains/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53domains/endpoints.go b/service/route53domains/endpoints.go index 2b6b58c0277..a698fb03ec9 100644 --- a/service/route53domains/endpoints.go +++ b/service/route53domains/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53domains/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE_53_DOMAINS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route 53 Domains", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53domains/endpoints_config_test.go b/service/route53domains/endpoints_config_test.go new file mode 100644 index 00000000000..8fef330865a --- /dev/null +++ b/service/route53domains/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53domains + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53-domains.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53-domains.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + expectURL: aws.String("https://env-route-53-domains.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53-domains.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + expectURL: aws.String("http://config-route-53-domains.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route-53-domains.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route-53-domains.dev", + clientEndpoint: aws.String("https://client-route-53-domains.dev"), + expectURL: aws.String("https://client-route-53-domains.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE_53_DOMAINS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53domains/generated.json b/service/route53domains/generated.json index b188f31b8fd..fe97d7e983f 100644 --- a/service/route53domains/generated.json +++ b/service/route53domains/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53domains/go.mod b/service/route53domains/go.mod index 25bb35e4515..d01eb86ceb7 100644 --- a/service/route53domains/go.mod +++ b/service/route53domains/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53domains/go.sum b/service/route53domains/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/route53domains/go.sum +++ b/service/route53domains/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/route53recoverycluster/api_client.go b/service/route53recoverycluster/api_client.go index a86f9e54279..afab0381d39 100644 --- a/service/route53recoverycluster/api_client.go +++ b/service/route53recoverycluster/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53recoverycluster/endpoints.go b/service/route53recoverycluster/endpoints.go index 9b91fa6844a..83ce10b52e1 100644 --- a/service/route53recoverycluster/endpoints.go +++ b/service/route53recoverycluster/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53recoverycluster/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_CLUSTER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route53 Recovery Cluster", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53recoverycluster/endpoints_config_test.go b/service/route53recoverycluster/endpoints_config_test.go new file mode 100644 index 00000000000..cbcf519ef94 --- /dev/null +++ b/service/route53recoverycluster/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53recoverycluster + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-cluster.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-cluster.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + expectURL: aws.String("https://env-route53-recovery-cluster.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-cluster.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + expectURL: aws.String("http://config-route53-recovery-cluster.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-cluster.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-cluster.dev", + clientEndpoint: aws.String("https://client-route53-recovery-cluster.dev"), + expectURL: aws.String("https://client-route53-recovery-cluster.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_CLUSTER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53recoverycluster/generated.json b/service/route53recoverycluster/generated.json index 29f21a3b64e..e11ef4db592 100644 --- a/service/route53recoverycluster/generated.json +++ b/service/route53recoverycluster/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53recoverycluster/go.mod b/service/route53recoverycluster/go.mod index 1d64fe6594c..80bc0b47bec 100644 --- a/service/route53recoverycluster/go.mod +++ b/service/route53recoverycluster/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53recoverycluster/go.sum b/service/route53recoverycluster/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/route53recoverycluster/go.sum +++ b/service/route53recoverycluster/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/route53recoverycontrolconfig/api_client.go b/service/route53recoverycontrolconfig/api_client.go index a6ee4461f17..ee180de33f2 100644 --- a/service/route53recoverycontrolconfig/api_client.go +++ b/service/route53recoverycontrolconfig/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53recoverycontrolconfig/endpoints.go b/service/route53recoverycontrolconfig/endpoints.go index 721a65fb16e..f1d809549a4 100644 --- a/service/route53recoverycontrolconfig/endpoints.go +++ b/service/route53recoverycontrolconfig/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53recoverycontrolconfig/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_CONTROL_CONFIG") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route53 Recovery Control Config", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53recoverycontrolconfig/endpoints_config_test.go b/service/route53recoverycontrolconfig/endpoints_config_test.go new file mode 100644 index 00000000000..cc0fa62d492 --- /dev/null +++ b/service/route53recoverycontrolconfig/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53recoverycontrolconfig + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-control-config.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-control-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + expectURL: aws.String("https://env-route53-recovery-control-config.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-control-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + expectURL: aws.String("http://config-route53-recovery-control-config.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-control-config.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-control-config.dev", + clientEndpoint: aws.String("https://client-route53-recovery-control-config.dev"), + expectURL: aws.String("https://client-route53-recovery-control-config.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_CONTROL_CONFIG", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53recoverycontrolconfig/generated.json b/service/route53recoverycontrolconfig/generated.json index 175c9e5f6c7..7916f79dcbf 100644 --- a/service/route53recoverycontrolconfig/generated.json +++ b/service/route53recoverycontrolconfig/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53recoverycontrolconfig/go.mod b/service/route53recoverycontrolconfig/go.mod index 18a61ddaee3..d03b4e79d9f 100644 --- a/service/route53recoverycontrolconfig/go.mod +++ b/service/route53recoverycontrolconfig/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53recoverycontrolconfig/go.sum b/service/route53recoverycontrolconfig/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/route53recoverycontrolconfig/go.sum +++ b/service/route53recoverycontrolconfig/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/route53recoveryreadiness/api_client.go b/service/route53recoveryreadiness/api_client.go index 4fae55b5bdd..9deaf882351 100644 --- a/service/route53recoveryreadiness/api_client.go +++ b/service/route53recoveryreadiness/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53recoveryreadiness/endpoints.go b/service/route53recoveryreadiness/endpoints.go index 4bdcbcb8439..e4839879da0 100644 --- a/service/route53recoveryreadiness/endpoints.go +++ b/service/route53recoveryreadiness/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_READINESS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route53 Recovery Readiness", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53recoveryreadiness/endpoints_config_test.go b/service/route53recoveryreadiness/endpoints_config_test.go new file mode 100644 index 00000000000..869cb1a82c6 --- /dev/null +++ b/service/route53recoveryreadiness/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53recoveryreadiness + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-readiness.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-readiness.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + expectURL: aws.String("https://env-route53-recovery-readiness.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-readiness.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + expectURL: aws.String("http://config-route53-recovery-readiness.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53-recovery-readiness.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53-recovery-readiness.dev", + clientEndpoint: aws.String("https://client-route53-recovery-readiness.dev"), + expectURL: aws.String("https://client-route53-recovery-readiness.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE53_RECOVERY_READINESS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53recoveryreadiness/generated.json b/service/route53recoveryreadiness/generated.json index 4abb290faa3..fe2134d5256 100644 --- a/service/route53recoveryreadiness/generated.json +++ b/service/route53recoveryreadiness/generated.json @@ -44,6 +44,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53recoveryreadiness/go.mod b/service/route53recoveryreadiness/go.mod index 0aeee4ac6b1..b09e3606ef3 100644 --- a/service/route53recoveryreadiness/go.mod +++ b/service/route53recoveryreadiness/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53recoveryreadiness/go.sum b/service/route53recoveryreadiness/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/route53recoveryreadiness/go.sum +++ b/service/route53recoveryreadiness/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/route53resolver/api_client.go b/service/route53resolver/api_client.go index c9f7478a1bc..3bbeb325021 100644 --- a/service/route53resolver/api_client.go +++ b/service/route53resolver/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/route53resolver/endpoints.go b/service/route53resolver/endpoints.go index 27aeb62a817..21a71cc061a 100644 --- a/service/route53resolver/endpoints.go +++ b/service/route53resolver/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/route53resolver/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_ROUTE53RESOLVER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Route53Resolver", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/route53resolver/endpoints_config_test.go b/service/route53resolver/endpoints_config_test.go new file mode 100644 index 00000000000..2a7bb5dae2b --- /dev/null +++ b/service/route53resolver/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package route53resolver + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53resolver.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53resolver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + expectURL: aws.String("https://env-route53resolver.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53resolver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + expectURL: aws.String("http://config-route53resolver.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-route53resolver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-route53resolver.dev", + clientEndpoint: aws.String("https://client-route53resolver.dev"), + expectURL: aws.String("https://client-route53resolver.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_ROUTE53RESOLVER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/route53resolver/generated.json b/service/route53resolver/generated.json index e5207890272..116f331fe13 100644 --- a/service/route53resolver/generated.json +++ b/service/route53resolver/generated.json @@ -80,6 +80,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/route53resolver/go.mod b/service/route53resolver/go.mod index f2a9c585c85..f06a3921540 100644 --- a/service/route53resolver/go.mod +++ b/service/route53resolver/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/route53resolver/go.sum b/service/route53resolver/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/route53resolver/go.sum +++ b/service/route53resolver/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/rum/api_client.go b/service/rum/api_client.go index d3d32ecbbad..cce550f0d28 100644 --- a/service/rum/api_client.go +++ b/service/rum/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/rum/endpoints.go b/service/rum/endpoints.go index 754d5cd2963..108c72fae7e 100644 --- a/service/rum/endpoints.go +++ b/service/rum/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/rum/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_RUM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "RUM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/rum/endpoints_config_test.go b/service/rum/endpoints_config_test.go new file mode 100644 index 00000000000..63f59e9dbaa --- /dev/null +++ b/service/rum/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package rum + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rum.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-rum.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + expectURL: aws.String("https://env-rum.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-rum.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + expectURL: aws.String("http://config-rum.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-rum.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-rum.dev", + clientEndpoint: aws.String("https://client-rum.dev"), + expectURL: aws.String("https://client-rum.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_RUM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/rum/generated.json b/service/rum/generated.json index 761d254134b..8270a66d1ef 100644 --- a/service/rum/generated.json +++ b/service/rum/generated.json @@ -29,6 +29,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/rum/go.mod b/service/rum/go.mod index bd0b71eb1d4..17aa8a67aba 100644 --- a/service/rum/go.mod +++ b/service/rum/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/rum/go.sum b/service/rum/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/rum/go.sum +++ b/service/rum/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/s3/endpoints.go b/service/s3/endpoints.go index f10dcab9b84..ffbe9fb5ad9 100644 --- a/service/s3/endpoints.go +++ b/service/s3/endpoints.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3/internal/endpoints" @@ -20,6 +19,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -210,13 +210,15 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []config.Config - for _, c := range cfg.ConfigSources { - if cs, ok := c.(config.Config); ok { - configSources = append(configSources, cs) - } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_S3") + + if g && !s { + return } - value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3", configSources) + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } diff --git a/service/s3/endpoints_config_test.go b/service/s3/endpoints_config_test.go index ca7c6b1c058..3cdce5c51a2 100644 --- a/service/s3/endpoints_config_test.go +++ b/service/s3/endpoints_config_test.go @@ -5,141 +5,133 @@ package s3 import ( "context" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" "os" - "path/filepath" "reflect" "testing" ) -func TestConfiguredEndpoints(t *testing.T) { +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3 - -[services testing-s3] -s3 = - endpoint_url = http://config-s3.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3 - -[services testing-s3] -s3 = - endpoint_url = http://config-s3.dev -`, - ExpectURL: aws.String("https://env-s3.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + expectURL: aws.String("https://env-s3.dev"), }, "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3 -ignore_configured_endpoint_urls = true - -[services testing-s3] -s3 = - endpoint_url = http://config-s3.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + configIgnore: true, + expectURL: nil, }, "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("http://config-global.dev"), + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), }, "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3 - -[services testing-s3] -s3 = - endpoint_url = http://config-s3.dev -`, - ExpectURL: aws.String("http://config-s3.dev"), + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + expectURL: aws.String("http://config-s3.dev"), }, "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3": "https://env-s3.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3 - -[services testing-s3] -s3 = - endpoint_url = http://config-s3.dev -`, - ClientEndpoint: aws.String("https://client-s3.dev"), - ExpectURL: aws.String("https://client-s3.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3.dev", + clientEndpoint: aws.String("https://client-s3.dev"), + expectURL: aws.String("https://client-s3.dev"), }, } for name, c := range cases { t.Run(name, func(t *testing.T) { os.Clearenv() - for k, v := range c.Env { - t.Setenv(k, v) + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) } - tmpDir := t.TempDir() - os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_S3", c.envService) + } - awsConfig, err := config.LoadDefaultConfig( - context.TODO(), - config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), - config.WithSharedConfigProfile("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, } client := NewFromConfig(awsConfig, func(o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) diff --git a/service/s3/go.mod b/service/s3/go.mod index 09ea75e6e3d..58847dadb08 100644 --- a/service/s3/go.mod +++ b/service/s3/go.mod @@ -5,7 +5,6 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 - github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 @@ -20,16 +19,22 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ -replace github.com/aws/aws-sdk-go-v2/config => ../../config +replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ -replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ -replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/internal/v4a => ../../internal/v4a/ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../service/internal/accept-encoding/ @@ -39,3 +44,9 @@ replace github.com/aws/aws-sdk-go-v2/service/internal/checksum => ../../service/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../service/internal/s3shared/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/s3/internal/configtesting/go.mod b/service/s3/internal/configtesting/go.mod index 2f9dc8f1acd..30add19607c 100644 --- a/service/s3/internal/configtesting/go.mod +++ b/service/s3/internal/configtesting/go.mod @@ -17,6 +17,8 @@ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2 replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ diff --git a/service/s3/internal/configtesting/go.sum b/service/s3/internal/configtesting/go.sum index a646f1d3099..bd5e12334b7 100644 --- a/service/s3/internal/configtesting/go.sum +++ b/service/s3/internal/configtesting/go.sum @@ -1,3 +1,5 @@ +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/s3control/endpoints.go b/service/s3control/endpoints.go index 6bc6a05b075..6f3061123a6 100644 --- a/service/s3control/endpoints.go +++ b/service/s3control/endpoints.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3control/internal/endpoints" @@ -20,6 +19,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -210,13 +210,15 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []config.Config - for _, c := range cfg.ConfigSources { - if cs, ok := c.(config.Config); ok { - configSources = append(configSources, cs) - } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_S3_CONTROL") + + if g && !s { + return } - value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3 Control", configSources) + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3 Control", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } diff --git a/service/s3control/endpoints_config_test.go b/service/s3control/endpoints_config_test.go index f9ecbebb7d3..252e0027c27 100644 --- a/service/s3control/endpoints_config_test.go +++ b/service/s3control/endpoints_config_test.go @@ -5,141 +5,133 @@ package s3control import ( "context" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" "os" - "path/filepath" "reflect" "testing" ) -func TestConfiguredEndpoints(t *testing.T) { +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3-control - -[services testing-s3-control] -s3_control = - endpoint_url = http://config-s3-control.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3-control.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3-control - -[services testing-s3-control] -s3_control = - endpoint_url = http://config-s3-control.dev -`, - ExpectURL: aws.String("https://env-s3-control.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3-control.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + expectURL: aws.String("https://env-s3-control.dev"), }, "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3-control -ignore_configured_endpoint_urls = true - -[services testing-s3-control] -s3_control = - endpoint_url = http://config-s3-control.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3-control.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + configIgnore: true, + expectURL: nil, }, "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("http://config-global.dev"), + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), }, "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3-control - -[services testing-s3-control] -s3_control = - endpoint_url = http://config-s3-control.dev -`, - ExpectURL: aws.String("http://config-s3-control.dev"), + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + expectURL: aws.String("http://config-s3-control.dev"), }, "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3_CONTROL": "https://env-s3-control.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3-control - -[services testing-s3-control] -s3_control = - endpoint_url = http://config-s3-control.dev -`, - ClientEndpoint: aws.String("https://client-s3-control.dev"), - ExpectURL: aws.String("https://client-s3-control.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3-control.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3-control.dev", + clientEndpoint: aws.String("https://client-s3-control.dev"), + expectURL: aws.String("https://client-s3-control.dev"), }, } for name, c := range cases { t.Run(name, func(t *testing.T) { os.Clearenv() - for k, v := range c.Env { - t.Setenv(k, v) + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) } - tmpDir := t.TempDir() - os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_S3_CONTROL", c.envService) + } - awsConfig, err := config.LoadDefaultConfig( - context.TODO(), - config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), - config.WithSharedConfigProfile("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, } client := NewFromConfig(awsConfig, func(o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) diff --git a/service/s3control/go.mod b/service/s3control/go.mod index abf19814ef3..1e7291140b7 100644 --- a/service/s3control/go.mod +++ b/service/s3control/go.mod @@ -4,7 +4,6 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 - github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 @@ -15,12 +14,26 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ -replace github.com/aws/aws-sdk-go-v2/config => ../../config +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ -replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../service/internal/s3shared/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/s3outposts/endpoints.go b/service/s3outposts/endpoints.go index caa32c47857..266dfe611b7 100644 --- a/service/s3outposts/endpoints.go +++ b/service/s3outposts/endpoints.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/s3outposts/internal/endpoints" @@ -18,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -200,13 +200,15 @@ func resolveBaseEndpoint(cfg aws.Config, o *Options) { if cfg.BaseEndpoint != nil { o.BaseEndpoint = cfg.BaseEndpoint } - var configSources []config.Config - for _, c := range cfg.ConfigSources { - if cs, ok := c.(config.Config); ok { - configSources = append(configSources, cs) - } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_S3OUTPOSTS") + + if g && !s { + return } - value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3Outposts", configSources) + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "S3Outposts", cfg.ConfigSources) if found && err == nil { o.BaseEndpoint = &value } diff --git a/service/s3outposts/endpoints_config_test.go b/service/s3outposts/endpoints_config_test.go index 9f25c73a9bd..2731001de07 100644 --- a/service/s3outposts/endpoints_config_test.go +++ b/service/s3outposts/endpoints_config_test.go @@ -5,141 +5,133 @@ package s3outposts import ( "context" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" "os" - "path/filepath" "reflect" "testing" ) -func TestConfiguredEndpoints(t *testing.T) { +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { cases := map[string]struct { - Env map[string]string - SharedConfigFile string - ClientEndpoint *string - ExpectURL *string + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string }{ "env ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3outposts - -[services testing-s3outposts] -s3outposts = - endpoint_url = http://config-s3outposts.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3outposts.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + expectURL: nil, }, "env global": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("https://env-global.dev"), + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + expectURL: aws.String("https://env-global.dev"), }, "env service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3outposts - -[services testing-s3outposts] -s3outposts = - endpoint_url = http://config-s3outposts.dev -`, - ExpectURL: aws.String("https://env-s3outposts.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + expectURL: aws.String("https://env-s3outposts.dev"), }, "config ignore": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3outposts -ignore_configured_endpoint_urls = true - -[services testing-s3outposts] -s3outposts = - endpoint_url = http://config-s3outposts.dev -`, - ExpectURL: nil, + envGlobal: "https://env-global.dev", + envService: "https://env-s3outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + configIgnore: true, + expectURL: nil, }, "config global": { - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -`, - ExpectURL: aws.String("http://config-global.dev"), + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), }, "config service": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3outposts - -[services testing-s3outposts] -s3outposts = - endpoint_url = http://config-s3outposts.dev -`, - ExpectURL: aws.String("http://config-s3outposts.dev"), + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + expectURL: aws.String("http://config-s3outposts.dev"), }, "client": { - Env: map[string]string{ - "AWS_ENDPOINT_URL": "https://env-global.dev", - "AWS_ENDPOINT_URL_S3OUTPOSTS": "https://env-s3outposts.dev", - "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "true", - }, - SharedConfigFile: `[profile dev] -endpoint_url = http://config-global.dev -services = testing-s3outposts - -[services testing-s3outposts] -s3outposts = - endpoint_url = http://config-s3outposts.dev -`, - ClientEndpoint: aws.String("https://client-s3outposts.dev"), - ExpectURL: aws.String("https://client-s3outposts.dev"), + envGlobal: "https://env-global.dev", + envService: "https://env-s3outposts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-s3outposts.dev", + clientEndpoint: aws.String("https://client-s3outposts.dev"), + expectURL: aws.String("https://client-s3outposts.dev"), }, } for name, c := range cases { t.Run(name, func(t *testing.T) { os.Clearenv() - for k, v := range c.Env { - t.Setenv(k, v) + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) } - tmpDir := t.TempDir() - os.WriteFile(filepath.Join(tmpDir, "test_shared_config"), []byte(c.SharedConfigFile), os.FileMode(int(0777))) + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_S3OUTPOSTS", c.envService) + } - awsConfig, err := config.LoadDefaultConfig( - context.TODO(), - config.WithSharedConfigFiles([]string{filepath.Join(tmpDir, "test_shared_config")}), - config.WithSharedConfigProfile("dev"), - ) - if err != nil { - t.Fatalf("error loading default config: %v", err) + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, } client := NewFromConfig(awsConfig, func(o *Options) { - if c.ClientEndpoint != nil { - o.BaseEndpoint = c.ClientEndpoint + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint } }) - if e, a := c.ExpectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { t.Errorf("expect endpoint %v , got %v", e, a) } }) diff --git a/service/s3outposts/go.mod b/service/s3outposts/go.mod index a430bd3c147..a5dbe60a1c0 100644 --- a/service/s3outposts/go.mod +++ b/service/s3outposts/go.mod @@ -4,7 +4,6 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 - github.com/aws/aws-sdk-go-v2/config v1.19.1 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 @@ -14,10 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ -replace github.com/aws/aws-sdk-go-v2/config => ../../config +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ -replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemaker/api_client.go b/service/sagemaker/api_client.go index 5f0ffb19578..7bad2c1bc40 100644 --- a/service/sagemaker/api_client.go +++ b/service/sagemaker/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemaker/endpoints.go b/service/sagemaker/endpoints.go index a17fdd7ab70..2fb5e7b3a71 100644 --- a/service/sagemaker/endpoints.go +++ b/service/sagemaker/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemaker/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemaker/endpoints_config_test.go b/service/sagemaker/endpoints_config_test.go new file mode 100644 index 00000000000..bff0cccaf57 --- /dev/null +++ b/service/sagemaker/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemaker + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + expectURL: aws.String("https://env-sagemaker.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + expectURL: aws.String("http://config-sagemaker.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker.dev", + clientEndpoint: aws.String("https://client-sagemaker.dev"), + expectURL: aws.String("https://client-sagemaker.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemaker/generated.json b/service/sagemaker/generated.json index a61630c9287..8a3c7137114 100644 --- a/service/sagemaker/generated.json +++ b/service/sagemaker/generated.json @@ -317,6 +317,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemaker/go.mod b/service/sagemaker/go.mod index 05559910a7f..032f14e0ab5 100644 --- a/service/sagemaker/go.mod +++ b/service/sagemaker/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemaker/go.sum b/service/sagemaker/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/sagemaker/go.sum +++ b/service/sagemaker/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/sagemakera2iruntime/api_client.go b/service/sagemakera2iruntime/api_client.go index 6bcad70a829..c2cc3ddf244 100644 --- a/service/sagemakera2iruntime/api_client.go +++ b/service/sagemakera2iruntime/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakera2iruntime/endpoints.go b/service/sagemakera2iruntime/endpoints.go index 44926e38c85..4cab6564669 100644 --- a/service/sagemakera2iruntime/endpoints.go +++ b/service/sagemakera2iruntime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakera2iruntime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_A2I_RUNTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker A2I Runtime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakera2iruntime/endpoints_config_test.go b/service/sagemakera2iruntime/endpoints_config_test.go new file mode 100644 index 00000000000..cdc6d157621 --- /dev/null +++ b/service/sagemakera2iruntime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakera2iruntime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-a2i-runtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-a2i-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + expectURL: aws.String("https://env-sagemaker-a2i-runtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-a2i-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + expectURL: aws.String("http://config-sagemaker-a2i-runtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-a2i-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-a2i-runtime.dev", + clientEndpoint: aws.String("https://client-sagemaker-a2i-runtime.dev"), + expectURL: aws.String("https://client-sagemaker-a2i-runtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_A2I_RUNTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakera2iruntime/generated.json b/service/sagemakera2iruntime/generated.json index f731af1a356..da2cfa500b8 100644 --- a/service/sagemakera2iruntime/generated.json +++ b/service/sagemakera2iruntime/generated.json @@ -17,6 +17,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemakera2iruntime/go.mod b/service/sagemakera2iruntime/go.mod index 8812e74f453..b98e47f03b1 100644 --- a/service/sagemakera2iruntime/go.mod +++ b/service/sagemakera2iruntime/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakera2iruntime/go.sum b/service/sagemakera2iruntime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakera2iruntime/go.sum +++ b/service/sagemakera2iruntime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sagemakeredge/api_client.go b/service/sagemakeredge/api_client.go index 32f036fa8d6..97b1f6dc91f 100644 --- a/service/sagemakeredge/api_client.go +++ b/service/sagemakeredge/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakeredge/endpoints.go b/service/sagemakeredge/endpoints.go index 9402943f72b..b5306c0fbeb 100644 --- a/service/sagemakeredge/endpoints.go +++ b/service/sagemakeredge/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakeredge/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_EDGE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Sagemaker Edge", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakeredge/endpoints_config_test.go b/service/sagemakeredge/endpoints_config_test.go new file mode 100644 index 00000000000..4449e18dee8 --- /dev/null +++ b/service/sagemakeredge/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakeredge + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-edge.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-edge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + expectURL: aws.String("https://env-sagemaker-edge.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-edge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + expectURL: aws.String("http://config-sagemaker-edge.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-edge.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-edge.dev", + clientEndpoint: aws.String("https://client-sagemaker-edge.dev"), + expectURL: aws.String("https://client-sagemaker-edge.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_EDGE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakeredge/generated.json b/service/sagemakeredge/generated.json index 47339a1f981..ee8913ccff5 100644 --- a/service/sagemakeredge/generated.json +++ b/service/sagemakeredge/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemakeredge/go.mod b/service/sagemakeredge/go.mod index 3a25708d045..1c6a9849a5a 100644 --- a/service/sagemakeredge/go.mod +++ b/service/sagemakeredge/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakeredge/go.sum b/service/sagemakeredge/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakeredge/go.sum +++ b/service/sagemakeredge/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sagemakerfeaturestoreruntime/api_client.go b/service/sagemakerfeaturestoreruntime/api_client.go index 35fe25a641e..e94195c5385 100644 --- a/service/sagemakerfeaturestoreruntime/api_client.go +++ b/service/sagemakerfeaturestoreruntime/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakerfeaturestoreruntime/endpoints.go b/service/sagemakerfeaturestoreruntime/endpoints.go index e7ed0e6d971..7d4c8fefa88 100644 --- a/service/sagemakerfeaturestoreruntime/endpoints.go +++ b/service/sagemakerfeaturestoreruntime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakerfeaturestoreruntime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_FEATURESTORE_RUNTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker FeatureStore Runtime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakerfeaturestoreruntime/endpoints_config_test.go b/service/sagemakerfeaturestoreruntime/endpoints_config_test.go new file mode 100644 index 00000000000..2788b04c6ab --- /dev/null +++ b/service/sagemakerfeaturestoreruntime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakerfeaturestoreruntime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-featurestore-runtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-featurestore-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + expectURL: aws.String("https://env-sagemaker-featurestore-runtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-featurestore-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + expectURL: aws.String("http://config-sagemaker-featurestore-runtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-featurestore-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-featurestore-runtime.dev", + clientEndpoint: aws.String("https://client-sagemaker-featurestore-runtime.dev"), + expectURL: aws.String("https://client-sagemaker-featurestore-runtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_FEATURESTORE_RUNTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakerfeaturestoreruntime/generated.json b/service/sagemakerfeaturestoreruntime/generated.json index ec0f246978a..7fc4b8ede34 100644 --- a/service/sagemakerfeaturestoreruntime/generated.json +++ b/service/sagemakerfeaturestoreruntime/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemakerfeaturestoreruntime/go.mod b/service/sagemakerfeaturestoreruntime/go.mod index fe32997a2dd..aae50335ca9 100644 --- a/service/sagemakerfeaturestoreruntime/go.mod +++ b/service/sagemakerfeaturestoreruntime/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakerfeaturestoreruntime/go.sum b/service/sagemakerfeaturestoreruntime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakerfeaturestoreruntime/go.sum +++ b/service/sagemakerfeaturestoreruntime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sagemakergeospatial/api_client.go b/service/sagemakergeospatial/api_client.go index 37a90451b95..8ea4e79fa5a 100644 --- a/service/sagemakergeospatial/api_client.go +++ b/service/sagemakergeospatial/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakergeospatial/endpoints.go b/service/sagemakergeospatial/endpoints.go index f88eb0cf520..fe23726bfac 100644 --- a/service/sagemakergeospatial/endpoints.go +++ b/service/sagemakergeospatial/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakergeospatial/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_GEOSPATIAL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker Geospatial", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakergeospatial/endpoints_config_test.go b/service/sagemakergeospatial/endpoints_config_test.go new file mode 100644 index 00000000000..33f199d77a5 --- /dev/null +++ b/service/sagemakergeospatial/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakergeospatial + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-geospatial.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-geospatial.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + expectURL: aws.String("https://env-sagemaker-geospatial.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-geospatial.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + expectURL: aws.String("http://config-sagemaker-geospatial.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-geospatial.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-geospatial.dev", + clientEndpoint: aws.String("https://client-sagemaker-geospatial.dev"), + expectURL: aws.String("https://client-sagemaker-geospatial.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_GEOSPATIAL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakergeospatial/generated.json b/service/sagemakergeospatial/generated.json index f3567bf2352..2cd0d4f3c4a 100644 --- a/service/sagemakergeospatial/generated.json +++ b/service/sagemakergeospatial/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemakergeospatial/go.mod b/service/sagemakergeospatial/go.mod index 13fc6bce810..0f419a69fdb 100644 --- a/service/sagemakergeospatial/go.mod +++ b/service/sagemakergeospatial/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakergeospatial/go.sum b/service/sagemakergeospatial/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakergeospatial/go.sum +++ b/service/sagemakergeospatial/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sagemakermetrics/api_client.go b/service/sagemakermetrics/api_client.go index 602f3921250..be97472c5da 100644 --- a/service/sagemakermetrics/api_client.go +++ b/service/sagemakermetrics/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakermetrics/endpoints.go b/service/sagemakermetrics/endpoints.go index c988512cb4b..456ae787dc2 100644 --- a/service/sagemakermetrics/endpoints.go +++ b/service/sagemakermetrics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakermetrics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_METRICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker Metrics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakermetrics/endpoints_config_test.go b/service/sagemakermetrics/endpoints_config_test.go new file mode 100644 index 00000000000..d004fb6bcde --- /dev/null +++ b/service/sagemakermetrics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakermetrics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-metrics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-metrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + expectURL: aws.String("https://env-sagemaker-metrics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-metrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + expectURL: aws.String("http://config-sagemaker-metrics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-metrics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-metrics.dev", + clientEndpoint: aws.String("https://client-sagemaker-metrics.dev"), + expectURL: aws.String("https://client-sagemaker-metrics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_METRICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakermetrics/generated.json b/service/sagemakermetrics/generated.json index 52ae29cd47f..792b9912c09 100644 --- a/service/sagemakermetrics/generated.json +++ b/service/sagemakermetrics/generated.json @@ -13,6 +13,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sagemakermetrics/go.mod b/service/sagemakermetrics/go.mod index c324e2efe24..5fbf6bf53ad 100644 --- a/service/sagemakermetrics/go.mod +++ b/service/sagemakermetrics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakermetrics/go.sum b/service/sagemakermetrics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakermetrics/go.sum +++ b/service/sagemakermetrics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sagemakerruntime/api_client.go b/service/sagemakerruntime/api_client.go index ae74e0df859..f6869e503af 100644 --- a/service/sagemakerruntime/api_client.go +++ b/service/sagemakerruntime/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sagemakerruntime/endpoints.go b/service/sagemakerruntime/endpoints.go index d2b6007e148..94ea53e938c 100644 --- a/service/sagemakerruntime/endpoints.go +++ b/service/sagemakerruntime/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sagemakerruntime/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAGEMAKER_RUNTIME") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SageMaker Runtime", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sagemakerruntime/endpoints_config_test.go b/service/sagemakerruntime/endpoints_config_test.go new file mode 100644 index 00000000000..c2f37f607ad --- /dev/null +++ b/service/sagemakerruntime/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sagemakerruntime + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-runtime.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + expectURL: aws.String("https://env-sagemaker-runtime.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + expectURL: aws.String("http://config-sagemaker-runtime.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sagemaker-runtime.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sagemaker-runtime.dev", + clientEndpoint: aws.String("https://client-sagemaker-runtime.dev"), + expectURL: aws.String("https://client-sagemaker-runtime.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAGEMAKER_RUNTIME", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sagemakerruntime/generated.json b/service/sagemakerruntime/generated.json index 53eae175c56..905f2bb180a 100644 --- a/service/sagemakerruntime/generated.json +++ b/service/sagemakerruntime/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/sagemakerruntime/go.mod b/service/sagemakerruntime/go.mod index c92c28941a8..2f905dd0cfd 100644 --- a/service/sagemakerruntime/go.mod +++ b/service/sagemakerruntime/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -15,6 +16,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sagemakerruntime/go.sum b/service/sagemakerruntime/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sagemakerruntime/go.sum +++ b/service/sagemakerruntime/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/savingsplans/api_client.go b/service/savingsplans/api_client.go index b4b412c6a70..c093aecd30c 100644 --- a/service/savingsplans/api_client.go +++ b/service/savingsplans/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/savingsplans/endpoints.go b/service/savingsplans/endpoints.go index 9975b5bc86e..c6c8da18300 100644 --- a/service/savingsplans/endpoints.go +++ b/service/savingsplans/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/savingsplans/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SAVINGSPLANS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "savingsplans", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/savingsplans/endpoints_config_test.go b/service/savingsplans/endpoints_config_test.go new file mode 100644 index 00000000000..d5db94da6fb --- /dev/null +++ b/service/savingsplans/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package savingsplans + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-savingsplans.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-savingsplans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + expectURL: aws.String("https://env-savingsplans.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-savingsplans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + expectURL: aws.String("http://config-savingsplans.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-savingsplans.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-savingsplans.dev", + clientEndpoint: aws.String("https://client-savingsplans.dev"), + expectURL: aws.String("https://client-savingsplans.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SAVINGSPLANS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/savingsplans/generated.json b/service/savingsplans/generated.json index dee6fbe6ffd..294b862e96a 100644 --- a/service/savingsplans/generated.json +++ b/service/savingsplans/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/savingsplans/go.mod b/service/savingsplans/go.mod index 8b328f176f5..834162a65cd 100644 --- a/service/savingsplans/go.mod +++ b/service/savingsplans/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/savingsplans/go.sum b/service/savingsplans/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/savingsplans/go.sum +++ b/service/savingsplans/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/scheduler/api_client.go b/service/scheduler/api_client.go index d1be85141ab..be0eb84da71 100644 --- a/service/scheduler/api_client.go +++ b/service/scheduler/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/scheduler/endpoints.go b/service/scheduler/endpoints.go index b7007d8812c..5d56a7ed371 100644 --- a/service/scheduler/endpoints.go +++ b/service/scheduler/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/scheduler/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SCHEDULER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Scheduler", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/scheduler/endpoints_config_test.go b/service/scheduler/endpoints_config_test.go new file mode 100644 index 00000000000..aa50b33a8c9 --- /dev/null +++ b/service/scheduler/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package scheduler + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-scheduler.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-scheduler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + expectURL: aws.String("https://env-scheduler.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-scheduler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + expectURL: aws.String("http://config-scheduler.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-scheduler.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-scheduler.dev", + clientEndpoint: aws.String("https://client-scheduler.dev"), + expectURL: aws.String("https://client-scheduler.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SCHEDULER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/scheduler/generated.json b/service/scheduler/generated.json index 71f3cd19c91..342a6192268 100644 --- a/service/scheduler/generated.json +++ b/service/scheduler/generated.json @@ -24,6 +24,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/scheduler/go.mod b/service/scheduler/go.mod index 639299da006..e815fd49698 100644 --- a/service/scheduler/go.mod +++ b/service/scheduler/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/scheduler/go.sum b/service/scheduler/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/scheduler/go.sum +++ b/service/scheduler/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/schemas/api_client.go b/service/schemas/api_client.go index 39089422cd7..bcf1670f21a 100644 --- a/service/schemas/api_client.go +++ b/service/schemas/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/schemas/endpoints.go b/service/schemas/endpoints.go index 7277912cbd0..01eb399d1a6 100644 --- a/service/schemas/endpoints.go +++ b/service/schemas/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/schemas/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SCHEMAS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "schemas", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/schemas/endpoints_config_test.go b/service/schemas/endpoints_config_test.go new file mode 100644 index 00000000000..6941ed34e1d --- /dev/null +++ b/service/schemas/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package schemas + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-schemas.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-schemas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + expectURL: aws.String("https://env-schemas.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-schemas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + expectURL: aws.String("http://config-schemas.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-schemas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-schemas.dev", + clientEndpoint: aws.String("https://client-schemas.dev"), + expectURL: aws.String("https://client-schemas.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SCHEMAS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/schemas/generated.json b/service/schemas/generated.json index 36c0f656b8e..027ac1e14ed 100644 --- a/service/schemas/generated.json +++ b/service/schemas/generated.json @@ -44,6 +44,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/schemas/go.mod b/service/schemas/go.mod index f7a65ac088b..e1542148640 100644 --- a/service/schemas/go.mod +++ b/service/schemas/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/schemas/go.sum b/service/schemas/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/schemas/go.sum +++ b/service/schemas/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/secretsmanager/api_client.go b/service/secretsmanager/api_client.go index 9024fa315e9..e5f9ef45342 100644 --- a/service/secretsmanager/api_client.go +++ b/service/secretsmanager/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/secretsmanager/endpoints.go b/service/secretsmanager/endpoints.go index 4bf660c9b3e..ca93ffb1b80 100644 --- a/service/secretsmanager/endpoints.go +++ b/service/secretsmanager/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/secretsmanager/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SECRETS_MANAGER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Secrets Manager", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/secretsmanager/endpoints_config_test.go b/service/secretsmanager/endpoints_config_test.go new file mode 100644 index 00000000000..0425b1491a0 --- /dev/null +++ b/service/secretsmanager/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package secretsmanager + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-secrets-manager.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-secrets-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + expectURL: aws.String("https://env-secrets-manager.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-secrets-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + expectURL: aws.String("http://config-secrets-manager.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-secrets-manager.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-secrets-manager.dev", + clientEndpoint: aws.String("https://client-secrets-manager.dev"), + expectURL: aws.String("https://client-secrets-manager.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SECRETS_MANAGER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/secretsmanager/generated.json b/service/secretsmanager/generated.json index d166471f1bc..70ed3b92114 100644 --- a/service/secretsmanager/generated.json +++ b/service/secretsmanager/generated.json @@ -34,6 +34,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/secretsmanager/go.mod b/service/secretsmanager/go.mod index 58559cee3eb..f01feac50c3 100644 --- a/service/secretsmanager/go.mod +++ b/service/secretsmanager/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/secretsmanager/go.sum b/service/secretsmanager/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/secretsmanager/go.sum +++ b/service/secretsmanager/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/securityhub/api_client.go b/service/securityhub/api_client.go index 3f659583e01..1a73e1ae46d 100644 --- a/service/securityhub/api_client.go +++ b/service/securityhub/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/securityhub/endpoints.go b/service/securityhub/endpoints.go index 76c4e4d8e25..29624ca1a1e 100644 --- a/service/securityhub/endpoints.go +++ b/service/securityhub/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/securityhub/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SECURITYHUB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SecurityHub", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/securityhub/endpoints_config_test.go b/service/securityhub/endpoints_config_test.go new file mode 100644 index 00000000000..3d511ffc42d --- /dev/null +++ b/service/securityhub/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package securityhub + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-securityhub.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-securityhub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + expectURL: aws.String("https://env-securityhub.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-securityhub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + expectURL: aws.String("http://config-securityhub.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-securityhub.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securityhub.dev", + clientEndpoint: aws.String("https://client-securityhub.dev"), + expectURL: aws.String("https://client-securityhub.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SECURITYHUB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/securityhub/generated.json b/service/securityhub/generated.json index 404eea61213..83124dbc267 100644 --- a/service/securityhub/generated.json +++ b/service/securityhub/generated.json @@ -79,6 +79,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/securityhub/go.mod b/service/securityhub/go.mod index cc39aa242ee..104a73c71d9 100644 --- a/service/securityhub/go.mod +++ b/service/securityhub/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/securityhub/go.sum b/service/securityhub/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/securityhub/go.sum +++ b/service/securityhub/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/securitylake/api_client.go b/service/securitylake/api_client.go index 996803b3977..6202f36f749 100644 --- a/service/securitylake/api_client.go +++ b/service/securitylake/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/securitylake/endpoints.go b/service/securitylake/endpoints.go index 98d52a07b47..98cda62be00 100644 --- a/service/securitylake/endpoints.go +++ b/service/securitylake/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/securitylake/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SECURITYLAKE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SecurityLake", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/securitylake/endpoints_config_test.go b/service/securitylake/endpoints_config_test.go new file mode 100644 index 00000000000..3df5a2659cb --- /dev/null +++ b/service/securitylake/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package securitylake + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-securitylake.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-securitylake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + expectURL: aws.String("https://env-securitylake.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-securitylake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + expectURL: aws.String("http://config-securitylake.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-securitylake.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-securitylake.dev", + clientEndpoint: aws.String("https://client-securitylake.dev"), + expectURL: aws.String("https://client-securitylake.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SECURITYLAKE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/securitylake/generated.json b/service/securitylake/generated.json index c6de888fede..405bccd3b4a 100644 --- a/service/securitylake/generated.json +++ b/service/securitylake/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/securitylake/go.mod b/service/securitylake/go.mod index 203fa635ed0..f8f9b89b017 100644 --- a/service/securitylake/go.mod +++ b/service/securitylake/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/securitylake/go.sum b/service/securitylake/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/securitylake/go.sum +++ b/service/securitylake/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/serverlessapplicationrepository/api_client.go b/service/serverlessapplicationrepository/api_client.go index 6eda73b3040..0819ee580b4 100644 --- a/service/serverlessapplicationrepository/api_client.go +++ b/service/serverlessapplicationrepository/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/serverlessapplicationrepository/endpoints.go b/service/serverlessapplicationrepository/endpoints.go index 78e94a1a726..0c06e09830f 100644 --- a/service/serverlessapplicationrepository/endpoints.go +++ b/service/serverlessapplicationrepository/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/serverlessapplicationrepository/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SERVERLESSAPPLICATIONREPOSITORY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ServerlessApplicationRepository", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/serverlessapplicationrepository/endpoints_config_test.go b/service/serverlessapplicationrepository/endpoints_config_test.go new file mode 100644 index 00000000000..31d904e2288 --- /dev/null +++ b/service/serverlessapplicationrepository/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package serverlessapplicationrepository + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-serverlessapplicationrepository.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-serverlessapplicationrepository.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + expectURL: aws.String("https://env-serverlessapplicationrepository.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-serverlessapplicationrepository.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + expectURL: aws.String("http://config-serverlessapplicationrepository.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-serverlessapplicationrepository.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-serverlessapplicationrepository.dev", + clientEndpoint: aws.String("https://client-serverlessapplicationrepository.dev"), + expectURL: aws.String("https://client-serverlessapplicationrepository.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SERVERLESSAPPLICATIONREPOSITORY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/serverlessapplicationrepository/generated.json b/service/serverlessapplicationrepository/generated.json index d3965903276..dfe10849039 100644 --- a/service/serverlessapplicationrepository/generated.json +++ b/service/serverlessapplicationrepository/generated.json @@ -26,6 +26,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/serverlessapplicationrepository/go.mod b/service/serverlessapplicationrepository/go.mod index 79d52db53f0..f5ccc29fce5 100644 --- a/service/serverlessapplicationrepository/go.mod +++ b/service/serverlessapplicationrepository/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/serverlessapplicationrepository/go.sum b/service/serverlessapplicationrepository/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/serverlessapplicationrepository/go.sum +++ b/service/serverlessapplicationrepository/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/servicecatalog/api_client.go b/service/servicecatalog/api_client.go index 0698746118d..db232cfd73f 100644 --- a/service/servicecatalog/api_client.go +++ b/service/servicecatalog/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/servicecatalog/endpoints.go b/service/servicecatalog/endpoints.go index 26b3ca0b4b6..3c27845f276 100644 --- a/service/servicecatalog/endpoints.go +++ b/service/servicecatalog/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/servicecatalog/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SERVICE_CATALOG") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Service Catalog", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/servicecatalog/endpoints_config_test.go b/service/servicecatalog/endpoints_config_test.go new file mode 100644 index 00000000000..e0b0b9fb3ad --- /dev/null +++ b/service/servicecatalog/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package servicecatalog + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + expectURL: aws.String("https://env-service-catalog.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + expectURL: aws.String("http://config-service-catalog.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog.dev", + clientEndpoint: aws.String("https://client-service-catalog.dev"), + expectURL: aws.String("https://client-service-catalog.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SERVICE_CATALOG", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/servicecatalog/generated.json b/service/servicecatalog/generated.json index f7eb5cb49a4..6b7d572800b 100644 --- a/service/servicecatalog/generated.json +++ b/service/servicecatalog/generated.json @@ -102,6 +102,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/servicecatalog/go.mod b/service/servicecatalog/go.mod index 8692f1aef3e..2035f3afc32 100644 --- a/service/servicecatalog/go.mod +++ b/service/servicecatalog/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/servicecatalog/go.sum b/service/servicecatalog/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/servicecatalog/go.sum +++ b/service/servicecatalog/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/servicecatalogappregistry/api_client.go b/service/servicecatalogappregistry/api_client.go index 47dd254c5b3..f73853936df 100644 --- a/service/servicecatalogappregistry/api_client.go +++ b/service/servicecatalogappregistry/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/servicecatalogappregistry/endpoints.go b/service/servicecatalogappregistry/endpoints.go index 47a440ff268..f6dba19a28d 100644 --- a/service/servicecatalogappregistry/endpoints.go +++ b/service/servicecatalogappregistry/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SERVICE_CATALOG_APPREGISTRY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Service Catalog AppRegistry", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/servicecatalogappregistry/endpoints_config_test.go b/service/servicecatalogappregistry/endpoints_config_test.go new file mode 100644 index 00000000000..788d95c3d8a --- /dev/null +++ b/service/servicecatalogappregistry/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package servicecatalogappregistry + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog-appregistry.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog-appregistry.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + expectURL: aws.String("https://env-service-catalog-appregistry.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog-appregistry.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + expectURL: aws.String("http://config-service-catalog-appregistry.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-catalog-appregistry.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-catalog-appregistry.dev", + clientEndpoint: aws.String("https://client-service-catalog-appregistry.dev"), + expectURL: aws.String("https://client-service-catalog-appregistry.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SERVICE_CATALOG_APPREGISTRY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/servicecatalogappregistry/generated.json b/service/servicecatalogappregistry/generated.json index 0b01bff20d3..d1b97b2aa1e 100644 --- a/service/servicecatalogappregistry/generated.json +++ b/service/servicecatalogappregistry/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/servicecatalogappregistry/go.mod b/service/servicecatalogappregistry/go.mod index 93a4f632523..11221937330 100644 --- a/service/servicecatalogappregistry/go.mod +++ b/service/servicecatalogappregistry/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/servicecatalogappregistry/go.sum b/service/servicecatalogappregistry/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/servicecatalogappregistry/go.sum +++ b/service/servicecatalogappregistry/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/servicediscovery/api_client.go b/service/servicediscovery/api_client.go index e1b79b7fc71..ea642639b64 100644 --- a/service/servicediscovery/api_client.go +++ b/service/servicediscovery/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/servicediscovery/endpoints.go b/service/servicediscovery/endpoints.go index 4b8499f7225..71cb8f4d559 100644 --- a/service/servicediscovery/endpoints.go +++ b/service/servicediscovery/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/servicediscovery/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SERVICEDISCOVERY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "ServiceDiscovery", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/servicediscovery/endpoints_config_test.go b/service/servicediscovery/endpoints_config_test.go new file mode 100644 index 00000000000..a99fc613b11 --- /dev/null +++ b/service/servicediscovery/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package servicediscovery + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-servicediscovery.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-servicediscovery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + expectURL: aws.String("https://env-servicediscovery.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-servicediscovery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + expectURL: aws.String("http://config-servicediscovery.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-servicediscovery.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-servicediscovery.dev", + clientEndpoint: aws.String("https://client-servicediscovery.dev"), + expectURL: aws.String("https://client-servicediscovery.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SERVICEDISCOVERY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/servicediscovery/generated.json b/service/servicediscovery/generated.json index 1585669d7e2..a2c0a4cfc4a 100644 --- a/service/servicediscovery/generated.json +++ b/service/servicediscovery/generated.json @@ -39,6 +39,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/servicediscovery/go.mod b/service/servicediscovery/go.mod index b45d125c49d..46f4d52a652 100644 --- a/service/servicediscovery/go.mod +++ b/service/servicediscovery/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/servicediscovery/go.sum b/service/servicediscovery/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/servicediscovery/go.sum +++ b/service/servicediscovery/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/servicequotas/api_client.go b/service/servicequotas/api_client.go index 435f9e115e4..305a851e0e1 100644 --- a/service/servicequotas/api_client.go +++ b/service/servicequotas/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/servicequotas/endpoints.go b/service/servicequotas/endpoints.go index 834d524e5a3..e7805c67941 100644 --- a/service/servicequotas/endpoints.go +++ b/service/servicequotas/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/servicequotas/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SERVICE_QUOTAS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Service Quotas", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/servicequotas/endpoints_config_test.go b/service/servicequotas/endpoints_config_test.go new file mode 100644 index 00000000000..aa505987b5b --- /dev/null +++ b/service/servicequotas/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package servicequotas + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-quotas.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-quotas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + expectURL: aws.String("https://env-service-quotas.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-quotas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + expectURL: aws.String("http://config-service-quotas.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-service-quotas.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-service-quotas.dev", + clientEndpoint: aws.String("https://client-service-quotas.dev"), + expectURL: aws.String("https://client-service-quotas.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SERVICE_QUOTAS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/servicequotas/generated.json b/service/servicequotas/generated.json index ab069405bd9..7e6f3219386 100644 --- a/service/servicequotas/generated.json +++ b/service/servicequotas/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/servicequotas/go.mod b/service/servicequotas/go.mod index 13b225fbe7f..eed87a660f3 100644 --- a/service/servicequotas/go.mod +++ b/service/servicequotas/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/servicequotas/go.sum b/service/servicequotas/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/servicequotas/go.sum +++ b/service/servicequotas/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ses/api_client.go b/service/ses/api_client.go index 61712ca9c05..5c66a497d37 100644 --- a/service/ses/api_client.go +++ b/service/ses/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ses/endpoints.go b/service/ses/endpoints.go index 5133ced7ece..9ab24435b6d 100644 --- a/service/ses/endpoints.go +++ b/service/ses/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ses/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SES", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ses/endpoints_config_test.go b/service/ses/endpoints_config_test.go new file mode 100644 index 00000000000..ad4e2312d67 --- /dev/null +++ b/service/ses/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ses + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ses.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ses.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + expectURL: aws.String("https://env-ses.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ses.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + expectURL: aws.String("http://config-ses.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ses.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ses.dev", + clientEndpoint: aws.String("https://client-ses.dev"), + expectURL: aws.String("https://client-ses.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ses/generated.json b/service/ses/generated.json index a59b4127de7..eb9843d2c17 100644 --- a/service/ses/generated.json +++ b/service/ses/generated.json @@ -84,6 +84,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ses/go.mod b/service/ses/go.mod index db5fba2710a..bb2f6cb24f0 100644 --- a/service/ses/go.mod +++ b/service/ses/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ses/go.sum b/service/ses/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/ses/go.sum +++ b/service/ses/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/sesv2/api_client.go b/service/sesv2/api_client.go index a76a0ad8c7b..f46e8d33f18 100644 --- a/service/sesv2/api_client.go +++ b/service/sesv2/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sesv2/endpoints.go b/service/sesv2/endpoints.go index 3f3769dab7b..c94f7789a50 100644 --- a/service/sesv2/endpoints.go +++ b/service/sesv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sesv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SESV2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SESv2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sesv2/endpoints_config_test.go b/service/sesv2/endpoints_config_test.go new file mode 100644 index 00000000000..b8b4b823e1d --- /dev/null +++ b/service/sesv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sesv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sesv2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sesv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + expectURL: aws.String("https://env-sesv2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sesv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + expectURL: aws.String("http://config-sesv2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sesv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sesv2.dev", + clientEndpoint: aws.String("https://client-sesv2.dev"), + expectURL: aws.String("https://client-sesv2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SESV2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sesv2/generated.json b/service/sesv2/generated.json index 2a98f96d27e..bd906fcec50 100644 --- a/service/sesv2/generated.json +++ b/service/sesv2/generated.json @@ -104,6 +104,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sesv2/go.mod b/service/sesv2/go.mod index c21b71ada39..5d8d671d288 100644 --- a/service/sesv2/go.mod +++ b/service/sesv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sesv2/go.sum b/service/sesv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sesv2/go.sum +++ b/service/sesv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sfn/api_client.go b/service/sfn/api_client.go index 379babace9c..d2d3a8af1e6 100644 --- a/service/sfn/api_client.go +++ b/service/sfn/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sfn/endpoints.go b/service/sfn/endpoints.go index 5b23c510e92..c32cc8a39ab 100644 --- a/service/sfn/endpoints.go +++ b/service/sfn/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sfn/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SFN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SFN", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sfn/endpoints_config_test.go b/service/sfn/endpoints_config_test.go new file mode 100644 index 00000000000..f5e6c8dbadd --- /dev/null +++ b/service/sfn/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sfn + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sfn.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sfn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + expectURL: aws.String("https://env-sfn.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sfn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + expectURL: aws.String("http://config-sfn.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sfn.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sfn.dev", + clientEndpoint: aws.String("https://client-sfn.dev"), + expectURL: aws.String("https://client-sfn.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SFN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sfn/generated.json b/service/sfn/generated.json index aaaf23ec312..81682d2b988 100644 --- a/service/sfn/generated.json +++ b/service/sfn/generated.json @@ -46,6 +46,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sfn/go.mod b/service/sfn/go.mod index 1942cd1be3a..9183092951a 100644 --- a/service/sfn/go.mod +++ b/service/sfn/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sfn/go.sum b/service/sfn/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sfn/go.sum +++ b/service/sfn/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/shield/api_client.go b/service/shield/api_client.go index 9527e63b55a..f23907d6ea9 100644 --- a/service/shield/api_client.go +++ b/service/shield/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/shield/endpoints.go b/service/shield/endpoints.go index 8838bc7c12e..b106be7bf26 100644 --- a/service/shield/endpoints.go +++ b/service/shield/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/shield/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SHIELD") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Shield", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/shield/endpoints_config_test.go b/service/shield/endpoints_config_test.go new file mode 100644 index 00000000000..3f7d5c806c9 --- /dev/null +++ b/service/shield/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package shield + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-shield.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-shield.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + expectURL: aws.String("https://env-shield.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-shield.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + expectURL: aws.String("http://config-shield.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-shield.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-shield.dev", + clientEndpoint: aws.String("https://client-shield.dev"), + expectURL: aws.String("https://client-shield.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SHIELD", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/shield/generated.json b/service/shield/generated.json index 13c3ed93357..5496393bdb9 100644 --- a/service/shield/generated.json +++ b/service/shield/generated.json @@ -48,6 +48,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/shield/go.mod b/service/shield/go.mod index 94553236036..6d2373c9b5f 100644 --- a/service/shield/go.mod +++ b/service/shield/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/shield/go.sum b/service/shield/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/shield/go.sum +++ b/service/shield/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/signer/api_client.go b/service/signer/api_client.go index b6785b1a5e3..6afc1a54210 100644 --- a/service/signer/api_client.go +++ b/service/signer/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/signer/endpoints.go b/service/signer/endpoints.go index 0c9583d2c21..75c2900bcb6 100644 --- a/service/signer/endpoints.go +++ b/service/signer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/signer/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SIGNER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "signer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/signer/endpoints_config_test.go b/service/signer/endpoints_config_test.go new file mode 100644 index 00000000000..629bfc29981 --- /dev/null +++ b/service/signer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package signer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-signer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-signer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + expectURL: aws.String("https://env-signer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-signer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + expectURL: aws.String("http://config-signer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-signer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-signer.dev", + clientEndpoint: aws.String("https://client-signer.dev"), + expectURL: aws.String("https://client-signer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SIGNER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/signer/generated.json b/service/signer/generated.json index ffb3eb42b45..9fe016f02f0 100644 --- a/service/signer/generated.json +++ b/service/signer/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/signer/go.mod b/service/signer/go.mod index ff2925a1433..be2bf1f5e04 100644 --- a/service/signer/go.mod +++ b/service/signer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/signer/go.sum b/service/signer/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/signer/go.sum +++ b/service/signer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/simspaceweaver/api_client.go b/service/simspaceweaver/api_client.go index 87d8a09db73..0483620e99a 100644 --- a/service/simspaceweaver/api_client.go +++ b/service/simspaceweaver/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/simspaceweaver/endpoints.go b/service/simspaceweaver/endpoints.go index 01997e76ba3..628657b5f23 100644 --- a/service/simspaceweaver/endpoints.go +++ b/service/simspaceweaver/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/simspaceweaver/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SIMSPACEWEAVER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SimSpaceWeaver", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/simspaceweaver/endpoints_config_test.go b/service/simspaceweaver/endpoints_config_test.go new file mode 100644 index 00000000000..9601c217ee8 --- /dev/null +++ b/service/simspaceweaver/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package simspaceweaver + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-simspaceweaver.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-simspaceweaver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + expectURL: aws.String("https://env-simspaceweaver.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-simspaceweaver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + expectURL: aws.String("http://config-simspaceweaver.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-simspaceweaver.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-simspaceweaver.dev", + clientEndpoint: aws.String("https://client-simspaceweaver.dev"), + expectURL: aws.String("https://client-simspaceweaver.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SIMSPACEWEAVER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/simspaceweaver/generated.json b/service/simspaceweaver/generated.json index 8bd7eb72bea..120e131f17c 100644 --- a/service/simspaceweaver/generated.json +++ b/service/simspaceweaver/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/simspaceweaver/go.mod b/service/simspaceweaver/go.mod index e98dc6a7b0b..d295f7ceb49 100644 --- a/service/simspaceweaver/go.mod +++ b/service/simspaceweaver/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/simspaceweaver/go.sum b/service/simspaceweaver/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/simspaceweaver/go.sum +++ b/service/simspaceweaver/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sms/api_client.go b/service/sms/api_client.go index 81dd17f2934..8ae4b60280d 100644 --- a/service/sms/api_client.go +++ b/service/sms/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sms/endpoints.go b/service/sms/endpoints.go index 2a58427103b..0063eecfbe8 100644 --- a/service/sms/endpoints.go +++ b/service/sms/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sms/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SMS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SMS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sms/endpoints_config_test.go b/service/sms/endpoints_config_test.go new file mode 100644 index 00000000000..f06ace1aa4f --- /dev/null +++ b/service/sms/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sms + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sms.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + expectURL: aws.String("https://env-sms.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + expectURL: aws.String("http://config-sms.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sms.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sms.dev", + clientEndpoint: aws.String("https://client-sms.dev"), + expectURL: aws.String("https://client-sms.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SMS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sms/generated.json b/service/sms/generated.json index a47871d7f45..73e7ef4d1f4 100644 --- a/service/sms/generated.json +++ b/service/sms/generated.json @@ -47,6 +47,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sms/go.mod b/service/sms/go.mod index abf9d6a3e82..4b145b1f0a9 100644 --- a/service/sms/go.mod +++ b/service/sms/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sms/go.sum b/service/sms/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sms/go.sum +++ b/service/sms/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/snowball/api_client.go b/service/snowball/api_client.go index fcaa4ff26e4..63ad538e91e 100644 --- a/service/snowball/api_client.go +++ b/service/snowball/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/snowball/endpoints.go b/service/snowball/endpoints.go index fa10a6a509b..370a60b3b1d 100644 --- a/service/snowball/endpoints.go +++ b/service/snowball/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/snowball/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SNOWBALL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Snowball", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/snowball/endpoints_config_test.go b/service/snowball/endpoints_config_test.go new file mode 100644 index 00000000000..3ea65d74952 --- /dev/null +++ b/service/snowball/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package snowball + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-snowball.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-snowball.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + expectURL: aws.String("https://env-snowball.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-snowball.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + expectURL: aws.String("http://config-snowball.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-snowball.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snowball.dev", + clientEndpoint: aws.String("https://client-snowball.dev"), + expectURL: aws.String("https://client-snowball.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SNOWBALL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/snowball/generated.json b/service/snowball/generated.json index 3da93f8caae..efd27d07fb6 100644 --- a/service/snowball/generated.json +++ b/service/snowball/generated.json @@ -39,6 +39,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/snowball/go.mod b/service/snowball/go.mod index 438659c5d77..25495c9079a 100644 --- a/service/snowball/go.mod +++ b/service/snowball/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/snowball/go.sum b/service/snowball/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/snowball/go.sum +++ b/service/snowball/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/snowdevicemanagement/api_client.go b/service/snowdevicemanagement/api_client.go index f275b47dd9a..e27d3b9e423 100644 --- a/service/snowdevicemanagement/api_client.go +++ b/service/snowdevicemanagement/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/snowdevicemanagement/endpoints.go b/service/snowdevicemanagement/endpoints.go index 69aa758e2e6..964828ebff5 100644 --- a/service/snowdevicemanagement/endpoints.go +++ b/service/snowdevicemanagement/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/snowdevicemanagement/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SNOW_DEVICE_MANAGEMENT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Snow Device Management", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/snowdevicemanagement/endpoints_config_test.go b/service/snowdevicemanagement/endpoints_config_test.go new file mode 100644 index 00000000000..cbe9aac7ffe --- /dev/null +++ b/service/snowdevicemanagement/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package snowdevicemanagement + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-snow-device-management.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-snow-device-management.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + expectURL: aws.String("https://env-snow-device-management.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-snow-device-management.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + expectURL: aws.String("http://config-snow-device-management.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-snow-device-management.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-snow-device-management.dev", + clientEndpoint: aws.String("https://client-snow-device-management.dev"), + expectURL: aws.String("https://client-snow-device-management.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SNOW_DEVICE_MANAGEMENT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/snowdevicemanagement/generated.json b/service/snowdevicemanagement/generated.json index f72c9d97cab..d36010d6f2a 100644 --- a/service/snowdevicemanagement/generated.json +++ b/service/snowdevicemanagement/generated.json @@ -25,6 +25,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/snowdevicemanagement/go.mod b/service/snowdevicemanagement/go.mod index c1eef2f78ab..f4256d9b973 100644 --- a/service/snowdevicemanagement/go.mod +++ b/service/snowdevicemanagement/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/snowdevicemanagement/go.sum b/service/snowdevicemanagement/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/snowdevicemanagement/go.sum +++ b/service/snowdevicemanagement/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sns/api_client.go b/service/sns/api_client.go index 8aff3b63f2c..dc56c5785c7 100644 --- a/service/sns/api_client.go +++ b/service/sns/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sns/endpoints.go b/service/sns/endpoints.go index 45415dd3859..b88ab60da46 100644 --- a/service/sns/endpoints.go +++ b/service/sns/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sns/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SNS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SNS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sns/endpoints_config_test.go b/service/sns/endpoints_config_test.go new file mode 100644 index 00000000000..42b0c23ad55 --- /dev/null +++ b/service/sns/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sns + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sns.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + expectURL: aws.String("https://env-sns.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + expectURL: aws.String("http://config-sns.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sns.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sns.dev", + clientEndpoint: aws.String("https://client-sns.dev"), + expectURL: aws.String("https://client-sns.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SNS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sns/generated.json b/service/sns/generated.json index bdfc3e0b4eb..a014f303a0c 100644 --- a/service/sns/generated.json +++ b/service/sns/generated.json @@ -54,6 +54,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sns/go.mod b/service/sns/go.mod index 0bca3172466..2fd662eb729 100644 --- a/service/sns/go.mod +++ b/service/sns/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sns/go.sum b/service/sns/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sns/go.sum +++ b/service/sns/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sqs/api_client.go b/service/sqs/api_client.go index 52b8bc240f0..2aaaf57a3d6 100644 --- a/service/sqs/api_client.go +++ b/service/sqs/api_client.go @@ -300,6 +300,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sqs/endpoints.go b/service/sqs/endpoints.go index d101e395db5..78c750243f7 100644 --- a/service/sqs/endpoints.go +++ b/service/sqs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sqs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SQS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SQS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sqs/endpoints_config_test.go b/service/sqs/endpoints_config_test.go new file mode 100644 index 00000000000..ac54579713a --- /dev/null +++ b/service/sqs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sqs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sqs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sqs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + expectURL: aws.String("https://env-sqs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sqs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + expectURL: aws.String("http://config-sqs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sqs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sqs.dev", + clientEndpoint: aws.String("https://client-sqs.dev"), + expectURL: aws.String("https://client-sqs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SQS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sqs/generated.json b/service/sqs/generated.json index c4ab0445102..f410f01b564 100644 --- a/service/sqs/generated.json +++ b/service/sqs/generated.json @@ -35,6 +35,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sqs/go.mod b/service/sqs/go.mod index 1e9d7546eff..d41a949302a 100644 --- a/service/sqs/go.mod +++ b/service/sqs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sqs/go.sum b/service/sqs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/sqs/go.sum +++ b/service/sqs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ssm/api_client.go b/service/ssm/api_client.go index 1508dddfc9a..cdb382f5f06 100644 --- a/service/ssm/api_client.go +++ b/service/ssm/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssm/endpoints.go b/service/ssm/endpoints.go index 1e8a8732a91..9fdbe384ac5 100644 --- a/service/ssm/endpoints.go +++ b/service/ssm/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssm/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSM", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssm/endpoints_config_test.go b/service/ssm/endpoints_config_test.go new file mode 100644 index 00000000000..f88a27adae5 --- /dev/null +++ b/service/ssm/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssm + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + expectURL: aws.String("https://env-ssm.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + expectURL: aws.String("http://config-ssm.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm.dev", + clientEndpoint: aws.String("https://client-ssm.dev"), + expectURL: aws.String("https://client-ssm.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssm/generated.json b/service/ssm/generated.json index a3aaad95247..39a15ccf261 100644 --- a/service/ssm/generated.json +++ b/service/ssm/generated.json @@ -152,6 +152,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssm/go.mod b/service/ssm/go.mod index f93c82765da..a834845e278 100644 --- a/service/ssm/go.mod +++ b/service/ssm/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssm/go.sum b/service/ssm/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/ssm/go.sum +++ b/service/ssm/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/ssmcontacts/api_client.go b/service/ssmcontacts/api_client.go index b5647dad7db..1a8ab15c060 100644 --- a/service/ssmcontacts/api_client.go +++ b/service/ssmcontacts/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssmcontacts/endpoints.go b/service/ssmcontacts/endpoints.go index 1fc7ac604e6..d8b9f7b1979 100644 --- a/service/ssmcontacts/endpoints.go +++ b/service/ssmcontacts/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssmcontacts/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSM_CONTACTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSM Contacts", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssmcontacts/endpoints_config_test.go b/service/ssmcontacts/endpoints_config_test.go new file mode 100644 index 00000000000..e4fe1d6882f --- /dev/null +++ b/service/ssmcontacts/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssmcontacts + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-contacts.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-contacts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + expectURL: aws.String("https://env-ssm-contacts.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-contacts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + expectURL: aws.String("http://config-ssm-contacts.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-contacts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-contacts.dev", + clientEndpoint: aws.String("https://client-ssm-contacts.dev"), + expectURL: aws.String("https://client-ssm-contacts.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSM_CONTACTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssmcontacts/generated.json b/service/ssmcontacts/generated.json index e5f85f27658..baa30b31a12 100644 --- a/service/ssmcontacts/generated.json +++ b/service/ssmcontacts/generated.json @@ -51,6 +51,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssmcontacts/go.mod b/service/ssmcontacts/go.mod index 6ab0e54014b..f5179e24ab8 100644 --- a/service/ssmcontacts/go.mod +++ b/service/ssmcontacts/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssmcontacts/go.sum b/service/ssmcontacts/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ssmcontacts/go.sum +++ b/service/ssmcontacts/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ssmincidents/api_client.go b/service/ssmincidents/api_client.go index b5b625d79ba..292f0386748 100644 --- a/service/ssmincidents/api_client.go +++ b/service/ssmincidents/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssmincidents/endpoints.go b/service/ssmincidents/endpoints.go index a10678e9b62..166afd56392 100644 --- a/service/ssmincidents/endpoints.go +++ b/service/ssmincidents/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssmincidents/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSM_INCIDENTS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSM Incidents", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssmincidents/endpoints_config_test.go b/service/ssmincidents/endpoints_config_test.go new file mode 100644 index 00000000000..d213bce4523 --- /dev/null +++ b/service/ssmincidents/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssmincidents + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-incidents.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-incidents.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + expectURL: aws.String("https://env-ssm-incidents.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-incidents.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + expectURL: aws.String("http://config-ssm-incidents.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-incidents.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-incidents.dev", + clientEndpoint: aws.String("https://client-ssm-incidents.dev"), + expectURL: aws.String("https://client-ssm-incidents.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSM_INCIDENTS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssmincidents/generated.json b/service/ssmincidents/generated.json index 8a4c8c53619..3fb8812044f 100644 --- a/service/ssmincidents/generated.json +++ b/service/ssmincidents/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssmincidents/go.mod b/service/ssmincidents/go.mod index ea432c71d34..93b02707873 100644 --- a/service/ssmincidents/go.mod +++ b/service/ssmincidents/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssmincidents/go.sum b/service/ssmincidents/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/ssmincidents/go.sum +++ b/service/ssmincidents/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/ssmsap/api_client.go b/service/ssmsap/api_client.go index db6dc09b938..776969b6020 100644 --- a/service/ssmsap/api_client.go +++ b/service/ssmsap/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssmsap/endpoints.go b/service/ssmsap/endpoints.go index 92c10aa89d2..46e517724fa 100644 --- a/service/ssmsap/endpoints.go +++ b/service/ssmsap/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssmsap/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSM_SAP") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Ssm Sap", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssmsap/endpoints_config_test.go b/service/ssmsap/endpoints_config_test.go new file mode 100644 index 00000000000..842c6d1510b --- /dev/null +++ b/service/ssmsap/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssmsap + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-sap.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-sap.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + expectURL: aws.String("https://env-ssm-sap.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-sap.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + expectURL: aws.String("http://config-ssm-sap.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-ssm-sap.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-ssm-sap.dev", + clientEndpoint: aws.String("https://client-ssm-sap.dev"), + expectURL: aws.String("https://client-ssm-sap.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSM_SAP", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssmsap/generated.json b/service/ssmsap/generated.json index 54805814f72..0b6b42be22b 100644 --- a/service/ssmsap/generated.json +++ b/service/ssmsap/generated.json @@ -30,6 +30,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssmsap/go.mod b/service/ssmsap/go.mod index 701305ffa2f..5a99fddb548 100644 --- a/service/ssmsap/go.mod +++ b/service/ssmsap/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssmsap/go.sum b/service/ssmsap/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ssmsap/go.sum +++ b/service/ssmsap/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sso/api_client.go b/service/sso/api_client.go index da4e470a60b..a2579227393 100644 --- a/service/sso/api_client.go +++ b/service/sso/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sso/endpoints.go b/service/sso/endpoints.go index 6a2c7eb3e10..42c62e7c8ad 100644 --- a/service/sso/endpoints.go +++ b/service/sso/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sso/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSO") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSO", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sso/endpoints_config_test.go b/service/sso/endpoints_config_test.go new file mode 100644 index 00000000000..f6af998599c --- /dev/null +++ b/service/sso/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sso + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + expectURL: aws.String("https://env-sso.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + expectURL: aws.String("http://config-sso.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso.dev", + clientEndpoint: aws.String("https://client-sso.dev"), + expectURL: aws.String("https://client-sso.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSO", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sso/generated.json b/service/sso/generated.json index ab6af36e87e..8e618418710 100644 --- a/service/sso/generated.json +++ b/service/sso/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sso/go.mod b/service/sso/go.mod index 6780bb2fc6a..2323e98b5d0 100644 --- a/service/sso/go.mod +++ b/service/sso/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sso/go.sum b/service/sso/go.sum index a646f1d3099..f404e03a89f 100644 --- a/service/sso/go.sum +++ b/service/sso/go.sum @@ -1,3 +1,20 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ssoadmin/api_client.go b/service/ssoadmin/api_client.go index f3705df63ed..1e89e142681 100644 --- a/service/ssoadmin/api_client.go +++ b/service/ssoadmin/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssoadmin/endpoints.go b/service/ssoadmin/endpoints.go index 72ceb17b485..eda18872c60 100644 --- a/service/ssoadmin/endpoints.go +++ b/service/ssoadmin/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssoadmin/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSO_ADMIN") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSO Admin", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssoadmin/endpoints_config_test.go b/service/ssoadmin/endpoints_config_test.go new file mode 100644 index 00000000000..5f3f59ebccd --- /dev/null +++ b/service/ssoadmin/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssoadmin + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-admin.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-admin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + expectURL: aws.String("https://env-sso-admin.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-admin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + expectURL: aws.String("http://config-sso-admin.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-admin.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-admin.dev", + clientEndpoint: aws.String("https://client-sso-admin.dev"), + expectURL: aws.String("https://client-sso-admin.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSO_ADMIN", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssoadmin/generated.json b/service/ssoadmin/generated.json index 301e6472431..88c408b674e 100644 --- a/service/ssoadmin/generated.json +++ b/service/ssoadmin/generated.json @@ -49,6 +49,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssoadmin/go.mod b/service/ssoadmin/go.mod index e21b256e482..1df58e85bad 100644 --- a/service/ssoadmin/go.mod +++ b/service/ssoadmin/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssoadmin/go.sum b/service/ssoadmin/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/ssoadmin/go.sum +++ b/service/ssoadmin/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/ssooidc/api_client.go b/service/ssooidc/api_client.go index 24a692276ff..6a56093d8ac 100644 --- a/service/ssooidc/api_client.go +++ b/service/ssooidc/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/ssooidc/endpoints.go b/service/ssooidc/endpoints.go index e8d190e48a4..739c13a71dc 100644 --- a/service/ssooidc/endpoints.go +++ b/service/ssooidc/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/ssooidc/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SSO_OIDC") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SSO OIDC", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/ssooidc/endpoints_config_test.go b/service/ssooidc/endpoints_config_test.go new file mode 100644 index 00000000000..cbbb1365916 --- /dev/null +++ b/service/ssooidc/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package ssooidc + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-oidc.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-oidc.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + expectURL: aws.String("https://env-sso-oidc.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-oidc.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + expectURL: aws.String("http://config-sso-oidc.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sso-oidc.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sso-oidc.dev", + clientEndpoint: aws.String("https://client-sso-oidc.dev"), + expectURL: aws.String("https://client-sso-oidc.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SSO_OIDC", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/ssooidc/generated.json b/service/ssooidc/generated.json index fe2d075ad73..403fac7c5af 100644 --- a/service/ssooidc/generated.json +++ b/service/ssooidc/generated.json @@ -15,6 +15,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/ssooidc/go.mod b/service/ssooidc/go.mod index 06c0d0e4ef6..a56b8df01b8 100644 --- a/service/ssooidc/go.mod +++ b/service/ssooidc/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/ssooidc/go.sum b/service/ssooidc/go.sum index a646f1d3099..5d1fcd2196b 100644 --- a/service/ssooidc/go.sum +++ b/service/ssooidc/go.sum @@ -1,3 +1,20 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/storagegateway/api_client.go b/service/storagegateway/api_client.go index a142d76978c..0d1045b9e48 100644 --- a/service/storagegateway/api_client.go +++ b/service/storagegateway/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/storagegateway/endpoints.go b/service/storagegateway/endpoints.go index fdbf71059a2..568e0075e40 100644 --- a/service/storagegateway/endpoints.go +++ b/service/storagegateway/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/storagegateway/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_STORAGE_GATEWAY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Storage Gateway", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/storagegateway/endpoints_config_test.go b/service/storagegateway/endpoints_config_test.go new file mode 100644 index 00000000000..e9c0f8e12b7 --- /dev/null +++ b/service/storagegateway/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package storagegateway + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-storage-gateway.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-storage-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + expectURL: aws.String("https://env-storage-gateway.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-storage-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + expectURL: aws.String("http://config-storage-gateway.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-storage-gateway.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-storage-gateway.dev", + clientEndpoint: aws.String("https://client-storage-gateway.dev"), + expectURL: aws.String("https://client-storage-gateway.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_STORAGE_GATEWAY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/storagegateway/generated.json b/service/storagegateway/generated.json index 44bbca649bf..da8ea5afc9e 100644 --- a/service/storagegateway/generated.json +++ b/service/storagegateway/generated.json @@ -102,6 +102,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/storagegateway/go.mod b/service/storagegateway/go.mod index 9feec342951..b0e6f575233 100644 --- a/service/storagegateway/go.mod +++ b/service/storagegateway/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/storagegateway/go.sum b/service/storagegateway/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/storagegateway/go.sum +++ b/service/storagegateway/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/sts/api_client.go b/service/sts/api_client.go index 22ac6904306..c29d8cad17a 100644 --- a/service/sts/api_client.go +++ b/service/sts/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/sts/endpoints.go b/service/sts/endpoints.go index ef1caae8d36..02396a91373 100644 --- a/service/sts/endpoints.go +++ b/service/sts/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/sts/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_STS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "STS", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/sts/endpoints_config_test.go b/service/sts/endpoints_config_test.go new file mode 100644 index 00000000000..300256aadb2 --- /dev/null +++ b/service/sts/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package sts + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sts.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-sts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + expectURL: aws.String("https://env-sts.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-sts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + expectURL: aws.String("http://config-sts.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-sts.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-sts.dev", + clientEndpoint: aws.String("https://client-sts.dev"), + expectURL: aws.String("https://client-sts.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_STS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/sts/generated.json b/service/sts/generated.json index 2ae7a9b23bb..e44e7d149c5 100644 --- a/service/sts/generated.json +++ b/service/sts/generated.json @@ -21,6 +21,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/sts/go.mod b/service/sts/go.mod index 6f2f551c14a..8ab549d7109 100644 --- a/service/sts/go.mod +++ b/service/sts/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 github.com/aws/smithy-go v1.15.0 @@ -13,8 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/sts/go.sum b/service/sts/go.sum index a646f1d3099..96e558a7666 100644 --- a/service/sts/go.sum +++ b/service/sts/go.sum @@ -1,3 +1,18 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/support/api_client.go b/service/support/api_client.go index 670a359ef94..d9e249b8b16 100644 --- a/service/support/api_client.go +++ b/service/support/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/support/endpoints.go b/service/support/endpoints.go index 557f95ba766..1968643dfd8 100644 --- a/service/support/endpoints.go +++ b/service/support/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/support/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SUPPORT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Support", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/support/endpoints_config_test.go b/service/support/endpoints_config_test.go new file mode 100644 index 00000000000..22b9c9d218d --- /dev/null +++ b/service/support/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package support + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-support.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-support.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + expectURL: aws.String("https://env-support.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-support.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + expectURL: aws.String("http://config-support.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-support.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support.dev", + clientEndpoint: aws.String("https://client-support.dev"), + expectURL: aws.String("https://client-support.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SUPPORT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/support/generated.json b/service/support/generated.json index 502ab58ea86..3f95572bd5f 100644 --- a/service/support/generated.json +++ b/service/support/generated.json @@ -28,6 +28,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/support/go.mod b/service/support/go.mod index d9d1c830bde..0011fed4a68 100644 --- a/service/support/go.mod +++ b/service/support/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/support/go.sum b/service/support/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/support/go.sum +++ b/service/support/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/supportapp/api_client.go b/service/supportapp/api_client.go index c593129fcc1..0c2ec9085b9 100644 --- a/service/supportapp/api_client.go +++ b/service/supportapp/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/supportapp/endpoints.go b/service/supportapp/endpoints.go index 53de8ea0f8c..58ec8729212 100644 --- a/service/supportapp/endpoints.go +++ b/service/supportapp/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/supportapp/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SUPPORT_APP") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Support App", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/supportapp/endpoints_config_test.go b/service/supportapp/endpoints_config_test.go new file mode 100644 index 00000000000..0442b186316 --- /dev/null +++ b/service/supportapp/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package supportapp + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-support-app.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-support-app.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + expectURL: aws.String("https://env-support-app.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-support-app.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + expectURL: aws.String("http://config-support-app.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-support-app.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-support-app.dev", + clientEndpoint: aws.String("https://client-support-app.dev"), + expectURL: aws.String("https://client-support-app.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SUPPORT_APP", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/supportapp/generated.json b/service/supportapp/generated.json index 8ffee53f60e..f04aa874904 100644 --- a/service/supportapp/generated.json +++ b/service/supportapp/generated.json @@ -22,6 +22,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/supportapp/go.mod b/service/supportapp/go.mod index 5b8e868ae3e..98a3be491f5 100644 --- a/service/supportapp/go.mod +++ b/service/supportapp/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/supportapp/go.sum b/service/supportapp/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/supportapp/go.sum +++ b/service/supportapp/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/swf/api_client.go b/service/swf/api_client.go index 604b643a4db..4514a48fe9d 100644 --- a/service/swf/api_client.go +++ b/service/swf/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/swf/endpoints.go b/service/swf/endpoints.go index 94080a589b2..54555f9a684 100644 --- a/service/swf/endpoints.go +++ b/service/swf/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/swf/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SWF") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "SWF", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/swf/endpoints_config_test.go b/service/swf/endpoints_config_test.go new file mode 100644 index 00000000000..86d0ba3001c --- /dev/null +++ b/service/swf/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package swf + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-swf.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-swf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + expectURL: aws.String("https://env-swf.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-swf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + expectURL: aws.String("http://config-swf.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-swf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-swf.dev", + clientEndpoint: aws.String("https://client-swf.dev"), + expectURL: aws.String("https://client-swf.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SWF", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/swf/generated.json b/service/swf/generated.json index db690a16c93..fd4e76d2e33 100644 --- a/service/swf/generated.json +++ b/service/swf/generated.json @@ -49,6 +49,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/swf/go.mod b/service/swf/go.mod index fb0fb9b512d..ab7701bad8b 100644 --- a/service/swf/go.mod +++ b/service/swf/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/swf/go.sum b/service/swf/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/swf/go.sum +++ b/service/swf/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/synthetics/api_client.go b/service/synthetics/api_client.go index a3fb1a2780c..42e0a6c493d 100644 --- a/service/synthetics/api_client.go +++ b/service/synthetics/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/synthetics/endpoints.go b/service/synthetics/endpoints.go index 4ba27280828..e23c91b4b36 100644 --- a/service/synthetics/endpoints.go +++ b/service/synthetics/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/synthetics/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_SYNTHETICS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "synthetics", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/synthetics/endpoints_config_test.go b/service/synthetics/endpoints_config_test.go new file mode 100644 index 00000000000..1723210b221 --- /dev/null +++ b/service/synthetics/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package synthetics + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-synthetics.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-synthetics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + expectURL: aws.String("https://env-synthetics.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-synthetics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + expectURL: aws.String("http://config-synthetics.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-synthetics.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-synthetics.dev", + clientEndpoint: aws.String("https://client-synthetics.dev"), + expectURL: aws.String("https://client-synthetics.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_SYNTHETICS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/synthetics/generated.json b/service/synthetics/generated.json index 51fae2be0af..5d17f202761 100644 --- a/service/synthetics/generated.json +++ b/service/synthetics/generated.json @@ -33,6 +33,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/synthetics/go.mod b/service/synthetics/go.mod index d20005edf8d..937f97dec86 100644 --- a/service/synthetics/go.mod +++ b/service/synthetics/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/synthetics/go.sum b/service/synthetics/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/synthetics/go.sum +++ b/service/synthetics/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/textract/api_client.go b/service/textract/api_client.go index 89551e7f16a..02afcc4c5ec 100644 --- a/service/textract/api_client.go +++ b/service/textract/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/textract/endpoints.go b/service/textract/endpoints.go index 9e1b4959eed..79a70b35bf8 100644 --- a/service/textract/endpoints.go +++ b/service/textract/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/textract/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TEXTRACT") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Textract", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/textract/endpoints_config_test.go b/service/textract/endpoints_config_test.go new file mode 100644 index 00000000000..43b267ff408 --- /dev/null +++ b/service/textract/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package textract + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-textract.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-textract.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + expectURL: aws.String("https://env-textract.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-textract.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + expectURL: aws.String("http://config-textract.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-textract.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-textract.dev", + clientEndpoint: aws.String("https://client-textract.dev"), + expectURL: aws.String("https://client-textract.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TEXTRACT", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/textract/generated.json b/service/textract/generated.json index 97d5bbfb50f..2b06637a7a2 100644 --- a/service/textract/generated.json +++ b/service/textract/generated.json @@ -37,6 +37,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/textract/go.mod b/service/textract/go.mod index 0b9244a231f..eb90b647cef 100644 --- a/service/textract/go.mod +++ b/service/textract/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/textract/go.sum b/service/textract/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/textract/go.sum +++ b/service/textract/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/timestreamquery/api_client.go b/service/timestreamquery/api_client.go index 230c892369f..32742b93ef5 100644 --- a/service/timestreamquery/api_client.go +++ b/service/timestreamquery/api_client.go @@ -318,6 +318,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/timestreamquery/endpoints.go b/service/timestreamquery/endpoints.go index ec204ec7f50..7e0ab3d566a 100644 --- a/service/timestreamquery/endpoints.go +++ b/service/timestreamquery/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/timestreamquery/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TIMESTREAM_QUERY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Timestream Query", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/timestreamquery/endpoints_config_test.go b/service/timestreamquery/endpoints_config_test.go new file mode 100644 index 00000000000..3b57be20470 --- /dev/null +++ b/service/timestreamquery/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package timestreamquery + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-query.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + expectURL: aws.String("https://env-timestream-query.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + expectURL: aws.String("http://config-timestream-query.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-query.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-query.dev", + clientEndpoint: aws.String("https://client-timestream-query.dev"), + expectURL: aws.String("https://client-timestream-query.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TIMESTREAM_QUERY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/timestreamquery/generated.json b/service/timestreamquery/generated.json index 1298a0135f5..67281237bd5 100644 --- a/service/timestreamquery/generated.json +++ b/service/timestreamquery/generated.json @@ -26,6 +26,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/timestreamquery/go.mod b/service/timestreamquery/go.mod index 45e30e0b8e3..dc0d7ed84a7 100644 --- a/service/timestreamquery/go.mod +++ b/service/timestreamquery/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 github.com/aws/smithy-go v1.15.0 @@ -13,8 +14,26 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/timestreamquery/go.sum b/service/timestreamquery/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/timestreamquery/go.sum +++ b/service/timestreamquery/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/timestreamwrite/api_client.go b/service/timestreamwrite/api_client.go index 45f56cd88a8..21f7c808908 100644 --- a/service/timestreamwrite/api_client.go +++ b/service/timestreamwrite/api_client.go @@ -318,6 +318,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveEnableEndpointDiscoveryFromConfigSources(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/timestreamwrite/endpoints.go b/service/timestreamwrite/endpoints.go index 0842e55ba03..78c57d3c41a 100644 --- a/service/timestreamwrite/endpoints.go +++ b/service/timestreamwrite/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/timestreamwrite/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TIMESTREAM_WRITE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Timestream Write", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/timestreamwrite/endpoints_config_test.go b/service/timestreamwrite/endpoints_config_test.go new file mode 100644 index 00000000000..86b6250e293 --- /dev/null +++ b/service/timestreamwrite/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package timestreamwrite + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-write.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-write.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + expectURL: aws.String("https://env-timestream-write.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-write.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + expectURL: aws.String("http://config-timestream-write.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-timestream-write.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-timestream-write.dev", + clientEndpoint: aws.String("https://client-timestream-write.dev"), + expectURL: aws.String("https://client-timestream-write.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TIMESTREAM_WRITE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/timestreamwrite/generated.json b/service/timestreamwrite/generated.json index 25ad4fedde1..41b0a8e67d8 100644 --- a/service/timestreamwrite/generated.json +++ b/service/timestreamwrite/generated.json @@ -32,6 +32,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/timestreamwrite/go.mod b/service/timestreamwrite/go.mod index b8903b9b7f7..ec734381de1 100644 --- a/service/timestreamwrite/go.mod +++ b/service/timestreamwrite/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 github.com/aws/smithy-go v1.15.0 @@ -13,8 +14,26 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../service/internal/endpoint-discovery/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/timestreamwrite/go.sum b/service/timestreamwrite/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/timestreamwrite/go.sum +++ b/service/timestreamwrite/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/tnb/api_client.go b/service/tnb/api_client.go index a3ab93e6441..9ec7bb9a10a 100644 --- a/service/tnb/api_client.go +++ b/service/tnb/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/tnb/endpoints.go b/service/tnb/endpoints.go index a1093534b5c..54f2a6579b1 100644 --- a/service/tnb/endpoints.go +++ b/service/tnb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/tnb/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TNB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "tnb", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/tnb/endpoints_config_test.go b/service/tnb/endpoints_config_test.go new file mode 100644 index 00000000000..37f793b73bf --- /dev/null +++ b/service/tnb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package tnb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-tnb.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-tnb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + expectURL: aws.String("https://env-tnb.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-tnb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + expectURL: aws.String("http://config-tnb.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-tnb.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-tnb.dev", + clientEndpoint: aws.String("https://client-tnb.dev"), + expectURL: aws.String("https://client-tnb.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TNB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/tnb/generated.json b/service/tnb/generated.json index fa484bdeee1..25c8f2e0bee 100644 --- a/service/tnb/generated.json +++ b/service/tnb/generated.json @@ -47,6 +47,7 @@ "document/doc.go", "document/document.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/document/document.go", diff --git a/service/tnb/go.mod b/service/tnb/go.mod index dd7d7bdca3f..6f1d811d22a 100644 --- a/service/tnb/go.mod +++ b/service/tnb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/tnb/go.sum b/service/tnb/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/tnb/go.sum +++ b/service/tnb/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/transcribe/api_client.go b/service/transcribe/api_client.go index f077a91ce77..0b3476c030d 100644 --- a/service/transcribe/api_client.go +++ b/service/transcribe/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/transcribe/endpoints.go b/service/transcribe/endpoints.go index 068c6654005..15e59a69892 100644 --- a/service/transcribe/endpoints.go +++ b/service/transcribe/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/transcribe/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TRANSCRIBE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Transcribe", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/transcribe/endpoints_config_test.go b/service/transcribe/endpoints_config_test.go new file mode 100644 index 00000000000..0c52a1318aa --- /dev/null +++ b/service/transcribe/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package transcribe + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + expectURL: aws.String("https://env-transcribe.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + expectURL: aws.String("http://config-transcribe.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe.dev", + clientEndpoint: aws.String("https://client-transcribe.dev"), + expectURL: aws.String("https://client-transcribe.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TRANSCRIBE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/transcribe/generated.json b/service/transcribe/generated.json index c14dde993e5..c2c57f7d224 100644 --- a/service/transcribe/generated.json +++ b/service/transcribe/generated.json @@ -51,6 +51,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/transcribe/go.mod b/service/transcribe/go.mod index 5a7a661d0da..1dc586e3f2a 100644 --- a/service/transcribe/go.mod +++ b/service/transcribe/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/transcribe/go.sum b/service/transcribe/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/transcribe/go.sum +++ b/service/transcribe/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/transcribestreaming/api_client.go b/service/transcribestreaming/api_client.go index 8cc6ee3f673..8e06055ebbf 100644 --- a/service/transcribestreaming/api_client.go +++ b/service/transcribestreaming/api_client.go @@ -298,6 +298,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/transcribestreaming/endpoints.go b/service/transcribestreaming/endpoints.go index 883a3db3b43..718a432b022 100644 --- a/service/transcribestreaming/endpoints.go +++ b/service/transcribestreaming/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/transcribestreaming/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TRANSCRIBE_STREAMING") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Transcribe Streaming", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/transcribestreaming/endpoints_config_test.go b/service/transcribestreaming/endpoints_config_test.go new file mode 100644 index 00000000000..d6b94171076 --- /dev/null +++ b/service/transcribestreaming/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package transcribestreaming + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe-streaming.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe-streaming.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + expectURL: aws.String("https://env-transcribe-streaming.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe-streaming.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + expectURL: aws.String("http://config-transcribe-streaming.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-transcribe-streaming.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transcribe-streaming.dev", + clientEndpoint: aws.String("https://client-transcribe-streaming.dev"), + expectURL: aws.String("https://client-transcribe-streaming.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TRANSCRIBE_STREAMING", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/transcribestreaming/generated.json b/service/transcribestreaming/generated.json index 68be5ceee46..3a16225a4f1 100644 --- a/service/transcribestreaming/generated.json +++ b/service/transcribestreaming/generated.json @@ -16,6 +16,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "eventstream.go", "generated.json", diff --git a/service/transcribestreaming/go.mod b/service/transcribestreaming/go.mod index f80ca343fc8..4e8e95e603a 100644 --- a/service/transcribestreaming/go.mod +++ b/service/transcribestreaming/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -15,6 +16,24 @@ replace github.com/aws/aws-sdk-go-v2 => ../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/transcribestreaming/go.sum b/service/transcribestreaming/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/transcribestreaming/go.sum +++ b/service/transcribestreaming/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/transcribestreaming/internal/testing/go.mod b/service/transcribestreaming/internal/testing/go.mod index 9d3deba7771..0e188bb0f08 100644 --- a/service/transcribestreaming/internal/testing/go.mod +++ b/service/transcribestreaming/internal/testing/go.mod @@ -15,14 +15,20 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../../ replace github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream => ../../../../aws/protocol/eventstream/ +replace github.com/aws/aws-sdk-go-v2/config => ../../../../config/ + replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../../../internal/endpoints/v2/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/eventstreamtesting => ../../../../service/internal/eventstreamtesting/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ diff --git a/service/transcribestreaming/internal/testing/go.sum b/service/transcribestreaming/internal/testing/go.sum index 0b535230803..0177daeb353 100644 --- a/service/transcribestreaming/internal/testing/go.sum +++ b/service/transcribestreaming/internal/testing/go.sum @@ -1,3 +1,9 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/transfer/api_client.go b/service/transfer/api_client.go index e4487e6fe68..8c44e95e42b 100644 --- a/service/transfer/api_client.go +++ b/service/transfer/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/transfer/endpoints.go b/service/transfer/endpoints.go index d4803f67dc0..f7b7e38d946 100644 --- a/service/transfer/endpoints.go +++ b/service/transfer/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/transfer/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TRANSFER") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Transfer", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/transfer/endpoints_config_test.go b/service/transfer/endpoints_config_test.go new file mode 100644 index 00000000000..15a09cf6638 --- /dev/null +++ b/service/transfer/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package transfer + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transfer.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-transfer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + expectURL: aws.String("https://env-transfer.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-transfer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + expectURL: aws.String("http://config-transfer.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-transfer.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-transfer.dev", + clientEndpoint: aws.String("https://client-transfer.dev"), + expectURL: aws.String("https://client-transfer.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TRANSFER", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/transfer/generated.json b/service/transfer/generated.json index 2d6340bef86..a636c29f2f3 100644 --- a/service/transfer/generated.json +++ b/service/transfer/generated.json @@ -72,6 +72,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/transfer/go.mod b/service/transfer/go.mod index 9e74181cb24..f2fc134618a 100644 --- a/service/transfer/go.mod +++ b/service/transfer/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -13,6 +14,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/transfer/go.sum b/service/transfer/go.sum index ef5982af332..bb80e8891d8 100644 --- a/service/transfer/go.sum +++ b/service/transfer/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/service/translate/api_client.go b/service/translate/api_client.go index 49132adc2e3..1b7276b72f2 100644 --- a/service/translate/api_client.go +++ b/service/translate/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/translate/endpoints.go b/service/translate/endpoints.go index bfe84de294c..7daefdc646f 100644 --- a/service/translate/endpoints.go +++ b/service/translate/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/translate/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_TRANSLATE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Translate", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/translate/endpoints_config_test.go b/service/translate/endpoints_config_test.go new file mode 100644 index 00000000000..2ce53eeae6b --- /dev/null +++ b/service/translate/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package translate + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-translate.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-translate.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + expectURL: aws.String("https://env-translate.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-translate.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + expectURL: aws.String("http://config-translate.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-translate.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-translate.dev", + clientEndpoint: aws.String("https://client-translate.dev"), + expectURL: aws.String("https://client-translate.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_TRANSLATE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/translate/generated.json b/service/translate/generated.json index 2a35ede6e5a..c1f0efece44 100644 --- a/service/translate/generated.json +++ b/service/translate/generated.json @@ -31,6 +31,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/translate/go.mod b/service/translate/go.mod index f5546a1927f..664b8a94fd0 100644 --- a/service/translate/go.mod +++ b/service/translate/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/translate/go.sum b/service/translate/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/translate/go.sum +++ b/service/translate/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/verifiedpermissions/api_client.go b/service/verifiedpermissions/api_client.go index b83a5e76e46..2a04618cc05 100644 --- a/service/verifiedpermissions/api_client.go +++ b/service/verifiedpermissions/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/verifiedpermissions/endpoints.go b/service/verifiedpermissions/endpoints.go index dea72b15f74..733fe11d9a5 100644 --- a/service/verifiedpermissions/endpoints.go +++ b/service/verifiedpermissions/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/verifiedpermissions/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_VERIFIEDPERMISSIONS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "VerifiedPermissions", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/verifiedpermissions/endpoints_config_test.go b/service/verifiedpermissions/endpoints_config_test.go new file mode 100644 index 00000000000..05c387d9648 --- /dev/null +++ b/service/verifiedpermissions/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package verifiedpermissions + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-verifiedpermissions.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-verifiedpermissions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + expectURL: aws.String("https://env-verifiedpermissions.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-verifiedpermissions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + expectURL: aws.String("http://config-verifiedpermissions.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-verifiedpermissions.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-verifiedpermissions.dev", + clientEndpoint: aws.String("https://client-verifiedpermissions.dev"), + expectURL: aws.String("https://client-verifiedpermissions.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_VERIFIEDPERMISSIONS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/verifiedpermissions/generated.json b/service/verifiedpermissions/generated.json index 634757971dc..4196a9b3d62 100644 --- a/service/verifiedpermissions/generated.json +++ b/service/verifiedpermissions/generated.json @@ -36,6 +36,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/verifiedpermissions/go.mod b/service/verifiedpermissions/go.mod index 99d59cbddbf..b52b12ec1bf 100644 --- a/service/verifiedpermissions/go.mod +++ b/service/verifiedpermissions/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/verifiedpermissions/go.sum b/service/verifiedpermissions/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/verifiedpermissions/go.sum +++ b/service/verifiedpermissions/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/voiceid/api_client.go b/service/voiceid/api_client.go index f8322559d07..d324d44b766 100644 --- a/service/voiceid/api_client.go +++ b/service/voiceid/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/voiceid/endpoints.go b/service/voiceid/endpoints.go index f7d1a81a6cb..7d7742d3760 100644 --- a/service/voiceid/endpoints.go +++ b/service/voiceid/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/voiceid/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_VOICE_ID") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Voice ID", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/voiceid/endpoints_config_test.go b/service/voiceid/endpoints_config_test.go new file mode 100644 index 00000000000..e78cb0fc37c --- /dev/null +++ b/service/voiceid/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package voiceid + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-voice-id.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-voice-id.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + expectURL: aws.String("https://env-voice-id.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-voice-id.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + expectURL: aws.String("http://config-voice-id.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-voice-id.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-voice-id.dev", + clientEndpoint: aws.String("https://client-voice-id.dev"), + expectURL: aws.String("https://client-voice-id.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_VOICE_ID", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/voiceid/generated.json b/service/voiceid/generated.json index 9184c385e01..b1b217eade1 100644 --- a/service/voiceid/generated.json +++ b/service/voiceid/generated.json @@ -41,6 +41,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/voiceid/go.mod b/service/voiceid/go.mod index d152c0ed982..8a655938311 100644 --- a/service/voiceid/go.mod +++ b/service/voiceid/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/voiceid/go.sum b/service/voiceid/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/voiceid/go.sum +++ b/service/voiceid/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/vpclattice/api_client.go b/service/vpclattice/api_client.go index f0714a89766..6e3d4f5d2be 100644 --- a/service/vpclattice/api_client.go +++ b/service/vpclattice/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/vpclattice/endpoints.go b/service/vpclattice/endpoints.go index 4507e1612e8..ed6f801a525 100644 --- a/service/vpclattice/endpoints.go +++ b/service/vpclattice/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/vpclattice/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_VPC_LATTICE") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "VPC Lattice", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/vpclattice/endpoints_config_test.go b/service/vpclattice/endpoints_config_test.go new file mode 100644 index 00000000000..1506e7f5918 --- /dev/null +++ b/service/vpclattice/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package vpclattice + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-vpc-lattice.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-vpc-lattice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + expectURL: aws.String("https://env-vpc-lattice.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-vpc-lattice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + expectURL: aws.String("http://config-vpc-lattice.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-vpc-lattice.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-vpc-lattice.dev", + clientEndpoint: aws.String("https://client-vpc-lattice.dev"), + expectURL: aws.String("https://client-vpc-lattice.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_VPC_LATTICE", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/vpclattice/generated.json b/service/vpclattice/generated.json index 6d0e9f44e64..c8054e3230a 100644 --- a/service/vpclattice/generated.json +++ b/service/vpclattice/generated.json @@ -64,6 +64,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/vpclattice/go.mod b/service/vpclattice/go.mod index 1a856579c53..3208724d21e 100644 --- a/service/vpclattice/go.mod +++ b/service/vpclattice/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/vpclattice/go.sum b/service/vpclattice/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/vpclattice/go.sum +++ b/service/vpclattice/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/waf/api_client.go b/service/waf/api_client.go index be0aba5e643..1093cc1f85c 100644 --- a/service/waf/api_client.go +++ b/service/waf/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/waf/endpoints.go b/service/waf/endpoints.go index 96f89aa0383..f6c5bec3890 100644 --- a/service/waf/endpoints.go +++ b/service/waf/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/waf/internal/endpoints" smithy "github.com/aws/smithy-go" smithyendpoints "github.com/aws/smithy-go/endpoints" @@ -17,6 +18,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -195,6 +197,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WAF") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WAF", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/waf/endpoints_config_test.go b/service/waf/endpoints_config_test.go new file mode 100644 index 00000000000..328a7a761f1 --- /dev/null +++ b/service/waf/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package waf + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + expectURL: aws.String("https://env-waf.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + expectURL: aws.String("http://config-waf.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf.dev", + clientEndpoint: aws.String("https://client-waf.dev"), + expectURL: aws.String("https://client-waf.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WAF", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/waf/generated.json b/service/waf/generated.json index b2a29374cca..05ba2114d21 100644 --- a/service/waf/generated.json +++ b/service/waf/generated.json @@ -89,6 +89,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/waf/go.mod b/service/waf/go.mod index cdb282b0073..a0cd85048d3 100644 --- a/service/waf/go.mod +++ b/service/waf/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/waf/go.sum b/service/waf/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/waf/go.sum +++ b/service/waf/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/wafregional/api_client.go b/service/wafregional/api_client.go index 706fc4e47d9..9a1d66b9b86 100644 --- a/service/wafregional/api_client.go +++ b/service/wafregional/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/wafregional/endpoints.go b/service/wafregional/endpoints.go index 044fc7b4053..a6b644c3d56 100644 --- a/service/wafregional/endpoints.go +++ b/service/wafregional/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/wafregional/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WAF_REGIONAL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WAF Regional", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/wafregional/endpoints_config_test.go b/service/wafregional/endpoints_config_test.go new file mode 100644 index 00000000000..c05ef70d3db --- /dev/null +++ b/service/wafregional/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package wafregional + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf-regional.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf-regional.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + expectURL: aws.String("https://env-waf-regional.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf-regional.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + expectURL: aws.String("http://config-waf-regional.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-waf-regional.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-waf-regional.dev", + clientEndpoint: aws.String("https://client-waf-regional.dev"), + expectURL: aws.String("https://client-waf-regional.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WAF_REGIONAL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/wafregional/generated.json b/service/wafregional/generated.json index 1c91db79c9a..d6a359603da 100644 --- a/service/wafregional/generated.json +++ b/service/wafregional/generated.json @@ -93,6 +93,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/wafregional/go.mod b/service/wafregional/go.mod index 90b3ba5ee50..b9c54e6be77 100644 --- a/service/wafregional/go.mod +++ b/service/wafregional/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/wafregional/go.sum b/service/wafregional/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/wafregional/go.sum +++ b/service/wafregional/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/wafv2/api_client.go b/service/wafv2/api_client.go index c4246af5d50..2de990ce60c 100644 --- a/service/wafv2/api_client.go +++ b/service/wafv2/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/wafv2/endpoints.go b/service/wafv2/endpoints.go index 93eb119e577..081272bbea0 100644 --- a/service/wafv2/endpoints.go +++ b/service/wafv2/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/wafv2/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WAFV2") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WAFV2", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/wafv2/endpoints_config_test.go b/service/wafv2/endpoints_config_test.go new file mode 100644 index 00000000000..77ce8c671a8 --- /dev/null +++ b/service/wafv2/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package wafv2 + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wafv2.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-wafv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + expectURL: aws.String("https://env-wafv2.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wafv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + expectURL: aws.String("http://config-wafv2.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-wafv2.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wafv2.dev", + clientEndpoint: aws.String("https://client-wafv2.dev"), + expectURL: aws.String("https://client-wafv2.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WAFV2", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/wafv2/generated.json b/service/wafv2/generated.json index 92a024491d6..6ecdf8ebba5 100644 --- a/service/wafv2/generated.json +++ b/service/wafv2/generated.json @@ -65,6 +65,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/wafv2/go.mod b/service/wafv2/go.mod index a38c1dc59af..07267be0ab2 100644 --- a/service/wafv2/go.mod +++ b/service/wafv2/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/wafv2/go.sum b/service/wafv2/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/wafv2/go.sum +++ b/service/wafv2/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/wellarchitected/api_client.go b/service/wellarchitected/api_client.go index 4626ddc1164..343c12628da 100644 --- a/service/wellarchitected/api_client.go +++ b/service/wellarchitected/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/wellarchitected/endpoints.go b/service/wellarchitected/endpoints.go index 244b28c1c76..6cbebfcc085 100644 --- a/service/wellarchitected/endpoints.go +++ b/service/wellarchitected/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/wellarchitected/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WELLARCHITECTED") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WellArchitected", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/wellarchitected/endpoints_config_test.go b/service/wellarchitected/endpoints_config_test.go new file mode 100644 index 00000000000..8297ee18d5d --- /dev/null +++ b/service/wellarchitected/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package wellarchitected + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wellarchitected.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-wellarchitected.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + expectURL: aws.String("https://env-wellarchitected.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wellarchitected.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + expectURL: aws.String("http://config-wellarchitected.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-wellarchitected.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wellarchitected.dev", + clientEndpoint: aws.String("https://client-wellarchitected.dev"), + expectURL: aws.String("https://client-wellarchitected.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WELLARCHITECTED", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/wellarchitected/generated.json b/service/wellarchitected/generated.json index 4ef0ab2cd03..8948a46c6ac 100644 --- a/service/wellarchitected/generated.json +++ b/service/wellarchitected/generated.json @@ -82,6 +82,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/wellarchitected/go.mod b/service/wellarchitected/go.mod index 3a575dd9f5e..94bf22f2d64 100644 --- a/service/wellarchitected/go.mod +++ b/service/wellarchitected/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/wellarchitected/go.sum b/service/wellarchitected/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/wellarchitected/go.sum +++ b/service/wellarchitected/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/wisdom/api_client.go b/service/wisdom/api_client.go index b76fb3fb8a5..23cd7bc8947 100644 --- a/service/wisdom/api_client.go +++ b/service/wisdom/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/wisdom/endpoints.go b/service/wisdom/endpoints.go index 8a128b7026b..ebc409422fe 100644 --- a/service/wisdom/endpoints.go +++ b/service/wisdom/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/wisdom/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WISDOM") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "Wisdom", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/wisdom/endpoints_config_test.go b/service/wisdom/endpoints_config_test.go new file mode 100644 index 00000000000..756e56ae03f --- /dev/null +++ b/service/wisdom/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package wisdom + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wisdom.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-wisdom.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + expectURL: aws.String("https://env-wisdom.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-wisdom.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + expectURL: aws.String("http://config-wisdom.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-wisdom.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-wisdom.dev", + clientEndpoint: aws.String("https://client-wisdom.dev"), + expectURL: aws.String("https://client-wisdom.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WISDOM", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/wisdom/generated.json b/service/wisdom/generated.json index 98d1da616cd..ad1519e4055 100644 --- a/service/wisdom/generated.json +++ b/service/wisdom/generated.json @@ -43,6 +43,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/wisdom/go.mod b/service/wisdom/go.mod index 302c52f8986..a777ae2ba13 100644 --- a/service/wisdom/go.mod +++ b/service/wisdom/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/wisdom/go.sum b/service/wisdom/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/wisdom/go.sum +++ b/service/wisdom/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/workdocs/api_client.go b/service/workdocs/api_client.go index e6928391951..48fb3b36bf4 100644 --- a/service/workdocs/api_client.go +++ b/service/workdocs/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/workdocs/endpoints.go b/service/workdocs/endpoints.go index 099a4190e19..80f00ef1026 100644 --- a/service/workdocs/endpoints.go +++ b/service/workdocs/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/workdocs/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKDOCS") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkDocs", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/workdocs/endpoints_config_test.go b/service/workdocs/endpoints_config_test.go new file mode 100644 index 00000000000..25ea587e408 --- /dev/null +++ b/service/workdocs/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package workdocs + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workdocs.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-workdocs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + expectURL: aws.String("https://env-workdocs.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workdocs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + expectURL: aws.String("http://config-workdocs.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-workdocs.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workdocs.dev", + clientEndpoint: aws.String("https://client-workdocs.dev"), + expectURL: aws.String("https://client-workdocs.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKDOCS", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/workdocs/generated.json b/service/workdocs/generated.json index 970dd547d45..bc7bed436e9 100644 --- a/service/workdocs/generated.json +++ b/service/workdocs/generated.json @@ -56,6 +56,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/workdocs/go.mod b/service/workdocs/go.mod index 2dbd00f3bca..8fb1a76e9ae 100644 --- a/service/workdocs/go.mod +++ b/service/workdocs/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/workdocs/go.sum b/service/workdocs/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/workdocs/go.sum +++ b/service/workdocs/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/worklink/api_client.go b/service/worklink/api_client.go index afde0e970a4..4e187442888 100644 --- a/service/worklink/api_client.go +++ b/service/worklink/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/worklink/endpoints.go b/service/worklink/endpoints.go index 9c388fc3b0f..0cb4294e9fc 100644 --- a/service/worklink/endpoints.go +++ b/service/worklink/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/worklink/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKLINK") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkLink", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/worklink/endpoints_config_test.go b/service/worklink/endpoints_config_test.go new file mode 100644 index 00000000000..b5654ca27e7 --- /dev/null +++ b/service/worklink/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package worklink + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-worklink.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-worklink.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + expectURL: aws.String("https://env-worklink.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-worklink.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + expectURL: aws.String("http://config-worklink.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-worklink.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-worklink.dev", + clientEndpoint: aws.String("https://client-worklink.dev"), + expectURL: aws.String("https://client-worklink.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKLINK", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/worklink/generated.json b/service/worklink/generated.json index 9c3939ab614..2ffec766065 100644 --- a/service/worklink/generated.json +++ b/service/worklink/generated.json @@ -45,6 +45,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/worklink/go.mod b/service/worklink/go.mod index e48f6ac91e0..6375e172f15 100644 --- a/service/worklink/go.mod +++ b/service/worklink/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/worklink/go.sum b/service/worklink/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/worklink/go.sum +++ b/service/worklink/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/workmail/api_client.go b/service/workmail/api_client.go index bdf22f08824..f1fc93c544b 100644 --- a/service/workmail/api_client.go +++ b/service/workmail/api_client.go @@ -303,6 +303,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/workmail/endpoints.go b/service/workmail/endpoints.go index 939101d376d..b6ea1df7c3c 100644 --- a/service/workmail/endpoints.go +++ b/service/workmail/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/workmail/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKMAIL") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkMail", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/workmail/endpoints_config_test.go b/service/workmail/endpoints_config_test.go new file mode 100644 index 00000000000..24a9053e947 --- /dev/null +++ b/service/workmail/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package workmail + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmail.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + expectURL: aws.String("https://env-workmail.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + expectURL: aws.String("http://config-workmail.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmail.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmail.dev", + clientEndpoint: aws.String("https://client-workmail.dev"), + expectURL: aws.String("https://client-workmail.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKMAIL", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/workmail/generated.json b/service/workmail/generated.json index 0a9196a3971..43106ff27f2 100644 --- a/service/workmail/generated.json +++ b/service/workmail/generated.json @@ -96,6 +96,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/workmail/go.mod b/service/workmail/go.mod index 42193de77db..9741acdc58b 100644 --- a/service/workmail/go.mod +++ b/service/workmail/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/workmail/go.sum b/service/workmail/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/workmail/go.sum +++ b/service/workmail/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/workmailmessageflow/api_client.go b/service/workmailmessageflow/api_client.go index 9b18bbfc4a9..3ab226eaa33 100644 --- a/service/workmailmessageflow/api_client.go +++ b/service/workmailmessageflow/api_client.go @@ -296,6 +296,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/workmailmessageflow/endpoints.go b/service/workmailmessageflow/endpoints.go index b53ddee9be6..d4406793650 100644 --- a/service/workmailmessageflow/endpoints.go +++ b/service/workmailmessageflow/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/workmailmessageflow/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKMAILMESSAGEFLOW") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkMailMessageFlow", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/workmailmessageflow/endpoints_config_test.go b/service/workmailmessageflow/endpoints_config_test.go new file mode 100644 index 00000000000..0e13a86b16b --- /dev/null +++ b/service/workmailmessageflow/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package workmailmessageflow + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmailmessageflow.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmailmessageflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + expectURL: aws.String("https://env-workmailmessageflow.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmailmessageflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + expectURL: aws.String("http://config-workmailmessageflow.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-workmailmessageflow.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workmailmessageflow.dev", + clientEndpoint: aws.String("https://client-workmailmessageflow.dev"), + expectURL: aws.String("https://client-workmailmessageflow.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKMAILMESSAGEFLOW", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/workmailmessageflow/generated.json b/service/workmailmessageflow/generated.json index 6fce6d9067b..4e4b67a8f83 100644 --- a/service/workmailmessageflow/generated.json +++ b/service/workmailmessageflow/generated.json @@ -14,6 +14,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/workmailmessageflow/go.mod b/service/workmailmessageflow/go.mod index 7e0d2270f52..c8ab24dfa4f 100644 --- a/service/workmailmessageflow/go.mod +++ b/service/workmailmessageflow/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/workmailmessageflow/go.sum b/service/workmailmessageflow/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/workmailmessageflow/go.sum +++ b/service/workmailmessageflow/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/workspaces/api_client.go b/service/workspaces/api_client.go index f52e834e0e7..a3ee3e96720 100644 --- a/service/workspaces/api_client.go +++ b/service/workspaces/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/workspaces/endpoints.go b/service/workspaces/endpoints.go index 9e28e0d4b14..328f1cc6b0b 100644 --- a/service/workspaces/endpoints.go +++ b/service/workspaces/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/workspaces/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKSPACES") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkSpaces", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/workspaces/endpoints_config_test.go b/service/workspaces/endpoints_config_test.go new file mode 100644 index 00000000000..51292ff8f43 --- /dev/null +++ b/service/workspaces/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package workspaces + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + expectURL: aws.String("https://env-workspaces.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + expectURL: aws.String("http://config-workspaces.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces.dev", + clientEndpoint: aws.String("https://client-workspaces.dev"), + expectURL: aws.String("https://client-workspaces.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKSPACES", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/workspaces/generated.json b/service/workspaces/generated.json index 2077177c7da..f092e9453bf 100644 --- a/service/workspaces/generated.json +++ b/service/workspaces/generated.json @@ -85,6 +85,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/workspaces/go.mod b/service/workspaces/go.mod index 87717c9b60e..cca9d7d3fd6 100644 --- a/service/workspaces/go.mod +++ b/service/workspaces/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/workspaces/go.sum b/service/workspaces/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/workspaces/go.sum +++ b/service/workspaces/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/workspacesweb/api_client.go b/service/workspacesweb/api_client.go index a7baf0aa571..41f5ae3cb03 100644 --- a/service/workspacesweb/api_client.go +++ b/service/workspacesweb/api_client.go @@ -304,6 +304,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/workspacesweb/endpoints.go b/service/workspacesweb/endpoints.go index 87207f23e74..dd13dbf6812 100644 --- a/service/workspacesweb/endpoints.go +++ b/service/workspacesweb/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/workspacesweb/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_WORKSPACES_WEB") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "WorkSpaces Web", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/workspacesweb/endpoints_config_test.go b/service/workspacesweb/endpoints_config_test.go new file mode 100644 index 00000000000..f290492b6a7 --- /dev/null +++ b/service/workspacesweb/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package workspacesweb + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces-web.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces-web.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + expectURL: aws.String("https://env-workspaces-web.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces-web.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + expectURL: aws.String("http://config-workspaces-web.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-workspaces-web.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-workspaces-web.dev", + clientEndpoint: aws.String("https://client-workspaces-web.dev"), + expectURL: aws.String("https://client-workspaces-web.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_WORKSPACES_WEB", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/workspacesweb/generated.json b/service/workspacesweb/generated.json index effb9eff9bf..9e1a9f1edc1 100644 --- a/service/workspacesweb/generated.json +++ b/service/workspacesweb/generated.json @@ -70,6 +70,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/workspacesweb/go.mod b/service/workspacesweb/go.mod index c3f32cb5427..638c509e065 100644 --- a/service/workspacesweb/go.mod +++ b/service/workspacesweb/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/workspacesweb/go.sum b/service/workspacesweb/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/workspacesweb/go.sum +++ b/service/workspacesweb/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/service/xray/api_client.go b/service/xray/api_client.go index e961d7ddcf7..4c3017ab8ab 100644 --- a/service/xray/api_client.go +++ b/service/xray/api_client.go @@ -295,6 +295,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { resolveAWSEndpointResolver(cfg, &opts) resolveUseDualStackEndpoint(cfg, &opts) resolveUseFIPSEndpoint(cfg, &opts) + resolveBaseEndpoint(cfg, &opts) return New(opts, optFns...) } diff --git a/service/xray/endpoints.go b/service/xray/endpoints.go index 7145fa79250..aedbceec45e 100644 --- a/service/xray/endpoints.go +++ b/service/xray/endpoints.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn" + internalepconfig "github.com/aws/aws-sdk-go-v2/internal/endpoints/config" internalendpoints "github.com/aws/aws-sdk-go-v2/service/xray/internal/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/aws/smithy-go/middleware" @@ -16,6 +17,7 @@ import ( smithyhttp "github.com/aws/smithy-go/transport/http" "net/http" "net/url" + "os" "strings" ) @@ -194,6 +196,24 @@ func resolveEndpointResolverV2(options *Options) { } } +func resolveBaseEndpoint(cfg aws.Config, o *Options) { + if cfg.BaseEndpoint != nil { + o.BaseEndpoint = cfg.BaseEndpoint + } + + _, g := os.LookupEnv("AWS_ENDPOINT_URL") + _, s := os.LookupEnv("AWS_ENDPOINT_URL_XRAY") + + if g && !s { + return + } + + value, found, err := internalepconfig.ResolveServiceBaseEndpoint(context.Background(), "XRay", cfg.ConfigSources) + if found && err == nil { + o.BaseEndpoint = &value + } +} + // Utility function to aid with translating pseudo-regions to classical regions // with the appropriate setting indicated by the pseudo-region func mapPseudoRegion(pr string) (region string, fips aws.FIPSEndpointState) { diff --git a/service/xray/endpoints_config_test.go b/service/xray/endpoints_config_test.go new file mode 100644 index 00000000000..2eb6a70c197 --- /dev/null +++ b/service/xray/endpoints_config_test.go @@ -0,0 +1,139 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package xray + +import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "os" + "reflect" + "testing" +) + +type mockConfigSource struct { + global string + service string + ignore bool +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +func (m mockConfigSource) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) { + return m.ignore, m.ignore, nil +} + +// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use +// with configured endpoints. +func (m mockConfigSource) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) { + if m.service != "" { + return m.service, true, nil + } + return "", false, nil +} + +func TestResolveBaseEndpoint(t *testing.T) { + cases := map[string]struct { + envGlobal string + envService string + envIgnore bool + configGlobal string + configService string + configIgnore bool + clientEndpoint *string + expectURL *string + }{ + "env ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-xray.dev", + envIgnore: true, + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + expectURL: nil, + }, + "env global": { + envGlobal: "https://env-global.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + expectURL: aws.String("https://env-global.dev"), + }, + "env service": { + envGlobal: "https://env-global.dev", + envService: "https://env-xray.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + expectURL: aws.String("https://env-xray.dev"), + }, + "config ignore": { + envGlobal: "https://env-global.dev", + envService: "https://env-xray.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + configIgnore: true, + expectURL: nil, + }, + "config global": { + configGlobal: "http://config-global.dev", + expectURL: aws.String("http://config-global.dev"), + }, + "config service": { + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + expectURL: aws.String("http://config-xray.dev"), + }, + "client": { + envGlobal: "https://env-global.dev", + envService: "https://env-xray.dev", + configGlobal: "http://config-global.dev", + configService: "http://config-xray.dev", + clientEndpoint: aws.String("https://client-xray.dev"), + expectURL: aws.String("https://client-xray.dev"), + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + os.Clearenv() + + awsConfig := aws.Config{} + ignore := c.envIgnore || c.configIgnore + + if c.configGlobal != "" && !ignore { + awsConfig.BaseEndpoint = aws.String(c.configGlobal) + } + + if c.envGlobal != "" { + t.Setenv("AWS_ENDPOINT_URL", c.envGlobal) + if !ignore { + awsConfig.BaseEndpoint = aws.String(c.envGlobal) + } + } + + if c.envService != "" { + t.Setenv("AWS_ENDPOINT_URL_XRAY", c.envService) + } + + awsConfig.ConfigSources = []interface{}{ + mockConfigSource{ + global: c.envGlobal, + service: c.envService, + ignore: c.envIgnore, + }, + mockConfigSource{ + global: c.configGlobal, + service: c.configService, + ignore: c.configIgnore, + }, + } + + client := NewFromConfig(awsConfig, func(o *Options) { + if c.clientEndpoint != nil { + o.BaseEndpoint = c.clientEndpoint + } + }) + + if e, a := c.expectURL, client.options.BaseEndpoint; !reflect.DeepEqual(e, a) { + t.Errorf("expect endpoint %v , got %v", e, a) + } + }) + } +} diff --git a/service/xray/generated.json b/service/xray/generated.json index 80608289933..be2258d5f51 100644 --- a/service/xray/generated.json +++ b/service/xray/generated.json @@ -42,6 +42,7 @@ "deserializers.go", "doc.go", "endpoints.go", + "endpoints_config_test.go", "endpoints_test.go", "generated.json", "internal/endpoints/endpoints.go", diff --git a/service/xray/go.mod b/service/xray/go.mod index 648bc7d5123..03e229bdf95 100644 --- a/service/xray/go.mod +++ b/service/xray/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/aws/aws-sdk-go-v2 v1.21.2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 + github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 github.com/aws/smithy-go v1.15.0 github.com/google/go-cmp v0.5.8 @@ -12,6 +13,24 @@ require ( replace github.com/aws/aws-sdk-go-v2 => ../../ +replace github.com/aws/aws-sdk-go-v2/config => ../../config/ + +replace github.com/aws/aws-sdk-go-v2/credentials => ../../credentials/ + +replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../feature/ec2/imds/ + replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/ +replace github.com/aws/aws-sdk-go-v2/internal/endpoints/config => ../../internal/endpoints/config/ + replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/ + +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../internal/ini/ + +replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../service/internal/presigned-url/ + +replace github.com/aws/aws-sdk-go-v2/service/sso => ../../service/sso/ + +replace github.com/aws/aws-sdk-go-v2/service/ssooidc => ../../service/ssooidc/ + +replace github.com/aws/aws-sdk-go-v2/service/sts => ../../service/sts/ diff --git a/service/xray/go.sum b/service/xray/go.sum index a646f1d3099..bdfbab63ce4 100644 --- a/service/xray/go.sum +++ b/service/xray/go.sum @@ -1,3 +1,21 @@ +github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs= +github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= +github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview h1:WWMjRroyXu4yENbC8vJIN5CIWAWjcNnUgKYwT/q5gBs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= +github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From f6b44c98736638d93e2ab45bc674e0a03b3609ad Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 10:26:42 -0700 Subject: [PATCH 24/26] remove config package from internal/endpoints/config --- internal/endpoints/config/config.go | 31 +++++++++++++++++++++++++++-- internal/endpoints/config/go.mod | 2 -- internal/endpoints/config/go.sum | 12 ----------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/internal/endpoints/config/config.go b/internal/endpoints/config/config.go index 012ac6c07ab..8bdf55159a7 100644 --- a/internal/endpoints/config/config.go +++ b/internal/endpoints/config/config.go @@ -2,7 +2,6 @@ package config import ( "context" - "github.com/aws/aws-sdk-go-v2/config" ) // ServiceBaseEndpointProvider is needed to search for all providers @@ -11,10 +10,38 @@ type ServiceBaseEndpointProvider interface { GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) } +// IgnoreConfiguredEndpointsProvider is needed to search for all providers +// that provide a flag to disable configured endpoints. +// +// Currently duplicated from github.com/aws/aws-sdk-go-v2/config because +// service packages cannot import github.com/aws/aws-sdk-go-v2/config +// due to result import cycle error. +type IgnoreConfiguredEndpointsProvider interface { + GetIgnoreConfiguredEndpoints(ctx context.Context) (bool, bool, error) +} + +// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured +// endpoints feature. +// +// Currently duplicated from github.com/aws/aws-sdk-go-v2/config because +// service packages cannot import github.com/aws/aws-sdk-go-v2/config +// due to result import cycle error. +func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []interface{}) (value bool, found bool, err error) { + for _, cfg := range configs { + if p, ok := cfg.(IgnoreConfiguredEndpointsProvider); ok { + value, found, err = p.GetIgnoreConfiguredEndpoints(ctx) + if err != nil || found { + break + } + } + } + return +} + // ResolveServiceBaseEndpoint is used to retrieve service endpoints from configured sources // while allowing for configured endpoints to be disabled func ResolveServiceBaseEndpoint(ctx context.Context, sdkID string, configs []interface{}) (value string, found bool, err error) { - if val, found, _ := config.GetIgnoreConfiguredEndpoints(ctx, configs); found && val { + if val, found, _ := GetIgnoreConfiguredEndpoints(ctx, configs); found && val { return "", false, nil } diff --git a/internal/endpoints/config/go.mod b/internal/endpoints/config/go.mod index 959ca512045..68fe6fd3b28 100644 --- a/internal/endpoints/config/go.mod +++ b/internal/endpoints/config/go.mod @@ -2,8 +2,6 @@ module github.com/aws/aws-sdk-go-v2/internal/endpoints/config go 1.15 -require github.com/aws/aws-sdk-go-v2/config v1.19.1 - replace github.com/aws/aws-sdk-go-v2 => ../../../ replace github.com/aws/aws-sdk-go-v2/config => ../../../config/ diff --git a/internal/endpoints/config/go.sum b/internal/endpoints/config/go.sum index 4ad6d15cf52..e69de29bb2d 100644 --- a/internal/endpoints/config/go.sum +++ b/internal/endpoints/config/go.sum @@ -1,12 +0,0 @@ -github.com/aws/aws-sdk-go-v2/internal/endpoints/config v1.0.0-preview/go.mod h1:4/h8taQkWpxZY0AOxZNxccsa9PxzUmZQEpoqL6TwuKA= -github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= -github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From c9fba926e11400db29d8fe9712926aef727a4e0f Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Sun, 29 Oct 2023 10:28:47 -0700 Subject: [PATCH 25/26] add changelog file --- .../06da4f604ded49eda17be9d3f9ef19d7.json | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+) create mode 100644 .changelog/06da4f604ded49eda17be9d3f9ef19d7.json diff --git a/.changelog/06da4f604ded49eda17be9d3f9ef19d7.json b/.changelog/06da4f604ded49eda17be9d3f9ef19d7.json new file mode 100644 index 00000000000..adaed7ab999 --- /dev/null +++ b/.changelog/06da4f604ded49eda17be9d3f9ef19d7.json @@ -0,0 +1,391 @@ +{ + "id": "06da4f60-4ded-49ed-a17b-e9d3f9ef19d7", + "type": "feature", + "collapse": true, + "description": "Adds support for configured endpoints via environment variables and the AWS shared configuration file.", + "modules": [ + "config", + "credentials", + "example/service/dynamodb/createTable", + "example/service/dynamodb/scanItems", + "example/service/s3/listObjects", + "example/service/s3/usingPrivateLink", + "feature/dynamodb/attributevalue", + "feature/dynamodb/expression", + "feature/dynamodbstreams/attributevalue", + "feature/ec2/imds/internal/configtesting", + "feature/s3/manager", + "internal/ini", + "internal/configsources/configtesting", + "internal/endpoints/config", + "internal/protocoltest/awsrestjson", + "internal/protocoltest/ec2query", + "internal/protocoltest/jsonrpc", + "internal/protocoltest/jsonrpc10", + "internal/protocoltest/query", + "internal/protocoltest/restxml", + "internal/protocoltest/restxmlwithnamespace", + "service/accessanalyzer", + "service/account", + "service/acm", + "service/acmpca", + "service/alexaforbusiness", + "service/amp", + "service/amplify", + "service/amplifybackend", + "service/amplifyuibuilder", + "service/apigateway", + "service/apigatewaymanagementapi", + "service/apigatewayv2", + "service/appconfig", + "service/appconfigdata", + "service/appfabric", + "service/appflow", + "service/appintegrations", + "service/applicationautoscaling", + "service/applicationcostprofiler", + "service/applicationdiscoveryservice", + "service/applicationinsights", + "service/appmesh", + "service/apprunner", + "service/appstream", + "service/appsync", + "service/arczonalshift", + "service/athena", + "service/auditmanager", + "service/autoscaling", + "service/autoscalingplans", + "service/backup", + "service/backupgateway", + "service/backupstorage", + "service/batch", + "service/bedrock", + "service/bedrockruntime", + "service/billingconductor", + "service/braket", + "service/budgets", + "service/chime", + "service/chimesdkidentity", + "service/chimesdkmediapipelines", + "service/chimesdkmeetings", + "service/chimesdkmessaging", + "service/chimesdkvoice", + "service/cleanrooms", + "service/cloud9", + "service/cloudcontrol", + "service/clouddirectory", + "service/cloudformation", + "service/cloudfront", + "service/cloudhsm", + "service/cloudhsmv2", + "service/cloudsearch", + "service/cloudsearchdomain", + "service/cloudtrail", + "service/cloudtraildata", + "service/cloudwatch", + "service/cloudwatchevents", + "service/cloudwatchlogs", + "service/codeartifact", + "service/codebuild", + "service/codecatalyst", + "service/codecommit", + "service/codedeploy", + "service/codeguruprofiler", + "service/codegurureviewer", + "service/codegurusecurity", + "service/codepipeline", + "service/codestar", + "service/codestarconnections", + "service/codestarnotifications", + "service/cognitoidentity", + "service/cognitoidentityprovider", + "service/cognitosync", + "service/comprehend", + "service/comprehendmedical", + "service/computeoptimizer", + "service/configservice", + "service/connect", + "service/connectcampaigns", + "service/connectcases", + "service/connectcontactlens", + "service/connectparticipant", + "service/controltower", + "service/costandusagereportservice", + "service/costexplorer", + "service/customerprofiles", + "service/databasemigrationservice", + "service/databrew", + "service/dataexchange", + "service/datapipeline", + "service/datasync", + "service/datazone", + "service/dax", + "service/detective", + "service/devicefarm", + "service/devopsguru", + "service/directconnect", + "service/directoryservice", + "service/dlm", + "service/docdb", + "service/docdbelastic", + "service/drs", + "service/dynamodb", + "service/dynamodbstreams", + "service/ebs", + "service/ec2", + "service/ec2instanceconnect", + "service/ecr", + "service/ecrpublic", + "service/ecs", + "service/efs", + "service/eks", + "service/elasticache", + "service/elasticbeanstalk", + "service/elasticinference", + "service/elasticloadbalancing", + "service/elasticloadbalancingv2", + "service/elasticsearchservice", + "service/elastictranscoder", + "service/emr", + "service/emrcontainers", + "service/emrserverless", + "service/entityresolution", + "service/eventbridge", + "service/evidently", + "service/finspace", + "service/finspacedata", + "service/firehose", + "service/fis", + "service/fms", + "service/forecast", + "service/forecastquery", + "service/frauddetector", + "service/fsx", + "service/gamelift", + "service/glacier", + "service/globalaccelerator", + "service/glue", + "service/grafana", + "service/greengrass", + "service/greengrassv2", + "service/groundstation", + "service/guardduty", + "service/health", + "service/healthlake", + "service/honeycode", + "service/iam", + "service/identitystore", + "service/imagebuilder", + "service/inspector", + "service/inspector2", + "service/internal/benchmark", + "service/internal/eventstreamtesting", + "service/internal/integrationtest", + "service/internetmonitor", + "service/iot", + "service/iot1clickdevicesservice", + "service/iot1clickprojects", + "service/iotanalytics", + "service/iotdataplane", + "service/iotdeviceadvisor", + "service/iotevents", + "service/ioteventsdata", + "service/iotfleethub", + "service/iotfleetwise", + "service/iotjobsdataplane", + "service/iotroborunner", + "service/iotsecuretunneling", + "service/iotsitewise", + "service/iotthingsgraph", + "service/iottwinmaker", + "service/iotwireless", + "service/ivs", + "service/ivschat", + "service/ivsrealtime", + "service/kafka", + "service/kafkaconnect", + "service/kendra", + "service/kendraranking", + "service/keyspaces", + "service/kinesis", + "service/kinesis/internal/testing", + "service/kinesisanalytics", + "service/kinesisanalyticsv2", + "service/kinesisvideo", + "service/kinesisvideoarchivedmedia", + "service/kinesisvideomedia", + "service/kinesisvideosignaling", + "service/kinesisvideowebrtcstorage", + "service/kms", + "service/lakeformation", + "service/lambda", + "service/lexmodelbuildingservice", + "service/lexmodelsv2", + "service/lexruntimeservice", + "service/lexruntimev2", + "service/licensemanager", + "service/licensemanagerlinuxsubscriptions", + "service/licensemanagerusersubscriptions", + "service/lightsail", + "service/location", + "service/lookoutequipment", + "service/lookoutmetrics", + "service/lookoutvision", + "service/m2", + "service/machinelearning", + "service/macie", + "service/macie2", + "service/managedblockchain", + "service/managedblockchainquery", + "service/marketplacecatalog", + "service/marketplacecommerceanalytics", + "service/marketplaceentitlementservice", + "service/marketplacemetering", + "service/mediaconnect", + "service/mediaconvert", + "service/medialive", + "service/mediapackage", + "service/mediapackagev2", + "service/mediapackagevod", + "service/mediastore", + "service/mediastoredata", + "service/mediatailor", + "service/medicalimaging", + "service/memorydb", + "service/mgn", + "service/migrationhub", + "service/migrationhubconfig", + "service/migrationhuborchestrator", + "service/migrationhubrefactorspaces", + "service/migrationhubstrategy", + "service/mobile", + "service/mq", + "service/mturk", + "service/mwaa", + "service/neptune", + "service/neptunedata", + "service/networkfirewall", + "service/networkmanager", + "service/nimble", + "service/oam", + "service/omics", + "service/opensearch", + "service/opensearchserverless", + "service/opsworks", + "service/opsworkscm", + "service/organizations", + "service/osis", + "service/outposts", + "service/panorama", + "service/paymentcryptography", + "service/paymentcryptographydata", + "service/pcaconnectorad", + "service/personalize", + "service/personalizeevents", + "service/personalizeruntime", + "service/pi", + "service/pinpoint", + "service/pinpointemail", + "service/pinpointsmsvoice", + "service/pinpointsmsvoicev2", + "service/pipes", + "service/polly", + "service/pricing", + "service/privatenetworks", + "service/proton", + "service/qldb", + "service/qldbsession", + "service/quicksight", + "service/ram", + "service/rbin", + "service/rds", + "service/rdsdata", + "service/redshift", + "service/redshiftdata", + "service/redshiftserverless", + "service/rekognition", + "service/resiliencehub", + "service/resourceexplorer2", + "service/resourcegroups", + "service/resourcegroupstaggingapi", + "service/robomaker", + "service/rolesanywhere", + "service/route53", + "service/route53domains", + "service/route53recoverycluster", + "service/route53recoverycontrolconfig", + "service/route53recoveryreadiness", + "service/route53resolver", + "service/rum", + "service/s3", + "service/s3/internal/configtesting", + "service/s3control", + "service/s3outposts", + "service/sagemaker", + "service/sagemakera2iruntime", + "service/sagemakeredge", + "service/sagemakerfeaturestoreruntime", + "service/sagemakergeospatial", + "service/sagemakermetrics", + "service/sagemakerruntime", + "service/savingsplans", + "service/scheduler", + "service/schemas", + "service/secretsmanager", + "service/securityhub", + "service/securitylake", + "service/serverlessapplicationrepository", + "service/servicecatalog", + "service/servicecatalogappregistry", + "service/servicediscovery", + "service/servicequotas", + "service/ses", + "service/sesv2", + "service/sfn", + "service/shield", + "service/signer", + "service/simspaceweaver", + "service/sms", + "service/snowball", + "service/snowdevicemanagement", + "service/sns", + "service/sqs", + "service/ssm", + "service/ssmcontacts", + "service/ssmincidents", + "service/ssmsap", + "service/sso", + "service/ssoadmin", + "service/ssooidc", + "service/storagegateway", + "service/sts", + "service/support", + "service/supportapp", + "service/swf", + "service/synthetics", + "service/textract", + "service/timestreamquery", + "service/timestreamwrite", + "service/tnb", + "service/transcribe", + "service/transcribestreaming", + "service/transcribestreaming/internal/testing", + "service/transfer", + "service/translate", + "service/verifiedpermissions", + "service/voiceid", + "service/vpclattice", + "service/waf", + "service/wafregional", + "service/wafv2", + "service/wellarchitected", + "service/wisdom", + "service/workdocs", + "service/worklink", + "service/workmail", + "service/workmailmessageflow", + "service/workspaces", + "service/workspacesweb", + "service/xray" + ] +} \ No newline at end of file From 5434101970aaf4bd1fe65b9d06e559e49187cf0b Mon Sep 17 00:00:00 2001 From: Isaiah Vita Date: Mon, 30 Oct 2023 07:54:39 -0700 Subject: [PATCH 26/26] change go.yml back to original state --- .github/workflows/go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f1e3ab5c56b..1b377bdf1b4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go-version: ["1.20", "1.21"] + go-version: [1.19, "1.20"] steps: - uses: actions/checkout@v2 @@ -48,7 +48,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go-version: [1.15, 1.16, 1.17, 1.18, 1.19] + go-version: [1.15, 1.16, 1.17, 1.18] exclude: - os: macos-latest go-version: 1.15 @@ -76,7 +76,7 @@ jobs: strategy: matrix: os: [windows-latest] - go-version: ["1.20", "1.21"] + go-version: [1.19, "1.20"] env: EACHMODULE_SKIP: "internal\\repotools\\changes" steps: @@ -103,7 +103,7 @@ jobs: strategy: matrix: os: [windows-latest] - go-version: [1.15, 1.16, 1.17, 1.18, 1.19] + go-version: [1.15, 1.16, 1.17, 1.18] env: EACHMODULE_SKIP: "internal\\repotools\\changes" steps: