Skip to content

Commit ab6e124

Browse files
committed
add codegen region validation
1 parent 7f09d56 commit ab6e124

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func bindAuthParamsRegion( _ interface{}, params $P, _ interface{}, options Opti
106106
private GoWriter.Writable writeEndpointParamResolver() {
107107
return goTemplate("""
108108
func bindAuthEndpointParams(ctx $P, params $P, input interface{}, options Options) {
109-
params.endpointParams = bindEndpointParams(ctx, input, options)
109+
params.endpointParams, _ = bindEndpointParams(ctx, input, options)
110110
}
111111
""", GoStdlibTypes.Context.Context, AuthParametersGenerator.STRUCT_SYMBOL);
112112
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import software.amazon.smithy.codegen.core.SymbolProvider;
55
import software.amazon.smithy.go.codegen.GoDelegator;
66
import software.amazon.smithy.go.codegen.GoSettings;
7+
import software.amazon.smithy.go.codegen.GoStdlibTypes;
78
import software.amazon.smithy.go.codegen.GoWriter;
89
import software.amazon.smithy.go.codegen.SmithyGoTypes;
910
import software.amazon.smithy.go.codegen.integration.GoIntegration;
@@ -93,12 +94,23 @@ func resolveAccountID(identity $auth:T, mode $accountIDEndpointMode:T) *string {
9394

9495
private GoWriter.Writable builtinBindingSource() {
9596
return goTemplate("""
96-
func bindRegion(region string) *string {
97+
func bindRegion(region string) (*string, error) {
9798
if region == "" {
98-
return nil
99+
return nil, nil
99100
}
100-
return $T($T(region))
101+
if !$validHost:T(region) {
102+
return nil, $error:T("invalid input region %s", region)
103+
}
104+
105+
return $awsString:T($mapFipsRegion:T(region)), nil
101106
}
102-
""", SdkGoTypes.Aws.String, SdkGoTypes.Internal.Endpoints.MapFIPSRegion);
107+
""",
108+
MapUtils.of(
109+
"awsString", SdkGoTypes.Aws.String,
110+
"mapFipsRegion", SdkGoTypes.Internal.Endpoints.MapFIPSRegion,
111+
"error", GoStdlibTypes.Fmt.Errorf,
112+
"validHost", SmithyGoTypes.Transport.Http.ValidHostLabel
113+
)
114+
);
103115
}
104116
}

0 commit comments

Comments
 (0)