Skip to content

Commit 2c81f80

Browse files
authored
Endpoint Prefix & Idempotency Token Auto-fill, and Authentication Bugfixes (#1518)
* Ensure TopDownIndex is used when iterating service operations * Temporary Model Fix Transforms for Location Service * Fixed Idempotency Token Autofill * Fixed Endpoint Prefix Bug * Add Changelog Annotations
1 parent a29bcb0 commit 2c81f80

File tree

143 files changed

+4513
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4513
-61
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "b51f6004-654f-4c5e-b479-9d04a5045020",
3+
"type": "bugfix",
4+
"description": "Fixed an issue that prevent auto-filling of an API's idempotency parameters when not explictly provided by the caller.",
5+
"modules": [
6+
"service/accessanalyzer",
7+
"service/amp",
8+
"service/appmesh",
9+
"service/braket",
10+
"service/codeguruprofiler",
11+
"service/grafana",
12+
"service/nimble",
13+
"service/proton",
14+
"service/snowdevicemanagement",
15+
"service/wisdom"
16+
]
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "b55ca4d6-6d1d-4102-baf0-cb7c49f3bde3",
3+
"type": "bugfix",
4+
"description": "Fixed a bug that prevented the resolution of the correct endpoint for some API operations.",
5+
"modules": [
6+
"service/evidently",
7+
"service/location"
8+
]
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "ce7b78be-3401-4ab3-9c6d-0f40cd08bd56",
3+
"type": "bugfix",
4+
"description": "Fixed an issue that caused some operations to not be signed using sigv4, resulting in authentication failures.",
5+
"modules": [
6+
"service/location"
7+
]
8+
}

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.smithy.go.codegen.SymbolUtils;
3737
import software.amazon.smithy.go.codegen.integration.GoIntegration;
3838
import software.amazon.smithy.model.Model;
39+
import software.amazon.smithy.model.knowledge.TopDownIndex;
3940
import software.amazon.smithy.model.shapes.OperationShape;
4041
import software.amazon.smithy.model.shapes.ServiceShape;
4142
import software.amazon.smithy.model.shapes.Shape;
@@ -198,8 +199,7 @@ public void writeAdditionalFiles(
198199
writeConvertToPresignMiddleware(writer, model, symbolProvider, serviceShape);
199200
});
200201

