Skip to content

Commit 7436fdb

Browse files
authored
Configure codegen for account id endpoint tests (#5243)
* Configure codegen for account id endpoint tests * Add null check for params * Update codegen generated classes tests
1 parent 84a2d27 commit 7436fdb

File tree

17 files changed

+625
-591
lines changed

17 files changed

+625
-591
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private MethodSpec ruleParams() {
307307
setter, SdkInternalExecutionAttribute.class);
308308
break;
309309
case AWS_AUTH_ACCOUNT_ID_ENDPOINT_MODE:
310-
b.addStatement("builder.$N(executionAttributes.getAttribute($T.$N).name())",
310+
b.addStatement("builder.$N(executionAttributes.getAttribute($T.$N).name().toLowerCase())",
311311
setter, AwsExecutionAttribute.class,
312312
model.getNamingStrategy().getEnumValueName(m.getBuiltInEnum().name()));
313313
break;

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.junit.jupiter.params.ParameterizedTest;
4545
import org.junit.jupiter.params.provider.MethodSource;
4646
import org.mockito.Mockito;
47+
import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointMode;
4748
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4849
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
4950
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
@@ -275,7 +276,7 @@ private CodeBlock syncOperationCallLambda(OperationModel opModel, Map<String, Tr
275276

276277
b.beginControlFlow("() -> ");
277278
b.addStatement("$T builder = $T.builder()", syncClientBuilder(), syncClientClass());
278-
b.addStatement("builder.credentialsProvider($T.CREDENTIALS_PROVIDER)", BaseRuleSetClientTest.class);
279+
configureCredentialsProvider(b, params);
279280
if (AuthUtils.usesBearerAuth(model)) {
280281
b.addStatement("builder.tokenProvider($T.TOKEN_PROVIDER)", BaseRuleSetClientTest.class);
281282
}
@@ -302,7 +303,7 @@ private CodeBlock asyncOperationCallLambda(OperationModel opModel, Map<String, T
302303

303304
b.beginControlFlow("() -> ");
304305
b.addStatement("$T builder = $T.builder()", asyncClientBuilder(), asyncClientClass());
305-
b.addStatement("builder.credentialsProvider($T.CREDENTIALS_PROVIDER)", BaseRuleSetClientTest.class);
306+
configureCredentialsProvider(b, params);
306307
if (AuthUtils.usesBearerAuth(model)) {
307308
b.addStatement("builder.tokenProvider($T.TOKEN_PROVIDER)", BaseRuleSetClientTest.class);
308309
}
@@ -324,6 +325,16 @@ private CodeBlock asyncOperationCallLambda(OperationModel opModel, Map<String, T
324325
return b.build();
325326
}
326327

328+
private void configureCredentialsProvider(CodeBlock.Builder b, Map<String, TreeNode> params) {
329+
if (params != null && params.containsKey("AccountId")) {
330+
CodeBlock valueLiteral = endpointRulesSpecUtils.treeNodeToLiteral(params.get("AccountId"));
331+
b.addStatement("builder.credentialsProvider($T.credentialsProviderWithAccountId($L))", BaseRuleSetClientTest.class,
332+
valueLiteral);
333+
} else {
334+
b.addStatement("builder.credentialsProvider($T.CREDENTIALS_PROVIDER)", BaseRuleSetClientTest.class);
335+
}
336+
}
337+
327338
private CodeBlock syncOperationInvocation(OperationModel opModel) {
328339
CodeBlock.Builder b = CodeBlock.builder();
329340

@@ -598,6 +609,10 @@ private CodeBlock setClientParams(String builderName, Map<String, TreeNode> para
598609
b.addStatement("$T.setProperty($L, $L ? \"global\" : \"regional\")", System.class,
599610
s3RegionalEndpointSystemPropertyCode(), valueLiteral);
600611
break;
612+
case AWS_AUTH_ACCOUNT_ID_ENDPOINT_MODE:
613+
b.addStatement("$N.accountIdEndpointMode($T.fromValue($L))", builderName, AccountIdEndpointMode.class,
614+
valueLiteral);
615+
break;
601616
default:
602617
break;
603618
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-default-params-without-allowlist.java

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/*
2-
* Copyright 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-
161
package software.amazon.awssdk.services.query.auth.scheme.internal;
172

183
import java.util.Arrays;
@@ -35,10 +20,9 @@ public final class DefaultQueryAuthSchemeParams implements QueryAuthSchemeParams
3520

3621
private final Boolean useFIPSEndpoint;
3722

38-
private final String awsAccountId;
39-
23+
private final String accountId;
4024

41-
private final String awsAccountIdEndpointMode;
25+
private final String accountIdEndpointMode;
4226

4327
private final List<String> listOfStrings;
4428

@@ -65,8 +49,8 @@ private DefaultQueryAuthSchemeParams(Builder builder) {
6549
this.region = builder.region;
6650
this.useDualStackEndpoint = builder.useDualStackEndpoint;
6751
this.useFIPSEndpoint = builder.useFIPSEndpoint;
68-
this.awsAccountId = builder.awsAccountId;
69-
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
52+
this.accountId = builder.accountId;
53+
this.accountIdEndpointMode = builder.accountIdEndpointMode;
7054
this.listOfStrings = builder.listOfStrings;
7155
this.defaultListOfStrings = Validate.paramNotNull(builder.defaultListOfStrings, "defaultListOfStrings");
7256
this.endpointId = builder.endpointId;
@@ -104,13 +88,13 @@ public Boolean useFipsEndpoint() {
10488
}
10589

10690
@Override
107-
public String awsAccountId() {
108-
return awsAccountId;
91+
public String accountId() {
92+
return accountId;
10993
}
11094

11195
@Override
112-
public String awsAccountIdEndpointMode() {
113-
return awsAccountIdEndpointMode;
96+
public String accountIdEndpointMode() {
97+
return accountIdEndpointMode;
11498
}
11599

116100
@Override
@@ -178,9 +162,9 @@ private static final class Builder implements QueryAuthSchemeParams.Builder, Que
178162

179163
private Boolean useFIPSEndpoint;
180164

181-
private String awsAccountId;
165+
private String accountId;
182166

183-
private String awsAccountIdEndpointMode;
167+
private String accountIdEndpointMode;
184168

185169
private List<String> listOfStrings;
186170

@@ -210,8 +194,8 @@ private static final class Builder implements QueryAuthSchemeParams.Builder, Que
210194
this.region = params.region;
211195
this.useDualStackEndpoint = params.useDualStackEndpoint;
212196
this.useFIPSEndpoint = params.useFIPSEndpoint;
213-
this.awsAccountId = params.awsAccountId;
214-
this.awsAccountIdEndpointMode = params.awsAccountIdEndpointMode;
197+
this.accountId = params.accountId;
198+
this.accountIdEndpointMode = params.accountIdEndpointMode;
215199
this.listOfStrings = params.listOfStrings;
216200
this.defaultListOfStrings = params.defaultListOfStrings;
217201
this.endpointId = params.endpointId;
@@ -249,14 +233,14 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
249233
}
250234

251235
@Override
252-
public Builder awsAccountId(String awsAccountId) {
253-
this.awsAccountId = awsAccountId;
236+
public Builder accountId(String accountId) {
237+
this.accountId = accountId;
254238
return this;
255239
}
256240

257241
@Override
258-
public Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode) {
259-
this.awsAccountIdEndpointMode = awsAccountIdEndpointMode;
242+
public Builder accountIdEndpointMode(String accountIdEndpointMode) {
243+
this.accountIdEndpointMode = accountIdEndpointMode;
260244
return this;
261245
}
262246

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-endpoint-provider-without-allowlist.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static QueryAuthSchemeProvider create() {
4343
public List<AuthSchemeOption> resolveAuthScheme(QueryAuthSchemeParams params) {
4444
QueryEndpointParams endpointParameters = QueryEndpointParams.builder().region(params.region())
4545
.useDualStackEndpoint(params.useDualStackEndpoint()).useFipsEndpoint(params.useFipsEndpoint())
46-
.awsAccountId(params.awsAccountId()).awsAccountIdEndpointMode(params.awsAccountIdEndpointMode())
46+
.accountId(params.accountId()).accountIdEndpointMode(params.accountIdEndpointMode())
4747
.listOfStrings(params.listOfStrings()).defaultListOfStrings(params.defaultListOfStrings())
4848
.endpointId(params.endpointId()).defaultTrueParam(params.defaultTrueParam())
4949
.defaultStringParam(params.defaultStringParam()).deprecatedParam(params.deprecatedParam())

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-params-without-allowlist.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/*
2-
* Copyright 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-
161
package software.amazon.awssdk.services.query.auth.scheme;
172

183
import java.util.List;
@@ -50,9 +35,9 @@ static Builder builder() {
5035

5136
Boolean useFipsEndpoint();
5237

53-
String awsAccountId();
38+
String accountId();
5439

55-
String awsAccountIdEndpointMode();
40+
String accountIdEndpointMode();
5641

5742
List<String> listOfStrings();
5843

@@ -99,9 +84,9 @@ interface Builder extends CopyableBuilder<Builder, QueryAuthSchemeParams> {
9984

10085
Builder useFipsEndpoint(Boolean useFIPSEndpoint);
10186

102-
Builder awsAccountId(String awsAccountId);
87+
Builder accountId(String accountId);
10388

104-
Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode);
89+
Builder accountIdEndpointMode(String accountIdEndpointMode);
10590

10691
Builder listOfStrings(List<String> listOfStrings);
10792

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-without-allowlist-auth-scheme-interceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ private QueryAuthSchemeParams authSchemeParams(SdkRequest request, ExecutionAttr
9090
builder.region(endpointParams.region());
9191
builder.useDualStackEndpoint(endpointParams.useDualStackEndpoint());
9292
builder.useFipsEndpoint(endpointParams.useFipsEndpoint());
93-
builder.awsAccountId(endpointParams.awsAccountId());
94-
builder.awsAccountIdEndpointMode(endpointParams.awsAccountIdEndpointMode());
93+
builder.accountId(endpointParams.accountId());
94+
builder.accountIdEndpointMode(endpointParams.accountIdEndpointMode());
9595
builder.listOfStrings(endpointParams.listOfStrings());
9696
builder.defaultListOfStrings(endpointParams.defaultListOfStrings());
9797
builder.endpointId(endpointParams.endpointId());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"type": "boolean",
1717
"builtIn": "AWS::UseFIPS"
1818
},
19-
"awsAccountId": {
19+
"AccountId": {
2020
"type": "String",
2121
"builtIn": "AWS::Auth::AccountId"
2222
},
23-
"awsAccountIdEndpointMode": {
23+
"AccountIdEndpointMode": {
2424
"type": "String",
2525
"builtIn": "AWS::Auth::AccountIdEndpointMode"
2626
},

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@
6262
}
6363
}
6464
},
65+
{
66+
"documentation": "test case 5",
67+
"operationInputs": [
68+
{
69+
"operationName": "OperationWithContextParam",
70+
"operationParams": {
71+
"StringMember": "this is a test with AccountId and AccountIdEndpointMode"
72+
},
73+
"builtInParams": {
74+
"AWS::Region": "us-east-5",
75+
"AWS::Auth::AccountId": "012345678901",
76+
"AWS::Auth::AccountIdEndpointMode": "required"
77+
}
78+
}
79+
],
80+
"params": {
81+
"Region": "us-east-5",
82+
"AccountId": "012345678901",
83+
"AccountIdEndpointMode": "required"
84+
},
85+
"expect": {
86+
"endpoint": {
87+
"url": "https://012345678901.myservice.aws"
88+
}
89+
}
90+
},
6591
{
6692
"documentation": "For region us-iso-west-1 with FIPS enabled and DualStack enabled",
6793
"expect": {

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ public final class QueryEndpointParams implements ToCopyableBuilder<QueryEndpoin
2020

2121
private final Boolean useFIPSEndpoint;
2222

23-
private final String awsAccountId;
23+
private final String accountId;
2424

25-
26-
private final String awsAccountIdEndpointMode;
25+
private final String accountIdEndpointMode;
2726

2827
private final List<String> listOfStrings;
2928

@@ -44,12 +43,13 @@ public final class QueryEndpointParams implements ToCopyableBuilder<QueryEndpoin
4443
private final String operationContextParam;
4544

4645
private final List<String> customEndpointArray;
46+
4747
private QueryEndpointParams(BuilderImpl builder) {
4848
this.region = builder.region;
4949
this.useDualStackEndpoint = builder.useDualStackEndpoint;
5050
this.useFIPSEndpoint = builder.useFIPSEndpoint;
51-
this.awsAccountId = builder.awsAccountId;
52-
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
51+
this.accountId = builder.accountId;
52+
this.accountIdEndpointMode = builder.accountIdEndpointMode;
5353
this.listOfStrings = builder.listOfStrings;
5454
this.defaultListOfStrings = builder.defaultListOfStrings;
5555
this.endpointId = builder.endpointId;
@@ -78,12 +78,12 @@ public Boolean useFipsEndpoint() {
7878
return useFIPSEndpoint;
7979
}
8080

81-
public String awsAccountId() {
82-
return awsAccountId;
81+
public String accountId() {
82+
return accountId;
8383
}
8484

85-
public String awsAccountIdEndpointMode() {
86-
return awsAccountIdEndpointMode;
85+
public String accountIdEndpointMode() {
86+
return accountIdEndpointMode;
8787
}
8888

8989
public List<String> listOfStrings() {
@@ -138,9 +138,9 @@ public interface Builder extends CopyableBuilder<Builder, QueryEndpointParams> {
138138

139139
Builder useFipsEndpoint(Boolean useFIPSEndpoint);
140140

141-
Builder awsAccountId(String awsAccountId);
141+
Builder accountId(String accountId);
142142

143-
Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode);
143+
Builder accountIdEndpointMode(String accountIdEndpointMode);
144144

145145
Builder listOfStrings(List<String> listOfStrings);
146146

@@ -173,9 +173,9 @@ private static class BuilderImpl implements Builder {
173173

174174
private Boolean useFIPSEndpoint;
175175

176-
private String awsAccountId;
176+
private String accountId;
177177

178-
private String awsAccountIdEndpointMode;
178+
private String accountIdEndpointMode;
179179

180180
private List<String> listOfStrings;
181181

@@ -204,8 +204,8 @@ private BuilderImpl(QueryEndpointParams builder) {
204204
this.region = builder.region;
205205
this.useDualStackEndpoint = builder.useDualStackEndpoint;
206206
this.useFIPSEndpoint = builder.useFIPSEndpoint;
207-
this.awsAccountId = builder.awsAccountId;
208-
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
207+
this.accountId = builder.accountId;
208+
this.accountIdEndpointMode = builder.accountIdEndpointMode;
209209
this.listOfStrings = builder.listOfStrings;
210210
this.defaultListOfStrings = builder.defaultListOfStrings;
211211
this.endpointId = builder.endpointId;
@@ -216,7 +216,6 @@ private BuilderImpl(QueryEndpointParams builder) {
216216
this.stringContextParam = builder.stringContextParam;
217217
this.operationContextParam = builder.operationContextParam;
218218
this.customEndpointArray = builder.customEndpointArray;
219-
220219
}
221220

222221
@Override
@@ -238,14 +237,14 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
238237
}
239238

240239
@Override
241-
public Builder awsAccountId(String awsAccountId) {
242-
this.awsAccountId = awsAccountId;
240+
public Builder accountId(String accountId) {
241+
this.accountId = accountId;
243242
return this;
244243
}
245244

246245
@Override
247-
public Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode) {
248-
this.awsAccountIdEndpointMode = awsAccountIdEndpointMode;
246+
public Builder accountIdEndpointMode(String accountIdEndpointMode) {
247+
this.accountIdEndpointMode = accountIdEndpointMode;
249248
return this;
250249
}
251250

0 commit comments

Comments
 (0)