Skip to content

Commit

Permalink
codegen: track upstream sigv4a trait changes (#2442)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Jan 5, 2024
1 parent 47dd1b1 commit 686a64c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 16 deletions.
10 changes: 10 additions & 0 deletions .changelog/261461c495de4ce09c41eb674762b213.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "261461c4-95de-4ce0-9c41-eb674762b213",
"type": "feature",
"collapse": true,
"description": "Support smithy sigv4a trait for codegen.",
"modules": [
"service/eventbridge",
"service/s3"
]
}
2 changes: 1 addition & 1 deletion codegen/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
smithyVersion=1.41.1
smithyVersion=1.42.0
smithyGradleVersion=0.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package software.amazon.smithy.aws.go.codegen.customization.auth;

import software.amazon.smithy.aws.go.codegen.SdkGoTypes;
import software.amazon.smithy.aws.traits.auth.SigV4ATrait;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.GoDelegator;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoStdlibTypes;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoTypes;
import software.amazon.smithy.go.codegen.auth.SigV4aTrait;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.go.codegen.integration.auth.SigV4aDefinition;
import software.amazon.smithy.go.codegen.integration.auth.SigV4ADefinition;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.MapUtils;
Expand All @@ -43,7 +43,7 @@ public class AwsSigV4aAuthScheme implements GoIntegration {
public List<RuntimeClientPlugin> getClientPlugins() {
return ListUtils.of(
RuntimeClientPlugin.builder()
.addAuthSchemeDefinition(SigV4aTrait.ID, new AwsSigV4a())
.addAuthSchemeDefinition(SigV4ATrait.ID, new AwsSigV4A())
.build()
);
}
Expand All @@ -52,12 +52,12 @@ public List<RuntimeClientPlugin> getClientPlugins() {
public void writeAdditionalFiles(
GoSettings settings, Model model, SymbolProvider symbolProvider, GoDelegator goDelegator
) {
if (settings.getService(model).hasTrait(SigV4aTrait.class)) {
if (settings.getService(model).hasTrait(SigV4ATrait.class)) {
goDelegator.useFileWriter("options.go", settings.getModuleName(), generateAdditionalSource());
}
}

public static class AwsSigV4a extends SigV4aDefinition {
public static class AwsSigV4A extends SigV4ADefinition {
@Override
public GoWriter.Writable generateDefaultAuthScheme() {
return goTemplate("""
Expand All @@ -67,7 +67,7 @@ public GoWriter.Writable generateDefaultAuthScheme() {
LogSigning: options.ClientLogMode.IsSigning(),
})""",
SdkGoTypes.Internal.Auth.NewHTTPAuthScheme,
SigV4aTrait.ID.toString(),
SigV4ATrait.ID.toString(),
SdkGoTypes.Internal.V4A.SignerAdapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package software.amazon.smithy.aws.go.codegen.customization.auth;

import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.aws.traits.auth.SigV4ATrait;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.auth.SigV4aTrait;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ServiceShape;
Expand All @@ -28,24 +28,27 @@
/**
* Throws the aws.auth#sigv4a trait onto the service such that auth codegen picks it up.
*/
public class BackfillSigV4aTrait implements GoIntegration {
private boolean isBackfillSigV4aService(ServiceShape service) {
public class BackfillSigV4ATrait implements GoIntegration {
private boolean isBackfillService(ServiceShape service) {
final String sdkId = service.expectTrait(ServiceTrait.class).getSdkId();
return sdkId.equalsIgnoreCase("s3") || sdkId.equalsIgnoreCase("eventbridge");
};

@Override
public Model preprocessModel(Model model, GoSettings settings) {
ServiceShape service = settings.getService(model);
if (!isBackfillSigV4aService(service)) {
if (!isBackfillService(service)) {
return model;
}

var v4a = SigV4ATrait.builder()
.name(service.expectTrait(SigV4Trait.class).getName())
.build();
return model.toBuilder()
.addShape(
service.toBuilder()
.addTrait(new SigV4aTrait())
.addTrait(new AuthTrait(SetUtils.of(SigV4Trait.ID, SigV4aTrait.ID)))
.addTrait(v4a)
.addTrait(new AuthTrait(SetUtils.of(SigV4Trait.ID, SigV4ATrait.ID)))
.build()
)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
software.amazon.smithy.aws.go.codegen.customization.auth.BackfillSigV4aTrait
software.amazon.smithy.aws.go.codegen.customization.auth.BackfillSigV4ATrait
software.amazon.smithy.aws.go.codegen.AddProtocols
software.amazon.smithy.aws.go.codegen.ClientResolvedDefaultsMode
software.amazon.smithy.aws.go.codegen.AddAwsConfigFields
Expand Down
10 changes: 9 additions & 1 deletion service/eventbridge/auth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion service/s3/auth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 686a64c

Please sign in to comment.