Skip to content

Commit 4682b6a

Browse files
authored
Achieve DisableMRAP parity in config loaders (#2239)
1 parent 7ecab86 commit 4682b6a

File tree

7 files changed

+107
-3
lines changed

7 files changed

+107
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "7c8973c1-e65d-45e5-9ef3-49859b24026a",
3+
"type": "announcement",
4+
"description": "BREAKFIX: corrected function spelling in environment config from GetS3DisableMultRegionAccessPoints to GetS3DisableMultiRegionAccessPoints",
5+
"modules": [
6+
"service/s3control"
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "8e145919-b32d-4a33-816c-eb4aa78031ac",
3+
"type": "bugfix",
4+
"description": "Adds DisableMRAP option to config loader, and DisableMRAP client resolver to achieve parity with other S3 options in the config loader. Additionally, added breakfix to correct spelling.",
5+
"modules": [
6+
"service/s3control"
7+
]
8+
}

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/ResolveClientConfigFromSources.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ public class ResolveClientConfigFromSources implements GoIntegration {
2424
private static final Logger LOGGER = Logger.getLogger(AddAwsConfigFields.class.getName());
2525

2626
private static final String CONFIG_SOURCE_CONFIG_NAME = "ConfigSources";
27-
// UseARNRegion
27+
2828
private static final String USE_ARN_REGION_OPTION = "UseARNRegion";
2929
private static final String USE_ARN_REGION_CONFIG_RESOLVER = "resolveUseARNRegion";
3030
private static final String RESOLVE_USE_ARN_REGION = "ResolveUseARNRegion";
3131

32+
private static final String DISABLE_MRAP_OPTION = "DisableMultiRegionAccessPoints";
33+
private static final String DISABLE_MRAP_CONFIG_RESOLVER = "resolveDisableMultiRegionAccessPoints";
34+
private static final String RESOLVE_DISABLE_MRAP = "ResolveDisableMultiRegionAccessPoints";
35+
3236
// EndpointDiscovery options
3337
private static final String ENDPOINT_DISCOVERY_OPTION = "EndpointDiscovery";
3438
private static final Symbol ENDPOINT_DISCOVERY_OPTION_TYPE = SymbolUtils.createValueSymbolBuilder(
@@ -54,6 +58,14 @@ public class ResolveClientConfigFromSources implements GoIntegration {
5458
.awsResolveFunction(SymbolUtils.createValueSymbolBuilder(USE_ARN_REGION_CONFIG_RESOLVER)
5559
.build())
5660
.build(),
61+
AddAwsConfigFields.AwsConfigField.builder()
62+
.name(DISABLE_MRAP_OPTION)
63+
.type(getUniversalSymbol("bool"))
64+
.generatedOnClient(false)
65+
.servicePredicate(ResolveClientConfigFromSources::isS3Service)
66+
.awsResolveFunction(SymbolUtils.createValueSymbolBuilder(DISABLE_MRAP_CONFIG_RESOLVER)
67+
.build())
68+
.build(),
5769
AddAwsConfigFields.AwsConfigField.builder()
5870
.name(ENDPOINT_DISCOVERY_OPTION)
5971
.type(ENDPOINT_DISCOVERY_OPTION_TYPE)
@@ -89,6 +101,7 @@ public void writeAdditionalFiles(
89101
ServiceShape serviceShape = settings.getService(model);
90102
goDelegator.useShapeWriter(serviceShape, writer -> {
91103
generateUseARNRegionResolver(model, serviceShape, writer);
104+
generateDisableMrapResolver(model, serviceShape, writer);
92105
generateEnableEndpointDiscoveryResolver(model, serviceShape, writer);
93106
generateUseUseDualStackResolver(model, serviceShape, writer);
94107
generateUseUseFIPSEndpointResolver(model, serviceShape, writer);
@@ -128,6 +141,22 @@ private static void generateUseARNRegionResolver(Model model, ServiceShape servi
128141
writer.write("");
129142
}
130143

144+
private static void generateDisableMrapResolver(Model model, ServiceShape serviceShape, GoWriter writer) {
145+
if (!isS3Service(model, serviceShape)) {
146+
return;
147+
}
148+
generatedResolverFunction(writer, DISABLE_MRAP_CONFIG_RESOLVER, "resolves DisableMultiRegionAccessPoints S3 configuration", () -> {
149+
writer.addUseImports(SmithyGoDependency.CONTEXT);
150+
Symbol resolverFunc = SymbolUtils.createValueSymbolBuilder(RESOLVE_DISABLE_MRAP,
151+
AwsGoDependency.S3_SHARED_CONFIG).build();
152+
writer.write("value, found, err := $T(context.Background(), cfg.$L)", resolverFunc,
153+
CONFIG_SOURCE_CONFIG_NAME);
154+
writer.write("if err != nil { return err }");
155+
writer.write("if found { o.$L = value }", DISABLE_MRAP_OPTION);
156+
});
157+
writer.write("");
158+
}
159+
131160
private static void generateEnableEndpointDiscoveryResolver(
132161
Model model,
133162
ServiceShape serviceShape,

config/env_config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ func (c EnvConfig) GetS3UseARNRegion(ctx context.Context) (value, ok bool, err e
482482
return *c.S3UseARNRegion, true, nil
483483
}
484484

485-
// GetS3DisableMultRegionAccessPoints returns whether to disable multi-region access point
485+
// GetS3DisableMultiRegionAccessPoints returns whether to disable multi-region access point
486486
// support for the S3 client.
487-
func (c EnvConfig) GetS3DisableMultRegionAccessPoints(ctx context.Context) (value, ok bool, err error) {
487+
func (c EnvConfig) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (value, ok bool, err error) {
488488
if c.S3DisableMultiRegionAccessPoints == nil {
489489
return false, false, nil
490490
}

config/load_options.go

+24
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ type LoadOptions struct {
172172
// the region, the client's requests are sent to.
173173
S3UseARNRegion *bool
174174

175+
// S3DisableMultiRegionAccessPoints specifies if the S3 service should disable
176+
// the S3 Multi-Region access points feature.
177+
S3DisableMultiRegionAccessPoints *bool
178+
175179
// EnableEndpointDiscovery specifies if endpoint discovery is enable for
176180
// the client.
177181
EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
@@ -876,6 +880,26 @@ func WithS3UseARNRegion(v bool) LoadOptionsFunc {
876880
}
877881
}
878882

883+
// GetS3DisableMultiRegionAccessPoints returns whether to disable
884+
// the S3 multi-region access points feature.
885+
func (o LoadOptions) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (v bool, found bool, err error) {
886+
if o.S3DisableMultiRegionAccessPoints == nil {
887+
return false, false, nil
888+
}
889+
return *o.S3DisableMultiRegionAccessPoints, true, nil
890+
}
891+
892+
// WithS3DisableMultiRegionAccessPoints is a helper function to construct functional options
893+
// that can be used to set S3DisableMultiRegionAccessPoints on LoadOptions.
894+
// If multiple WithS3DisableMultiRegionAccessPoints calls are made, the last call overrides
895+
// the previous call values.
896+
func WithS3DisableMultiRegionAccessPoints(v bool) LoadOptionsFunc {
897+
return func(o *LoadOptions) error {
898+
o.S3DisableMultiRegionAccessPoints = &v
899+
return nil
900+
}
901+
}
902+
879903
// GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
880904
func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
881905
if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {

service/internal/s3shared/config/config.go

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ type UseARNRegionProvider interface {
77
GetS3UseARNRegion(ctx context.Context) (value bool, found bool, err error)
88
}
99

10+
// DisableMultiRegionAccessPointsProvider is an interface for retrieving external configuration value for DisableMultiRegionAccessPoints
11+
type DisableMultiRegionAccessPointsProvider interface {
12+
GetS3DisableMultiRegionAccessPoints(ctx context.Context) (value bool, found bool, err error)
13+
}
14+
1015
// ResolveUseARNRegion extracts the first instance of a UseARNRegion from the config slice.
1116
// Additionally returns a boolean to indicate if the value was found in provided configs, and error if one is encountered.
1217
func ResolveUseARNRegion(ctx context.Context, configs []interface{}) (value bool, found bool, err error) {
@@ -20,3 +25,17 @@ func ResolveUseARNRegion(ctx context.Context, configs []interface{}) (value bool
2025
}
2126
return
2227
}
28+
29+
// ResolveDisableMultiRegionAccessPoints extracts the first instance of a DisableMultiRegionAccessPoints from the config slice.
30+
// Additionally returns a boolean to indicate if the value was found in provided configs, and error if one is encountered.
31+
func ResolveDisableMultiRegionAccessPoints(ctx context.Context, configs []interface{}) (value bool, found bool, err error) {
32+
for _, cfg := range configs {
33+
if p, ok := cfg.(DisableMultiRegionAccessPointsProvider); ok {
34+
value, found, err = p.GetS3DisableMultiRegionAccessPoints(ctx)
35+
if err != nil || found {
36+
break
37+
}
38+
}
39+
}
40+
return
41+
}

service/s3/api_client.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)