Skip to content

Commit 1aff970

Browse files
committed
Adds account ID as a built-in endpoint parameter (#4016)
1 parent cfcfb6d commit 1aff970

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/model/rules/endpoints/BuiltInParameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum BuiltInParameter {
2323
AWS_USE_DUAL_STACK,
2424
AWS_USE_FIPS,
2525
SDK_ENDPOINT,
26+
AWS_AUTH_ACCOUNT_ID,
2627
AWS_STS_USE_GLOBAL_ENDPOINT,
2728
AWS_S3_FORCE_PATH_STYLE,
2829
AWS_S3_ACCELERATE,
@@ -43,6 +44,8 @@ public static BuiltInParameter fromValue(String s) {
4344
return AWS_USE_FIPS;
4445
case "sdk::endpoint":
4546
return SDK_ENDPOINT;
47+
case "aws::auth::accountid":
48+
return AWS_AUTH_ACCOUNT_ID;
4649
case "aws::sts::useglobalendpoint":
4750
return AWS_STS_USE_GLOBAL_ENDPOINT;
4851
case "aws::s3::forcepathstyle":

codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointResolverInterceptorSpec.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ private MethodSpec ruleParams() {
287287
case SDK_ENDPOINT:
288288
builtInFn = "endpointBuiltIn";
289289
break;
290+
case AWS_AUTH_ACCOUNT_ID:
291+
builtInFn = "accountIdBuiltIn";
292+
break;
290293
case AWS_S3_USE_GLOBAL_ENDPOINT:
291294
builtInFn = "useGlobalEndpointBuiltIn";
292295
break;

codegen/src/main/resources/software/amazon/awssdk/codegen/rules/AwsEndpointProviderUtils.java.resource

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public final class AwsEndpointProviderUtils {
3737
return executionAttributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED);
3838
}
3939

40+
public static String accountIdBuiltIn(ExecutionAttributes executionAttributes) {
41+
return executionAttributes.getAttribute(AwsExecutionAttribute.AWS_AUTH_ACCOUNT_ID);
42+
}
43+
4044
/**
4145
* Returns the endpoint set on the client. Note that this strips off the query part of the URI because the endpoint
4246
* rules library, e.g. {@code ParseURL} will return an exception if the URI it parses has query parameters.

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/query/endpoint-rule-set.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"type": "boolean",
1717
"builtIn": "AWS::UseFIPS"
1818
},
19+
"awsAccountId": {
20+
"type": "String",
21+
"builtIn": "AWS::Auth::AccountId"
22+
},
1923
"endpointId": {
2024
"type": "string"
2125
},

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/rules/endpoint-parameters.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public final class QueryEndpointParams implements ToCopyableBuilder<QueryEndpoin
1818

1919
private final Boolean useFIPSEndpoint;
2020

21+
private final String awsAccountId;
22+
2123
private final String endpointId;
2224

2325
private final Boolean defaultTrueParam;
@@ -36,6 +38,7 @@ private QueryEndpointParams(BuilderImpl builder) {
3638
this.region = builder.region;
3739
this.useDualStackEndpoint = builder.useDualStackEndpoint;
3840
this.useFIPSEndpoint = builder.useFIPSEndpoint;
41+
this.awsAccountId = builder.awsAccountId;
3942
this.endpointId = builder.endpointId;
4043
this.defaultTrueParam = builder.defaultTrueParam;
4144
this.defaultStringParam = builder.defaultStringParam;
@@ -61,6 +64,10 @@ public Boolean useFipsEndpoint() {
6164
return useFIPSEndpoint;
6265
}
6366

67+
public String awsAccountId() {
68+
return awsAccountId;
69+
}
70+
6471
public String endpointId() {
6572
return endpointId;
6673
}
@@ -101,6 +108,8 @@ public interface Builder extends CopyableBuilder<Builder, QueryEndpointParams> {
101108

102109
Builder useFipsEndpoint(Boolean useFIPSEndpoint);
103110

111+
Builder awsAccountId(String awsAccountId);
112+
104113
Builder endpointId(String endpointId);
105114

106115
Builder defaultTrueParam(Boolean defaultTrueParam);
@@ -126,6 +135,8 @@ private static class BuilderImpl implements Builder {
126135

127136
private Boolean useFIPSEndpoint;
128137

138+
private String awsAccountId;
139+
129140
private String endpointId;
130141

131142
private Boolean defaultTrueParam = true;
@@ -174,6 +185,12 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
174185
return this;
175186
}
176187

188+
@Override
189+
public Builder awsAccountId(String awsAccountId) {
190+
this.awsAccountId = awsAccountId;
191+
return this;
192+
}
193+
177194
@Override
178195
public Builder endpointId(String endpointId) {
179196
this.endpointId = endpointId;

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/rules/endpoint-provider-class.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ private static Map<Identifier, Value> toIdentifierValueMap(QueryEndpointParams p
5454
if (params.useFipsEndpoint() != null) {
5555
paramsMap.put(Identifier.of("useFIPSEndpoint"), Value.fromBool(params.useFipsEndpoint()));
5656
}
57+
if (params.awsAccountId() != null) {
58+
paramsMap.put(Identifier.of("awsAccountId"), Value.fromStr(params.awsAccountId()));
59+
}
5760
if (params.endpointId() != null) {
5861
paramsMap.put(Identifier.of("endpointId"), Value.fromStr(params.endpointId()));
5962
}
@@ -339,6 +342,9 @@ private static EndpointRuleset ruleSet() {
339342
.addParameter(
340343
Parameter.builder().name("useFIPSEndpoint").type(ParameterType.fromValue("boolean"))
341344
.required(false).builtIn("AWS::UseFIPS").build())
345+
.addParameter(
346+
Parameter.builder().name("awsAccountId").type(ParameterType.fromValue("String"))
347+
.required(false).builtIn("AWS::Auth::AccountId").build())
342348
.addParameter(
343349
Parameter.builder().name("endpointId").type(ParameterType.fromValue("string"))
344350
.required(false).build())

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/rules/endpoint-resolve-interceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static QueryEndpointParams ruleParams(SdkRequest request, ExecutionAttrib
9696
builder.region(AwsEndpointProviderUtils.regionBuiltIn(executionAttributes));
9797
builder.useDualStackEndpoint(AwsEndpointProviderUtils.dualStackEnabledBuiltIn(executionAttributes));
9898
builder.useFipsEndpoint(AwsEndpointProviderUtils.fipsEnabledBuiltIn(executionAttributes));
99+
builder.awsAccountId(AwsEndpointProviderUtils.accountIdBuiltIn(executionAttributes));
99100
setClientContextParams(builder, executionAttributes);
100101
setContextParams(builder, executionAttributes.getAttribute(AwsExecutionAttribute.OPERATION_NAME), request);
101102
setStaticContextParams(builder, executionAttributes.getAttribute(AwsExecutionAttribute.OPERATION_NAME));

core/aws-core/src/main/java/software/amazon/awssdk/awscore/AwsExecutionAttribute.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* AWS-specific attributes attached to the execution. This information is available to {@link ExecutionInterceptor}s.
2828
*/
2929
@SdkPublicApi
30-
public final class AwsExecutionAttribute extends SdkExecutionAttribute {
30+
public final class AwsExecutionAttribute extends SdkExecutionAttribute {
3131
/**
3232
* The AWS {@link Region} the client was configured with. This is not always same as the
3333
* {@link AwsSignerExecutionAttribute#SIGNING_REGION} for global services like IAM.
@@ -58,6 +58,12 @@ public final class AwsExecutionAttribute extends SdkExecutionAttribute {
5858
public static final ExecutionAttribute<Boolean> USE_GLOBAL_ENDPOINT =
5959
new ExecutionAttribute<>("UseGlobalEndpoint");
6060

61+
/**
62+
* The AWS account ID associated with the identity resolved for this request.
63+
*/
64+
public static final ExecutionAttribute<String> AWS_AUTH_ACCOUNT_ID =
65+
new ExecutionAttribute<>("AwsAuthAccountId");
66+
6167
private AwsExecutionAttribute() {
6268
}
6369
}

0 commit comments

Comments
 (0)