201-
for (ShapeId operationId : serviceShape.getAllOperations()) {
202-
OperationShape operationShape = model.expectShape(operationId, OperationShape.class);
202+
for (OperationShape operationShape : TopDownIndex.of(model).getContainedOperations(serviceShape)) {
203203
if (!validOperations.contains(operationShape.getId())) {
204204
continue;
205205
}
@@ -229,11 +229,11 @@ private void writePresignOperationFunction(
229229
writer.writeDocs(
230230
String.format(
231231
"Presign%s is used to generate a presigned HTTP Request which contains presigned URL, signed headers "
232-
+ "and HTTP method used.", operationSymbol.getName())
232+
+ "and HTTP method used.", operationSymbol.getName())
233233
);
234234
writer.openBlock(
235235
"func (c *$T) Presign$T(ctx context.Context, params $P, optFns ...func($P)) "
236-
+ "($P, error) {", "}", presignClientSymbol, operationSymbol,
236+
+ "($P, error) {", "}", presignClientSymbol, operationSymbol,
237237
operationInputSymbol, presignOptionsSymbol, v4PresignedHTTPRequestSymbol,
238238
() -> {
239239
writer.write("if params == nil { params = &$T{} }", operationInputSymbol).insertTrailingNewline();
@@ -338,17 +338,17 @@ private void writeConvertToPresignMiddleware(
338338
smithyStack,
339339
() -> {
340340
Symbol smithyAfter = SymbolUtils.createValueSymbolBuilder("After",
341-
SmithyGoDependency.SMITHY_MIDDLEWARE)
341+
SmithyGoDependency.SMITHY_MIDDLEWARE)
342342
.build();
343343

344344
// Middleware to remove
345345
Symbol requestInvocationID = SymbolUtils.createPointableSymbolBuilder(
346-
"ClientRequestID",
347-
AwsGoDependency.AWS_MIDDLEWARE)
346+
"ClientRequestID",
347+
AwsGoDependency.AWS_MIDDLEWARE)
348348
.build();
349349

350350
Symbol presignMiddleware = SymbolUtils.createValueSymbolBuilder("NewPresignHTTPRequestMiddleware",
351-
AwsGoDependency.AWS_SIGNER_V4)
351+
AwsGoDependency.AWS_SIGNER_V4)
352352
.build();
353353

354354
// Middleware to add
@@ -385,25 +385,25 @@ private void writeConvertToPresignMiddleware(
385385
writer.write("// add multi-region access point presigner");
386386

387387
// ==== multi-region access point support
388-
Symbol PresignConstructor = SymbolUtils.createValueSymbolBuilder(
389-
"NewPresignHTTPRequestMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
390-
).build();
388+
Symbol PresignConstructor = SymbolUtils.createValueSymbolBuilder(
389+
"NewPresignHTTPRequestMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
390+
).build();
391391

392-
Symbol PresignOptions = SymbolUtils.createValueSymbolBuilder(
393-
"PresignHTTPRequestMiddlewareOptions", AwsCustomGoDependency.S3_CUSTOMIZATION
394-
).build();
392+
Symbol PresignOptions = SymbolUtils.createValueSymbolBuilder(
393+
"PresignHTTPRequestMiddlewareOptions", AwsCustomGoDependency.S3_CUSTOMIZATION
394+
).build();
395395

396-
Symbol RegisterPresigningMiddleware = SymbolUtils.createValueSymbolBuilder(
397-
"RegisterPreSigningMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
398-
).build();
396+
Symbol RegisterPresigningMiddleware = SymbolUtils.createValueSymbolBuilder(
397+
"RegisterPreSigningMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
398+
).build();
399399

400400
writer.openBlock("signermv := $T($T{", "})",
401-
PresignConstructor,PresignOptions, () -> {
402-
writer.write("CredentialsProvider : options.Credentials,");
403-
writer.write("V4Presigner : c.Presigner,");
404-
writer.write("V4aPresigner : c.presignerV4a,");
405-
writer.write("LogSigning : options.ClientLogMode.IsSigning(),");
406-
});
401+
PresignConstructor, PresignOptions, () -> {
402+
writer.write("CredentialsProvider : options.Credentials,");
403+
writer.write("V4Presigner : c.Presigner,");
404+
writer.write("V4aPresigner : c.presignerV4a,");
405+
writer.write("LogSigning : options.ClientLogMode.IsSigning(),");
406+
});
407407

408408
writer.write("err = $T(stack, signermv)", RegisterPresigningMiddleware);
409409
writer.write("if err != nil { return err }");
@@ -420,7 +420,7 @@ private void writeConvertToPresignMiddleware(
420420
"AddExpiresOnPresignedURL",
421421
AwsCustomGoDependency.S3_CUSTOMIZATION).build();
422422
writer.writeDocs("add middleware to set expiration for s3 presigned url, "
423-
+ " if expiration is set to 0, this middleware sets a default expiration of 900 seconds");
423+
+ " if expiration is set to 0, this middleware sets a default expiration of 900 seconds");
424424
writer.write("err = stack.Build.Add(&$T{ Expires: c.Expires, }, middleware.After)",
425425
expiresAsHeaderMiddleware);
426426
writer.write("if err != nil { return err }");
@@ -506,7 +506,7 @@ private void writePresignClientHelpers(
506506
// Helper function for NopClient
507507
writer.openBlock("func $L(o *Options) {", "}", NOP_HTTP_CLIENT_OPTION_FUNC_NAME, () -> {
508508
Symbol nopClientSymbol = SymbolUtils.createPointableSymbolBuilder("NopClient",
509-
SmithyGoDependency.SMITHY_HTTP_TRANSPORT)
509+
SmithyGoDependency.SMITHY_HTTP_TRANSPORT)
510510
.build();
511511

512512
writer.write("o.HTTPClient = $T{}", nopClientSymbol);
@@ -604,8 +604,8 @@ public void writePresignOptionType(
604604
writer.write("");
605605
writer.writeDocs(
606606
String.format("Expires sets the expiration duration for the generated presign url. This should "
607-
+ "be the duration in seconds the presigned URL should be considered valid for. If "
608-
+ "not set or set to zero, presign url would default to expire after 900 seconds."
607+
+ "be the duration in seconds the presigned URL should be considered valid for. If "
608+
+ "not set or set to zero, presign url would default to expire after 900 seconds."
609609
)
610610
);
611611
writer.write("Expires time.Duration");
@@ -632,15 +632,15 @@ public void writePresignOptionType(
632632
writer.openBlock("func $L(optFns ...func(*Options)) func($P) {", "}",
633633
PRESIGN_OPTIONS_FROM_CLIENT_OPTIONS, presignOptionsSymbol, () -> {
634634
writer.write("return $L(optFns).options", presignOptionsFromClientOptionsInternal.getName());
635-
});
635+
});
636636

637637
writer.insertTrailingNewline();
638638

639639
writer.write("type $L []func(*Options)", presignOptionsFromClientOptionsInternal.getName());
640640
writer.openBlock("func (w $L) options (o $P) {", "}",
641641
presignOptionsFromClientOptionsInternal.getName(), presignOptionsSymbol, () -> {
642642
writer.write("o.ClientOptions = append(o.ClientOptions, w...)");
643-
}).insertTrailingNewline();
643+
}).insertTrailingNewline();
644644

645645

646646
// s3 specific helpers
@@ -653,15 +653,15 @@ public void writePresignOptionType(
653653
writer.openBlock("func $L(dur time.Duration) func($P) {", "}",
654654
PRESIGN_OPTIONS_FROM_EXPIRES, presignOptionsSymbol, () -> {
655655
writer.write("return $L(dur).options", presignOptionsFromExpiresInternal.getName());
656-
});
656+
});
657657

658658
writer.insertTrailingNewline();
659659

660660
writer.write("type $L time.Duration", presignOptionsFromExpiresInternal.getName());
661661
writer.openBlock("func (w $L) options (o $P) {", "}",
662662
presignOptionsFromExpiresInternal.getName(), presignOptionsSymbol, () -> {
663663
writer.write("o.Expires = time.Duration(w)");
664-
}).insertTrailingNewline();
664+
}).insertTrailingNewline();
665665
}
666666
}
667667

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar;
2525
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
2626
import software.amazon.smithy.model.Model;
27+
import software.amazon.smithy.model.knowledge.TopDownIndex;
2728
import software.amazon.smithy.model.shapes.MemberShape;
2829
import software.amazon.smithy.model.shapes.OperationShape;
2930
import software.amazon.smithy.model.shapes.ServiceShape;
@@ -494,8 +495,7 @@ public void processFinalizedModel(GoSettings settings, Model model) {
494495
.build());
495496

