Skip to content

Commit 1898f5b

Browse files
Adds support for S3 Multi-region Access Point ARNs (#1402)
* SigV4a Signer Implementation * v4A Credential Wrapper * Add Config Resolver for v4a Wrapping * Regenerated Clients * Presign Middleware Support * Add configuration settings for disable mrap * java codegen changes * add customizations to support s3 mrap * regenerate s3 client * update mrap customization to use DNS helper utils, change behavior for custom endpoints, export a constant for v4a * feedback and code cleanup * delete v4a signer stale commit from aws package * adds changelog entry for MRAP Co-authored-by: Sean McGrail <[email protected]>
1 parent 1412e59 commit 1898f5b

File tree

134 files changed

+4905
-803
lines changed

Some content is hidden

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

134 files changed

+4905
-803
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "0c026d00-c5d0-4cf3-a1a1-00108e4634da",
3+
"type": "feature",
4+
"description": "Add support for S3 Multi-Region Access Point ARNs.",
5+
"modules": [
6+
"config",
7+
"service/internal/s3shared",
8+
"service/s3"
9+
]
10+
}

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

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public class AwsHttpPresignURLClientGenerator implements GoIntegration {
7272
private static final Symbol presignerInterfaceSymbol = SymbolUtils.createPointableSymbolBuilder(
7373
"HTTPPresignerV4"
7474
).build();
75+
76+
private static final Symbol presignerV4aInterfaceSymbol = SymbolUtils.createPointableSymbolBuilder(
77+
"httpPresignerV4a"
78+
).build();
79+
80+
7581
private static final Symbol v4NewPresignerSymbol = SymbolUtils.createPointableSymbolBuilder(
7682
"NewSigner", AwsGoDependency.AWS_SIGNER_V4
7783
).build();
@@ -176,6 +182,9 @@ public void writeAdditionalFiles(
176182
// generate presigner interface
177183
writePresignInterface(writer, model, symbolProvider, serviceShape);
178184

185+
// generate s3 sigv4a presigner interface
186+
writePresignV4aInterface(writer, model, symbolProvider, serviceShape);
187+
179188
// generate presign options and helpers per service
180189
writePresignOptionType(writer, model, symbolProvider, serviceShape);
181190

@@ -371,6 +380,37 @@ private void writeConvertToPresignMiddleware(
371380

372381
// s3 service needs expires and sets unsignedPayload if input is stream
373382
if (isS3ServiceShape(model, serviceShape)) {
383+
384+
writer.write("");
385+
writer.write("// add multi-region access point presigner");
386+
387+
// ==== multi-region access point support
388+
Symbol PresignConstructor = SymbolUtils.createValueSymbolBuilder(
389+
"NewPresignHTTPRequestMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
390+
).build();
391+
392+
Symbol PresignOptions = SymbolUtils.createValueSymbolBuilder(
393+
"PresignHTTPRequestMiddlewareOptions", AwsCustomGoDependency.S3_CUSTOMIZATION
394+
).build();
395+
396+
Symbol RegisterPresigningMiddleware = SymbolUtils.createValueSymbolBuilder(
397+
"RegisterPreSigningMiddleware", AwsCustomGoDependency.S3_CUSTOMIZATION
398+
).build();
399+
400+
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+
});
407+
408+
writer.write("err = $T(stack, signermv)", RegisterPresigningMiddleware);
409+
writer.write("if err != nil { return err }");
410+
writer.write("");
411+
412+
// =======
413+
374414
writer.openBlock("if c.Expires < 0 {", "}", () -> {
375415
writer.addUseImports(SmithyGoDependency.FMT);
376416
writer.write(
@@ -437,6 +477,13 @@ private void writePresignClientType(
437477
});
438478
writer.write("");
439479

480+
if (isS3ServiceShape(model, serviceShape)) {
481+
writer.openBlock("if options.presignerV4a == nil {", "}", () -> {
482+
writer.write("options.presignerV4a = $L(c.options)", AwsSignatureVersion4.NEW_SIGNER_V4A_FUNC_NAME);
483+
});
484+
writer.write("");
485+
}
486+
440487
writer.openBlock("return &$L{", "}", presignClientSymbol, () -> {
441488
writer.write("client: c,");
442489
writer.write("options: options,");
@@ -494,6 +541,38 @@ public void writePresignInterface(
494541
writer.write("");
495542
}
496543

544+
545+
/**
546+
* Writes the presigner sigv4a interface used by the presign url client
547+
*/
548+
public void writePresignV4aInterface(
549+
GoWriter writer,
550+
Model model,
551+
SymbolProvider symbolProvider,
552+
ServiceShape serviceShape
553+
) {
554+
if (!isS3ServiceShape(model, serviceShape)) {
555+
return;
556+
}
557+
558+
Symbol signerOptionsSymbol = SymbolUtils.createPointableSymbolBuilder(
559+
"SignerOptions", AwsCustomGoDependency.S3_SIGV4A_CUSTOMIZATION).build();
560+
561+
writer.writeDocs(
562+
String.format("%s represents sigv4a presigner interface used by presign url client",
563+
presignerV4aInterfaceSymbol.getName())
564+
);
565+
writer.openBlock("type $T interface {", "}", presignerV4aInterfaceSymbol, () -> {
566+
writer.write("PresignHTTP(");
567+
writer.write("ctx context.Context, credentials v4a.Credentials, r *http.Request,");
568+
writer.write("payloadHash string, service string, regionSet []string, signingTime time.Time,");
569+
writer.write("optFns ...func($P),", signerOptionsSymbol);
570+
writer.write(") (url string, signedHeader http.Header, err error)");
571+
});
572+
573+
writer.write("");
574+
}
575+
497576
/**
498577
* Writes the Presign client's type and methods.
499578
*
@@ -530,8 +609,13 @@ public void writePresignOptionType(
530609
)
531610
);
532611
writer.write("Expires time.Duration");
612+
writer.write("");
613+
614+
writer.writeDocs("presignerV4a is the presigner used by the presign url client");
615+
writer.write("presignerV4a $T", presignerV4aInterfaceSymbol);
533616
}
534617
});
618+
535619
writer.openBlock("func (o $T) copy() $T {", "}", presignOptionsSymbol, presignOptionsSymbol, () -> {
536620
writer.write("clientOptions := make([]func(*Options), len(o.ClientOptions))");
537621
writer.write("copy(clientOptions, o.ClientOptions)");
@@ -548,15 +632,15 @@ public void writePresignOptionType(
548632
writer.openBlock("func $L(optFns ...func(*Options)) func($P) {", "}",
549633
PRESIGN_OPTIONS_FROM_CLIENT_OPTIONS, presignOptionsSymbol, () -> {
550634
writer.write("return $L(optFns).options", presignOptionsFromClientOptionsInternal.getName());
551-
});
635+
});
552636

553637
writer.insertTrailingNewline();
554638

555639
writer.write("type $L []func(*Options)", presignOptionsFromClientOptionsInternal.getName());
556640
writer.openBlock("func (w $L) options (o $P) {", "}",
557641
presignOptionsFromClientOptionsInternal.getName(), presignOptionsSymbol, () -> {
558642
writer.write("o.ClientOptions = append(o.ClientOptions, w...)");
559-
}).insertTrailingNewline();
643+
}).insertTrailingNewline();
560644

561645

562646
// s3 specific helpers
@@ -569,15 +653,15 @@ public void writePresignOptionType(
569653
writer.openBlock("func $L(dur time.Duration) func($P) {", "}",
570654
PRESIGN_OPTIONS_FROM_EXPIRES, presignOptionsSymbol, () -> {
571655
writer.write("return $L(dur).options", presignOptionsFromExpiresInternal.getName());
572-
});
656+
});
573657

574658
writer.insertTrailingNewline();
575659

576660
writer.write("type $L time.Duration", presignOptionsFromExpiresInternal.getName());
577661
writer.openBlock("func (w $L) options (o $P) {", "}",
578662
presignOptionsFromExpiresInternal.getName(), presignOptionsSymbol, () -> {
579663
writer.write("o.Expires = time.Duration(w)");
580-
}).insertTrailingNewline();
664+
}).insertTrailingNewline();
581665
}
582666
}
583667

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public final class AwsSignatureVersion4 implements GoIntegration {
4646
public static final String SIGNER_INTERFACE_NAME = "HTTPSignerV4";
4747
public static final String SIGNER_CONFIG_FIELD_NAME = SIGNER_INTERFACE_NAME;
4848
public static final String NEW_SIGNER_FUNC_NAME = "newDefaultV4Signer";
49+
public static final String NEW_SIGNER_V4A_FUNC_NAME = "newDefaultV4aSigner";
4950
public static final String SIGNER_RESOLVER = "resolve" + SIGNER_CONFIG_FIELD_NAME;
5051

5152
private static final List<String> DISABLE_URI_PATH_ESCAPE = ListUtils.of("com.amazonaws.s3#AmazonS3");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ 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");
2930
public static final GoDependency APIGATEWAY_CUSTOMIZATION = aws(
3031
"service/apigateway/internal/customizations", "agcust");
3132
public static final GoDependency GLACIER_CUSTOMIZATION = aws(

0 commit comments

Comments
 (0)