Skip to content

Commit 17abc5e

Browse files
authored
Updates to Amazon EventBridge API Client (#1663)
* Relocate s3/internal/v4a to internal/v4a * Implementation * Regenerated Clients * Add Changelog Entry for v4a module release
1 parent 889e1da commit 17abc5e

File tree

69 files changed

+4841
-243
lines changed

Some content is hidden

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

69 files changed

+4841
-243
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "2a395467-f888-4401-90bb-f72ada747135",
3+
"type": "release",
4+
"description": "New internal v4a signing module location.",
5+
"modules": [
6+
"internal/v4a"
7+
]
8+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
public final class AwsEndpointGenerator implements GoIntegration {
3939
public static final String ENDPOINT_RESOLVER_CONFIG_NAME = "EndpointResolver";
40+
public static final String ENDPOINT_OPTIONS_CONFIG_NAME = "EndpointOptions";
4041

4142
@Override
4243
public void writeAdditionalFiles(
@@ -46,7 +47,8 @@ public void writeAdditionalFiles(
4647
TriConsumer<String, String, Consumer<GoWriter>> writerFactory
4748
) {
4849
String serviceId = settings.getService(model).expectTrait(ServiceTrait.class).getSdkId();
49-
boolean generateQueryHelpers = serviceId.equalsIgnoreCase("S3");
50+
boolean generateQueryHelpers = serviceId.equalsIgnoreCase("S3")
51+
|| serviceId.equalsIgnoreCase("EventBridge");
5052

5153
EndpointGenerator.builder()
5254
.settings(settings)
@@ -70,7 +72,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
7072
.withHelper(true)
7173
.build(),
7274
ConfigField.builder()
73-
.name("EndpointOptions")
75+
.name(ENDPOINT_OPTIONS_CONFIG_NAME)
7476
.type(SymbolUtils.createValueSymbolBuilder(EndpointGenerator.RESOLVER_OPTIONS)
7577
.build())
7678
.documentation("The endpoint options to be used when attempting "

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class AwsGoDependency {
4949
public static final GoDependency AWS_DEFAULTS = aws("aws/defaults");
5050
public static final GoDependency SERVICE_INTERNAL_CHECKSUM = awsModuleDep("service/internal/checksum",
5151
null, Versions.SERVICE_INTERNAL_CHECKSUM, "internalChecksum");
52+
public static final GoDependency INTERNAL_SIGV4A = awsModuleDep("internal/v4a",
53+
null, Versions.INTERNAL_SIGV4A, "v4a");
5254

5355
public static final GoDependency REGEXP = SmithyGoDependency.stdlib("regexp");
5456

@@ -102,5 +104,6 @@ private static final class Versions {
102104
private static final String INTERNAL_ENDPOINTS_V2 = "v2.0.0-00010101000000-000000000000";
103105
private static final String AWS_PROTOCOL_EVENTSTREAM = "v0.0.0-00010101000000-000000000000";
104106
private static final String SERVICE_INTERNAL_CHECKSUM = "v0.0.0-00010101000000-000000000000";
107+
private static final String INTERNAL_SIGV4A = "v0.0.0-00010101000000-000000000000";
105108
}
106109
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public void writePresignV4aInterface(
556556
}
557557

558558
Symbol signerOptionsSymbol = SymbolUtils.createPointableSymbolBuilder(
559-
"SignerOptions", AwsCustomGoDependency.S3_SIGV4A_CUSTOMIZATION).build();
559+
"SignerOptions", AwsGoDependency.INTERNAL_SIGV4A).build();
560560

561561
writer.writeDocs(
562562
String.format("%s represents sigv4a presigner interface used by presign url client",
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright 2020 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;
17+
18+
import software.amazon.smithy.aws.go.codegen.customization.AwsCustomGoDependency;
19+
import software.amazon.smithy.go.codegen.GoDependency;
20+
import software.amazon.smithy.go.codegen.GoWriter;
21+
import software.amazon.smithy.go.codegen.SmithyGoDependency;
22+
import software.amazon.smithy.go.codegen.SymbolUtils;
23+
import software.amazon.smithy.model.Model;
24+
import software.amazon.smithy.model.shapes.ServiceShape;
25+
26+
/**
27+
* Generates Client Configuration, Middleware, and Config Resolvers for AWS Signature Version 4a support.
28+
*/
29+
public final class AwsSignatureVersion4aUtils {
30+
public static final String RESOLVE_CREDENTIAL_PROVIDER = "resolveCredentialProvider";
31+
public static final String REGISTER_MIDDLEWARE_FUNCTION = "swapWithCustomHTTPSignerMiddleware";
32+
public static final String V4A_SIGNER_INTERFACE_NAME = "httpSignerV4a";
33+
public static final String SIGNER_OPTION_FIELD_NAME = V4A_SIGNER_INTERFACE_NAME;
34+
public static final String NEW_SIGNER_FUNC_NAME = "newDefaultV4aSigner";
35+
public static final String SIGNER_RESOLVER = "resolveHTTPSignerV4a";
36+
37+
public static void writeCredentialProviderResolver(GoWriter writer) {
38+
writer.pushState();
39+
writer.putContext("resolverName", RESOLVE_CREDENTIAL_PROVIDER);
40+
writer.putContext("fieldName", AddAwsConfigFields.CREDENTIALS_CONFIG_NAME);
41+
writer.putContext("credType", SymbolUtils.createPointableSymbolBuilder("CredentialsProvider",
42+
AwsCustomGoDependency.INTERNAL_SIGV4A).build());
43+
writer.putContext("anonType", SymbolUtils.createPointableSymbolBuilder("AnonymousCredentials",
44+
AwsCustomGoDependency.AWS_CORE).build());
45+
writer.putContext("adapType", SymbolUtils.createPointableSymbolBuilder("SymmetricCredentialAdaptor",
46+
AwsCustomGoDependency.INTERNAL_SIGV4A).build());
47+
writer.write("""
48+
func $resolverName:L(o *Options) {
49+
if o.$fieldName:L == nil {
50+
return
51+
}
52+
53+
if _, ok := o.$fieldName:L.($credType:T); ok {
54+
return
55+
}
56+
57+
switch o.$fieldName:L.(type) {
58+
case $anonType:T, $anonType:P:
59+
return
60+
}
61+
62+
o.$fieldName:L = &$adapType:T{SymmetricProvider: o.$fieldName:L}
63+
}
64+
""");
65+
writer.popState();
66+
}
67+
68+
public static void writerSignerInterface(GoWriter writer) {
69+
writer.pushState();
70+
writer.putContext("ifaceName", V4A_SIGNER_INTERFACE_NAME);
71+
writer.putContext("contextType", SymbolUtils.createValueSymbolBuilder("Context",
72+
SmithyGoDependency.CONTEXT).build());
73+
writer.putContext("credType", SymbolUtils.createValueSymbolBuilder("Credentials",
74+
AwsGoDependency.INTERNAL_SIGV4A).build());
75+
writer.putContext("reqType", SymbolUtils.createPointableSymbolBuilder("Request",
76+
SmithyGoDependency.NET_HTTP).build());
77+
writer.putContext("timeType", SymbolUtils.createPointableSymbolBuilder("Time",
78+
SmithyGoDependency.TIME).build());
79+
writer.putContext("optionsType", SymbolUtils.createPointableSymbolBuilder("SignerOptions",
80+
AwsGoDependency.INTERNAL_SIGV4A).build());
81+
writer.write("""
82+
type $ifaceName:L interface {
83+
SignHTTP(ctx $contextType:T, credentials $credType:T, r $reqType:P, payloadHash,
84+
service string, regionSet []string, signingTime $timeType:T,
85+
optFns ...func($optionsType:P)) error
86+
}
87+
""");
88+
writer.popState();
89+
}
90+
91+
public static void writerConfigFieldResolver(GoWriter writer, ServiceShape serviceShape) {
92+
writer.pushState();
93+
writer.putContext("resolverName", SIGNER_RESOLVER);
94+
writer.putContext("optionName", SIGNER_OPTION_FIELD_NAME);
95+
writer.putContext("newSigner", NEW_SIGNER_FUNC_NAME);
96+
writer.write("""
97+
func $resolverName:L(o *Options) {
98+
if o.$optionName:L != nil {
99+
return
100+
}
101+
o.$optionName:L = $newSigner:L(*o)
102+
}
103+
""");
104+
writer.popState();
105+
}
106+
107+
public static void writeNewV4ASignerFunc(GoWriter writer, ServiceShape serviceShape) {
108+
writeNewV4ASignerFunc(writer, serviceShape, false);
109+
}
110+
111+
public static void writeNewV4ASignerFunc(
112+
GoWriter writer,
113+
ServiceShape serviceShape,
114+
boolean disableURIPathEscaping
115+
) {
116+
writer.pushState();
117+
writer.putContext("funcName", NEW_SIGNER_FUNC_NAME);
118+
writer.putContext("signerType", SymbolUtils.createPointableSymbolBuilder("Signer",
119+
AwsCustomGoDependency.INTERNAL_SIGV4A).build());
120+
writer.putContext("newSigner", SymbolUtils.createValueSymbolBuilder("NewSigner",
121+
AwsCustomGoDependency.INTERNAL_SIGV4A).build());
122+
writer.putContext("signerOptions", SymbolUtils.createPointableSymbolBuilder("SignerOptions",
123+
AwsCustomGoDependency.INTERNAL_SIGV4A).build());
124+
writer.putContext("loggerField", AddAwsConfigFields.LOGGER_CONFIG_NAME);
125+
writer.putContext("modeField", AddAwsConfigFields.LOG_MODE_CONFIG_NAME);
126+
writer.putContext("disableEscape", disableURIPathEscaping);
127+
writer.write("""
128+
func $funcName:L(o Options) $signerType:P {
129+
return $newSigner:T(func(so $signerOptions:P){
130+
so.Logger = o.$loggerField:L
131+
so.LogSigning = o.$modeField:L.IsSigning()
132+
so.DisableURIPathEscaping = $disableEscape:L
133+
})
134+
}
135+
""");
136+
writer.popState();
137+
}
138+
139+
public static void writeMiddlewareRegister(
140+
Model model,
141+
GoWriter writer,
142+
ServiceShape serviceShape,
143+
GoDependency signerMiddleware
144+
) {
145+
writer.pushState();
146+
writer.putContext("funcName", REGISTER_MIDDLEWARE_FUNCTION);
147+
writer.putContext("stackType", SymbolUtils.createPointableSymbolBuilder("Stack",
148+
SmithyGoDependency.SMITHY_MIDDLEWARE).build());
149+
writer.putContext("newMiddleware", SymbolUtils.createValueSymbolBuilder(
150+
"NewSignHTTPRequestMiddleware", signerMiddleware).build());
151+
writer.putContext("middleOptions", SymbolUtils.createValueSymbolBuilder(
152+
"SignHTTPRequestMiddlewareOptions", signerMiddleware).build());
153+
writer.putContext("registerMiddleware", SymbolUtils.createValueSymbolBuilder(
154+
"RegisterSigningMiddleware", signerMiddleware).build());
155+
writer.putContext("credFileName", AddAwsConfigFields.CREDENTIALS_CONFIG_NAME);
156+
writer.putContext("v4Signer", AwsSignatureVersion4.SIGNER_CONFIG_FIELD_NAME);
157+
writer.putContext("v4aSigner", SIGNER_OPTION_FIELD_NAME);
158+
writer.putContext("logMode", AddAwsConfigFields.LOG_MODE_CONFIG_NAME);
159+
writer.write("""
160+
func $funcName:L(stack $stackType:P, o Options) error {
161+
mw := $newMiddleware:T($middleOptions:T{
162+
CredentialsProvider: o.$credFileName:L,
163+
V4Signer: o.$v4Signer:L,
164+
V4aSigner: o.$v4aSigner:L,
165+
LogSigning: o.$logMode:L.IsSigning(),
166+
})
167+
168+
return $registerMiddleware:T(stack, mw)
169+
}
170+
""");
171+
writer.popState();
172+
}
173+
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,25 @@ private void generateDNSSuffixFunction(GoWriter writer) {
359359
});
360360
writer.openBlock("default:", "", () -> writer.write("return \"\", fmt.Errorf(\"unknown partition\")"));
361361
});
362-
});
363-
writer.write("");
362+
}).write("");
363+
364+
writer.writeDocs("GetDNSSuffixFromRegion returns the DNS suffix for the provided region and options.");
365+
writer.openBlock("func GetDNSSuffixFromRegion(region string, options $T) (string, error) {", "}", optionsSymbol,
366+
() -> {
367+
List<Partition> sortedPartitions = getSortedPartitions();
368+
writer.openBlock("switch {", "}", () -> {
369+
sortedPartitions.forEach(partition -> {
370+
writer.write("""
371+
case partitionRegexp.$L.MatchString(region):
372+
return GetDNSSuffix($S, options)
373+
""", getPartitionIDFieldName(partition.getId()), partition.getId());
374+
});
375+
writer.write("""
376+
default:
377+
return GetDNSSuffix("aws", options)
378+
""");
379+
});
380+
}).write("");
364381
}
365382

