-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "b39efe9f-60e1-4df1-b6fc-ab1c5795d0a4", | ||
"type": "feature", | ||
"description": "Add codegen definition for sigv4a trait.", | ||
"modules": [ | ||
"." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
41 changes: 0 additions & 41 deletions
41
...n/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/auth/SigV4aTrait.java
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
...en/src/main/java/software/amazon/smithy/go/codegen/integration/auth/SigV4ADefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.go.codegen.integration.auth; | ||
|
||
import static software.amazon.smithy.go.codegen.GoWriter.emptyGoTemplate; | ||
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; | ||
|
||
import java.util.Map; | ||
import software.amazon.smithy.aws.traits.auth.SigV4ATrait; | ||
import software.amazon.smithy.aws.traits.auth.SigV4Trait; | ||
import software.amazon.smithy.aws.traits.auth.UnsignedPayloadTrait; | ||
import software.amazon.smithy.go.codegen.GoWriter; | ||
import software.amazon.smithy.go.codegen.SmithyGoTypes; | ||
import software.amazon.smithy.go.codegen.integration.AuthSchemeDefinition; | ||
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator; | ||
import software.amazon.smithy.model.shapes.OperationShape; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.utils.MapUtils; | ||
|
||
/** | ||
* Implements codegen for aws.auth#sigv4a. | ||
*/ | ||
public class SigV4ADefinition implements AuthSchemeDefinition { | ||
private static final Map<String, Object> COMMON_ENV = MapUtils.of( | ||
"properties", SmithyGoTypes.Smithy.Properties, | ||
"option", SmithyGoTypes.Auth.Option, | ||
"schemeId", SmithyGoTypes.Auth.SchemeIDSigV4A, | ||
"setSigningName", SmithyGoTypes.Transport.Http.SetSigV4ASigningName, | ||
"setSigningRegions", SmithyGoTypes.Transport.Http.SetSigV4ASigningRegions | ||
); | ||
|
||
@Override | ||
public GoWriter.Writable generateServiceOption( | ||
ProtocolGenerator.GenerationContext context, ServiceShape service | ||
) { | ||
var trait = service.expectTrait(SigV4ATrait.class); | ||
return goTemplate(""" | ||
&$option:T{ | ||
SchemeID: $schemeId:T, | ||
SignerProperties: func() $properties:T { | ||
var props $properties:T | ||
$setSigningName:T(&props, $name:S) | ||
$setSigningRegions:T(&props, []string{params.Region}) | ||
return props | ||
}(), | ||
},""", | ||
COMMON_ENV, | ||
MapUtils.of( | ||
"name", trait.getName() | ||
)); | ||
} | ||
|
||
@Override | ||
public GoWriter.Writable generateOperationOption( | ||
ProtocolGenerator.GenerationContext context, OperationShape operation | ||
) { | ||
var trait = context.getService().expectTrait(SigV4Trait.class); | ||
return goTemplate(""" | ||
&$option:T{ | ||
SchemeID: $schemeId:T, | ||
SignerProperties: func() $properties:T { | ||
var props $properties:T | ||
$setSigningName:T(&props, $name:S) | ||
$setSigningRegions:T(&props, []string{params.Region}) | ||
$unsignedPayload:W | ||
return props | ||
}(), | ||
},""", | ||
COMMON_ENV, | ||
MapUtils.of( | ||
"name", trait.getName(), | ||
"unsignedPayload", generateIsUnsignedPayload(operation) | ||
)); | ||
} | ||
|
||
private GoWriter.Writable generateIsUnsignedPayload(OperationShape operation) { | ||
return operation.hasTrait(UnsignedPayloadTrait.class) | ||
? goTemplate("$T(&props, true)", SmithyGoTypes.Transport.Http.SetIsUnsignedPayload) | ||
: emptyGoTemplate(); | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
...en/src/main/java/software/amazon/smithy/go/codegen/integration/auth/SigV4aDefinition.java
This file was deleted.
Oops, something went wrong.