496497

497-
for (ShapeId operationId : service.getAllOperations()) {
498-
OperationShape operation = model.expectShape(operationId, OperationShape.class);
498+
for (OperationShape operation : TopDownIndex.of(model).getContainedOperations(service)) {
499499
String helperFuncName = generateAddDiscoverEndpointMiddlewareName(service, operation);
500500

501501
Collection<Symbol> middlewareArgs = ListUtils.of(
@@ -556,8 +556,7 @@ public void writeAdditionalFiles(
556556
});
557557

558558
// generate code specific to the operation
559-
for (ShapeId id : service.getOperations()) {
560-
OperationShape operation = model.expectShape(id, OperationShape.class);
559+
for (OperationShape operation : TopDownIndex.of(model).getContainedOperations(service)) {
561560
goDelegator.useShapeWriter(operation, writer -> {
562561
generateAddDiscoverEndpointMiddleware(model, symbolProvider, writer, service, operation);
563562
generateFetchDiscoveredEndpointFunction(model, symbolProvider, writer, service, operation);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import software.amazon.smithy.go.codegen.integration.ProtocolUtils;
1414
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
1515
import software.amazon.smithy.model.Model;
16+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1617
import software.amazon.smithy.model.shapes.MemberShape;
1718
import software.amazon.smithy.model.shapes.OperationShape;
1819
import software.amazon.smithy.model.shapes.ServiceShape;
@@ -87,13 +88,12 @@ private void writeAccountIdSetter(
8788
writer.writeDocs("setDefaultAccountID sets the AccountID to the given value if the current value is nil");
8889
writer.openBlock("func setDefaultAccountID(input interface{}, accountID string) interface{} {", "}", () -> {
8990
writer.openBlock("switch i := input.(type) {", "}", () -> {
90-
for (ShapeId operationId : service.getAllOperations()) {
91-
OperationShape operation = model.expectShape(operationId, OperationShape.class);
91+
for (OperationShape operation : TopDownIndex.of(model).getContainedOperations(service)) {
9292
StructureShape input = ProtocolUtils.expectInput(model, operation);
9393

9494
List<MemberShape> accountId = input.getAllMembers().values().stream()
9595
.filter(m -> m.getMemberName().toLowerCase().equals("accountid"))
96-
.collect(Collectors.toList());
96+
.toList();
9797

9898
if (accountId.isEmpty()) {
9999
continue;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.smithy.aws.go.codegen.customization;
17+
18+
import java.util.List;
19+
import java.util.logging.Logger;
20+
import software.amazon.smithy.go.codegen.GoSettings;
21+
import software.amazon.smithy.go.codegen.integration.GoIntegration;
22+
import software.amazon.smithy.model.Model;
23+
import software.amazon.smithy.model.shapes.ShapeId;
24+
import software.amazon.smithy.model.traits.AuthTrait;
25+
import software.amazon.smithy.utils.ListUtils;
26+
27+
public class LocationModelFixes implements GoIntegration {
28+
private static final Logger LOGGER = Logger.getLogger(LocationModelFixes.class.getName());
29+
30+
private static final List<ShapeId> SHAPE_ID_EMPTY_AUTH_TRAIT_REMOVAL = ListUtils.of(
31+
ShapeId.from("com.amazonaws.location#BatchEvaluateGeofences"),
32+
ShapeId.from("com.amazonaws.location#DescribeGeofenceCollection"),
33+
ShapeId.from("com.amazonaws.location#DescribeMap"),
34+
ShapeId.from("com.amazonaws.location#DescribePlaceIndex"),
35+
ShapeId.from("com.amazonaws.location#DescribeRouteCalculator"),
36+
ShapeId.from("com.amazonaws.location#DescribeTracker")
37+
);
38+
39+
@Override
40+
public Model preprocessModel(
41+
Model model,
42+
GoSettings settings
43+
) {
44+
if (SHAPE_ID_EMPTY_AUTH_TRAIT_REMOVAL.size() == 0) {
45+
return model;
46+
}
47+
48+
var builder = model.toBuilder();
49+
50+
for (ShapeId shapeId : SHAPE_ID_EMPTY_AUTH_TRAIT_REMOVAL) {
51+
var optionalShape = model.getShape(shapeId);
52+
53+
if (optionalShape.isEmpty()) {
54+
continue;
55+
}
56+
57+
var shape = optionalShape.get().asOperationShape().get();
58+
59+
var optionalAuthTrait = shape.getTrait(AuthTrait.class);
60+
61+
if (optionalAuthTrait.isEmpty()) {
62+
LOGGER.warning(() -> String.format("%s no longer has an AuthTrait", shapeId));
63+
continue;
64+
}
65+
66+
var authTrait = optionalAuthTrait.get();
67+
68+
if (authTrait.getValueSet().size() != 0) {
69+
LOGGER.warning(() -> String.format("%s has a non-empty AuthTrait list and will not be removed",
70+
shapeId));
71+
continue;
72+
}
73+
74+
builder.addShape(shape.toBuilder()
75+
.removeTrait(AuthTrait.ID)
76+
.build());
77+
}
78+
79+
return builder.build();
80+
}
81+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import software.amazon.smithy.go.codegen.integration.ProtocolUtils;
1414
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
1515
import software.amazon.smithy.model.Model;
16+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1617
import software.amazon.smithy.model.shapes.OperationShape;
1718
import software.amazon.smithy.model.shapes.ServiceShape;
1819
import software.amazon.smithy.model.shapes.Shape;
@@ -57,11 +58,9 @@ public void writeAdditionalFiles(
5758
return;
5859
}
5960

60-
service.getAllOperations().stream()
61-
.filter(shapeId -> shapeId.getName(service).equalsIgnoreCase("Predict"))
61+
TopDownIndex.of(model).getContainedOperations(service).stream()
62+
.filter(shape -> shape.getId().getName(service).equalsIgnoreCase("Predict"))
6263
.findAny()
63-
.map(model::expectShape)
64-
.flatMap(Shape::asOperationShape)
6564
.ifPresent(operation -> {
6665
goDelegator.useShapeWriter(operation, writer -> writeEndpointAccessor(
6766
writer, model, symbolProvider, operation));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar;
1515
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
1616
import software.amazon.smithy.model.Model;
17+
import software.amazon.smithy.model.knowledge.TopDownIndex;
1718
import software.amazon.smithy.model.shapes.MemberShape;
1819
import software.amazon.smithy.model.shapes.OperationShape;
1920
import software.amazon.smithy.model.shapes.ServiceShape;
@@ -97,8 +98,7 @@ private void writeHostedZoneIDInputSanitizer(
9798

9899
writer.openBlock("func sanitizeHostedZoneIDInput(input interface{}) error {", "}", () -> {
99100
writer.openBlock("switch i:= input.(type) {", "}", () -> {
100-
service.getAllOperations().forEach((operationId)-> {
101-
OperationShape operation = model.expectShape(operationId, OperationShape.class);
101+
TopDownIndex.of(model).getContainedOperations(service).forEach((operation)-> {
102102
StructureShape input = model.expectShape(operation.getInput().get(), StructureShape.class);
103103
List<MemberShape> hostedZoneIDMembers = input.getAllMembers().values().stream()
104104
.filter(m -> m.getTarget().getName(service).equalsIgnoreCase("ResourceId")

0 commit comments

Comments
 (0)