Skip to content

Commit fedae5a

Browse files
authored
Adds account ID as a built-in endpoint parameter (#4016)
1 parent 64d5212 commit fedae5a

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
@@ -170,6 +170,9 @@ private MethodSpec ruleParams() {
170170
case SDK_ENDPOINT:
171171
builtInFn = "endpointBuiltIn";
172172
break;
173+
case AWS_AUTH_ACCOUNT_ID:
174+
builtInFn = "accountIdBuiltIn";
175+
break;
173176
case AWS_S3_USE_GLOBAL_ENDPOINT:
174177
builtInFn = "useGlobalEndpointBuiltIn";
175178
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
@@ -40,6 +40,10 @@ public final class AwsEndpointProviderUtils {
4040
return executionAttributes.getAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED);
4141
}
4242

43+
public static String accountIdBuiltIn(ExecutionAttributes executionAttributes) {
44+
return executionAttributes.getAttribute(AwsExecutionAttribute.AWS_AUTH_ACCOUNT_ID);
45+
}
46+
4347
/**
4448
* Returns the endpoint set on the client. Note that this strips off the query part of the URI because the endpoint
4549
* 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
@@ -16,6 +16,8 @@ public final class QueryEndpointParams {
1616

1717
private final Boolean useFIPSEndpoint;
1818

19+
private final String awsAccountId;
20+
1921
private final String endpointId;
2022

2123
private final Boolean defaultTrueParam;
@@ -34,6 +36,7 @@ private QueryEndpointParams(BuilderImpl builder) {
3436
this.region = builder.region;
3537
this.useDualStackEndpoint = builder.useDualStackEndpoint;
3638
this.useFIPSEndpoint = builder.useFIPSEndpoint;
39+
this.awsAccountId = builder.awsAccountId;
3740
this.endpointId = builder.endpointId;
3841
this.defaultTrueParam = builder.defaultTrueParam;
3942
this.defaultStringParam = builder.defaultStringParam;
@@ -59,6 +62,10 @@ public Boolean useFipsEndpoint() {
5962
return useFIPSEndpoint;
6063
}
6164

65+
public String awsAccountId() {
66+
return awsAccountId;
67+
}
68+
6269
public String endpointId() {
6370
return endpointId;
6471
}
@@ -95,6 +102,8 @@ public interface Builder {
95102

96103
Builder useFipsEndpoint(Boolean useFIPSEndpoint);
97104

105+
Builder awsAccountId(String awsAccountId);
106+
98107
Builder endpointId(String endpointId);
99108

100109
Builder defaultTrueParam(Boolean defaultTrueParam);
@@ -120,6 +129,8 @@ private static class BuilderImpl implements Builder {
120129

121130
private Boolean useFIPSEndpoint;
122131

132+
private String awsAccountId;
133+
123134
private String endpointId;
124135

125136
private Boolean defaultTrueParam = true;
@@ -152,6 +163,12 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
152163
return this;
153164
}
154165

166+
@Override
167+
public Builder awsAccountId(String awsAccountId) {
168+
this.awsAccountId = awsAccountId;
169+
return this;
170+
}
171+
155172
@Override
156173
public Builder endpointId(String endpointId) {
157174
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
@@ -38,6 +38,9 @@ private static Map<Identifier, Value> toIdentifierValueMap(QueryEndpointParams p
3838
if (params.useFipsEndpoint() != null) {
3939
paramsMap.put(Identifier.of("useFIPSEndpoint"), Value.fromBool(params.useFipsEndpoint()));
4040
}
41+
if (params.awsAccountId() != null) {
42+
paramsMap.put(Identifier.of("awsAccountId"), Value.fromStr(params.awsAccountId()));
43+
}
4144
if (params.endpointId() != null) {
4245
paramsMap.put(Identifier.of("endpointId"), Value.fromStr(params.endpointId()));
4346
}
@@ -297,6 +300,9 @@ private static EndpointRuleset ruleSet() {
297300
.addParameter(
298301
Parameter.builder().name("useFIPSEndpoint").type(ParameterType.fromValue("boolean"))
299302
.required(false).builtIn("AWS::UseFIPS").build())
303+
.addParameter(
304+
Parameter.builder().name("awsAccountId").type(ParameterType.fromValue("String"))
305+
.required(false).builtIn("AWS::Auth::AccountId").build())
300306
.addParameter(
301307
Parameter.builder().name("endpointId").type(ParameterType.fromValue("string"))
302308
.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
@@ -55,6 +55,7 @@ private static QueryEndpointParams ruleParams(Context.ModifyRequest context, Exe
5555
builder.region(AwsEndpointProviderUtils.regionBuiltIn(executionAttributes));
5656
builder.useDualStackEndpoint(AwsEndpointProviderUtils.dualStackEnabledBuiltIn(executionAttributes));
5757
builder.useFipsEndpoint(AwsEndpointProviderUtils.fipsEnabledBuiltIn(executionAttributes));
58+
builder.awsAccountId(AwsEndpointProviderUtils.accountIdBuiltIn(executionAttributes));
5859
setClientContextParams(builder, executionAttributes);
5960
setContextParams(builder, executionAttributes.getAttribute(AwsExecutionAttribute.OPERATION_NAME), context.request());
6061
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)