Skip to content

Configure codegen for account id endpoint tests #5243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private MethodSpec ruleParams() {
setter, SdkInternalExecutionAttribute.class);
break;
case AWS_AUTH_ACCOUNT_ID_ENDPOINT_MODE:
b.addStatement("builder.$N(executionAttributes.getAttribute($T.$N).name())",
b.addStatement("builder.$N(executionAttributes.getAttribute($T.$N).name().toLowerCase())",
setter, AwsExecutionAttribute.class,
model.getNamingStrategy().getEnumValueName(m.getBuiltInEnum().name()));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import software.amazon.awssdk.awscore.endpoints.AccountIdEndpointMode;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
Expand Down Expand Up @@ -275,7 +276,7 @@ private CodeBlock syncOperationCallLambda(OperationModel opModel, Map<String, Tr

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

b.beginControlFlow("() -> ");
b.addStatement("$T builder = $T.builder()", asyncClientBuilder(), asyncClientClass());
b.addStatement("builder.credentialsProvider($T.CREDENTIALS_PROVIDER)", BaseRuleSetClientTest.class);
configureCredentialsProvider(b, params);
if (AuthUtils.usesBearerAuth(model)) {
b.addStatement("builder.tokenProvider($T.TOKEN_PROVIDER)", BaseRuleSetClientTest.class);
}
Expand All @@ -324,6 +325,16 @@ private CodeBlock asyncOperationCallLambda(OperationModel opModel, Map<String, T
return b.build();
}

private void configureCredentialsProvider(CodeBlock.Builder b, Map<String, TreeNode> params) {
if (params != null && params.containsKey("AccountId")) {
CodeBlock valueLiteral = endpointRulesSpecUtils.treeNodeToLiteral(params.get("AccountId"));
b.addStatement("builder.credentialsProvider($T.credentialsProviderWithAccountId($L))", BaseRuleSetClientTest.class,
valueLiteral);
} else {
b.addStatement("builder.credentialsProvider($T.CREDENTIALS_PROVIDER)", BaseRuleSetClientTest.class);
}
}

private CodeBlock syncOperationInvocation(OperationModel opModel) {
CodeBlock.Builder b = CodeBlock.builder();

Expand Down Expand Up @@ -598,6 +609,10 @@ private CodeBlock setClientParams(String builderName, Map<String, TreeNode> para
b.addStatement("$T.setProperty($L, $L ? \"global\" : \"regional\")", System.class,
s3RegionalEndpointSystemPropertyCode(), valueLiteral);
break;
case AWS_AUTH_ACCOUNT_ID_ENDPOINT_MODE:
b.addStatement("$N.accountIdEndpointMode($T.fromValue($L))", builderName, AccountIdEndpointMode.class,
valueLiteral);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.services.query.auth.scheme.internal;

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

private final Boolean useFIPSEndpoint;

private final String awsAccountId;

private final String accountId;

private final String awsAccountIdEndpointMode;
private final String accountIdEndpointMode;

private final List<String> listOfStrings;

Expand All @@ -65,8 +49,8 @@ private DefaultQueryAuthSchemeParams(Builder builder) {
this.region = builder.region;
this.useDualStackEndpoint = builder.useDualStackEndpoint;
this.useFIPSEndpoint = builder.useFIPSEndpoint;
this.awsAccountId = builder.awsAccountId;
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
this.accountId = builder.accountId;
this.accountIdEndpointMode = builder.accountIdEndpointMode;
this.listOfStrings = builder.listOfStrings;
this.defaultListOfStrings = Validate.paramNotNull(builder.defaultListOfStrings, "defaultListOfStrings");
this.endpointId = builder.endpointId;
Expand Down Expand Up @@ -104,13 +88,13 @@ public Boolean useFipsEndpoint() {
}

@Override
public String awsAccountId() {
return awsAccountId;
public String accountId() {
return accountId;
}

@Override
public String awsAccountIdEndpointMode() {
return awsAccountIdEndpointMode;
public String accountIdEndpointMode() {
return accountIdEndpointMode;
}

@Override
Expand Down Expand Up @@ -178,9 +162,9 @@ private static final class Builder implements QueryAuthSchemeParams.Builder, Que

private Boolean useFIPSEndpoint;

private String awsAccountId;
private String accountId;

private String awsAccountIdEndpointMode;
private String accountIdEndpointMode;

private List<String> listOfStrings;

Expand Down Expand Up @@ -210,8 +194,8 @@ private static final class Builder implements QueryAuthSchemeParams.Builder, Que
this.region = params.region;
this.useDualStackEndpoint = params.useDualStackEndpoint;
this.useFIPSEndpoint = params.useFIPSEndpoint;
this.awsAccountId = params.awsAccountId;
this.awsAccountIdEndpointMode = params.awsAccountIdEndpointMode;
this.accountId = params.accountId;
this.accountIdEndpointMode = params.accountIdEndpointMode;
this.listOfStrings = params.listOfStrings;
this.defaultListOfStrings = params.defaultListOfStrings;
this.endpointId = params.endpointId;
Expand Down Expand Up @@ -249,14 +233,14 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
}

@Override
public Builder awsAccountId(String awsAccountId) {
this.awsAccountId = awsAccountId;
public Builder accountId(String accountId) {
this.accountId = accountId;
return this;
}

@Override
public Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode) {
this.awsAccountIdEndpointMode = awsAccountIdEndpointMode;
public Builder accountIdEndpointMode(String accountIdEndpointMode) {
this.accountIdEndpointMode = accountIdEndpointMode;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static QueryAuthSchemeProvider create() {
public List<AuthSchemeOption> resolveAuthScheme(QueryAuthSchemeParams params) {
QueryEndpointParams endpointParameters = QueryEndpointParams.builder().region(params.region())
.useDualStackEndpoint(params.useDualStackEndpoint()).useFipsEndpoint(params.useFipsEndpoint())
.awsAccountId(params.awsAccountId()).awsAccountIdEndpointMode(params.awsAccountIdEndpointMode())
.accountId(params.accountId()).accountIdEndpointMode(params.accountIdEndpointMode())
.listOfStrings(params.listOfStrings()).defaultListOfStrings(params.defaultListOfStrings())
.endpointId(params.endpointId()).defaultTrueParam(params.defaultTrueParam())
.defaultStringParam(params.defaultStringParam()).deprecatedParam(params.deprecatedParam())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.services.query.auth.scheme;

import java.util.List;
Expand Down Expand Up @@ -50,9 +35,9 @@ static Builder builder() {

Boolean useFipsEndpoint();

String awsAccountId();
String accountId();

String awsAccountIdEndpointMode();
String accountIdEndpointMode();

List<String> listOfStrings();

Expand Down Expand Up @@ -99,9 +84,9 @@ interface Builder extends CopyableBuilder<Builder, QueryAuthSchemeParams> {

Builder useFipsEndpoint(Boolean useFIPSEndpoint);

Builder awsAccountId(String awsAccountId);
Builder accountId(String accountId);

Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode);
Builder accountIdEndpointMode(String accountIdEndpointMode);

Builder listOfStrings(List<String> listOfStrings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private QueryAuthSchemeParams authSchemeParams(SdkRequest request, ExecutionAttr
builder.region(endpointParams.region());
builder.useDualStackEndpoint(endpointParams.useDualStackEndpoint());
builder.useFipsEndpoint(endpointParams.useFipsEndpoint());
builder.awsAccountId(endpointParams.awsAccountId());
builder.awsAccountIdEndpointMode(endpointParams.awsAccountIdEndpointMode());
builder.accountId(endpointParams.accountId());
builder.accountIdEndpointMode(endpointParams.accountIdEndpointMode());
builder.listOfStrings(endpointParams.listOfStrings());
builder.defaultListOfStrings(endpointParams.defaultListOfStrings());
builder.endpointId(endpointParams.endpointId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"type": "boolean",
"builtIn": "AWS::UseFIPS"
},
"awsAccountId": {
"AccountId": {
"type": "String",
"builtIn": "AWS::Auth::AccountId"
},
"awsAccountIdEndpointMode": {
"AccountIdEndpointMode": {
"type": "String",
"builtIn": "AWS::Auth::AccountIdEndpointMode"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@
}
}
},
{
"documentation": "test case 5",
"operationInputs": [
{
"operationName": "OperationWithContextParam",
"operationParams": {
"StringMember": "this is a test with AccountId and AccountIdEndpointMode"
},
"builtInParams": {
"AWS::Region": "us-east-5",
"AWS::Auth::AccountId": "012345678901",
"AWS::Auth::AccountIdEndpointMode": "required"
}
}
],
"params": {
"Region": "us-east-5",
"AccountId": "012345678901",
"AccountIdEndpointMode": "required"
},
"expect": {
"endpoint": {
"url": "https://012345678901.myservice.aws"
}
}
},
{
"documentation": "For region us-iso-west-1 with FIPS enabled and DualStack enabled",
"expect": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ public final class QueryEndpointParams implements ToCopyableBuilder<QueryEndpoin

private final Boolean useFIPSEndpoint;

private final String awsAccountId;
private final String accountId;


private final String awsAccountIdEndpointMode;
private final String accountIdEndpointMode;

private final List<String> listOfStrings;

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

private final List<String> customEndpointArray;

private QueryEndpointParams(BuilderImpl builder) {
this.region = builder.region;
this.useDualStackEndpoint = builder.useDualStackEndpoint;
this.useFIPSEndpoint = builder.useFIPSEndpoint;
this.awsAccountId = builder.awsAccountId;
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
this.accountId = builder.accountId;
this.accountIdEndpointMode = builder.accountIdEndpointMode;
this.listOfStrings = builder.listOfStrings;
this.defaultListOfStrings = builder.defaultListOfStrings;
this.endpointId = builder.endpointId;
Expand Down Expand Up @@ -78,12 +78,12 @@ public Boolean useFipsEndpoint() {
return useFIPSEndpoint;
}

public String awsAccountId() {
return awsAccountId;
public String accountId() {
return accountId;
}

public String awsAccountIdEndpointMode() {
return awsAccountIdEndpointMode;
public String accountIdEndpointMode() {
return accountIdEndpointMode;
}

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

Builder useFipsEndpoint(Boolean useFIPSEndpoint);

Builder awsAccountId(String awsAccountId);
Builder accountId(String accountId);

Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode);
Builder accountIdEndpointMode(String accountIdEndpointMode);

Builder listOfStrings(List<String> listOfStrings);

Expand Down Expand Up @@ -173,9 +173,9 @@ private static class BuilderImpl implements Builder {

private Boolean useFIPSEndpoint;

private String awsAccountId;
private String accountId;

private String awsAccountIdEndpointMode;
private String accountIdEndpointMode;

private List<String> listOfStrings;

Expand Down Expand Up @@ -204,8 +204,8 @@ private BuilderImpl(QueryEndpointParams builder) {
this.region = builder.region;
this.useDualStackEndpoint = builder.useDualStackEndpoint;
this.useFIPSEndpoint = builder.useFIPSEndpoint;
this.awsAccountId = builder.awsAccountId;
this.awsAccountIdEndpointMode = builder.awsAccountIdEndpointMode;
this.accountId = builder.accountId;
this.accountIdEndpointMode = builder.accountIdEndpointMode;
this.listOfStrings = builder.listOfStrings;
this.defaultListOfStrings = builder.defaultListOfStrings;
this.endpointId = builder.endpointId;
Expand All @@ -216,7 +216,6 @@ private BuilderImpl(QueryEndpointParams builder) {
this.stringContextParam = builder.stringContextParam;
this.operationContextParam = builder.operationContextParam;
this.customEndpointArray = builder.customEndpointArray;

}

@Override
Expand All @@ -238,14 +237,14 @@ public Builder useFipsEndpoint(Boolean useFIPSEndpoint) {
}

@Override
public Builder awsAccountId(String awsAccountId) {
this.awsAccountId = awsAccountId;
public Builder accountId(String accountId) {
this.accountId = accountId;
return this;
}

@Override
public Builder awsAccountIdEndpointMode(String awsAccountIdEndpointMode) {
this.awsAccountIdEndpointMode = awsAccountIdEndpointMode;
public Builder accountIdEndpointMode(String accountIdEndpointMode) {
this.accountIdEndpointMode = accountIdEndpointMode;
return this;
}

Expand Down
Loading
Loading