366383
private void generateAwsEndpointResolverWrapper(GoWriter writer) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public final class AwsCustomGoDependency extends AwsGoDependency {
2626
"service/dynamodb/internal/customizations", "ddbcust");
2727
public static final GoDependency S3_CUSTOMIZATION = aws("service/s3/internal/customizations", "s3cust");
2828
public static final GoDependency S3CONTROL_CUSTOMIZATION = aws("service/s3control/internal/customizations", "s3controlcust");
29-
public static final GoDependency S3_SIGV4A_CUSTOMIZATION = aws("service/s3/internal/v4a");
3029
public static final GoDependency APIGATEWAY_CUSTOMIZATION = aws(
3130
"service/apigateway/internal/customizations", "agcust");
3231
public static final GoDependency GLACIER_CUSTOMIZATION = aws(
@@ -43,6 +42,7 @@ public final class AwsCustomGoDependency extends AwsGoDependency {
4342
"service/route53/internal/customizations", "route53cust");
4443
public static final GoDependency PRESIGNEDURL_CUSTOMIZATION = awsModuleDep(
4544
"service/internal/presigned-url", null, Versions.INTERNAL_PRESIGNURL, "presignedurlcust");
45+
public static final GoDependency EVENTBRIDGE_CUSTOMIZATION = aws("service/eventbridge/internal/customizations", "ebcust");
4646

4747
private AwsCustomGoDependency() {
4848
super();

0 commit comments

Comments
 (0)