Skip to content

Commit 6144c8a

Browse files
authored
Remove obsolete useSra customization config (#6476)
1 parent ce459f7 commit 6144c8a

File tree

34 files changed

+142
-12045
lines changed

34 files changed

+142
-12045
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "removal",
3+
"category": "AWS SDK for Java v2 Codegenerator",
4+
"contributor": "",
5+
"description": "Remove `useSraAuth` setting from customization config."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ public class CustomizationConfig {
287287
*/
288288
private boolean requiredTraitValidationEnabled = false;
289289

290-
/**
291-
* Whether SRA based auth logic should be used.
292-
*/
293-
private boolean useSraAuth = true;
294-
295290
/**
296291
* Whether to generate auth scheme params based on endpoint params.
297292
*/
@@ -834,16 +829,6 @@ public void setRequiredTraitValidationEnabled(boolean requiredTraitValidationEna
834829
this.requiredTraitValidationEnabled = requiredTraitValidationEnabled;
835830
}
836831

837-
public void setUseSraAuth(boolean useSraAuth) {
838-
this.useSraAuth = useSraAuth;
839-
}
840-
841-
// TODO(post-sra-identity-auth): Remove this customization and all related switching logic, keeping only the
842-
// useSraAuth==true branch going forward.
843-
public boolean useSraAuth() {
844-
return useSraAuth;
845-
}
846-
847832
public void setEnableEndpointAuthSchemeParams(boolean enableEndpointAuthSchemeParams) {
848833
this.enableEndpointAuthSchemeParams = enableEndpointAuthSchemeParams;
849834
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecUtils.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@
3131
public final class AuthSchemeSpecUtils {
3232
private static final Set<String> DEFAULT_AUTH_SCHEME_PARAMS = setOf("region", "operation");
3333
private final IntermediateModel intermediateModel;
34-
private final boolean useSraAuth;
3534
private final Set<String> allowedEndpointAuthSchemeParams;
3635
private final boolean allowedEndpointAuthSchemeParamsConfigured;
3736

3837
public AuthSchemeSpecUtils(IntermediateModel intermediateModel) {
3938
this.intermediateModel = intermediateModel;
4039
CustomizationConfig customization = intermediateModel.getCustomizationConfig();
41-
this.useSraAuth = customization.useSraAuth();
4240
if (customization.getAllowedEndpointAuthSchemeParamsConfigured()) {
4341
this.allowedEndpointAuthSchemeParams = Collections.unmodifiableSet(
4442
new HashSet<>(customization.getAllowedEndpointAuthSchemeParams()));
@@ -49,10 +47,6 @@ public AuthSchemeSpecUtils(IntermediateModel intermediateModel) {
4947
}
5048
}
5149

52-
public boolean useSraAuth() {
53-
return useSraAuth;
54-
}
55-
5650
private String basePackage() {
5751
return intermediateModel.getMetadata().getFullAuthSchemePackageName();
5852
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 15 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@
4040
import javax.lang.model.element.Modifier;
4141
import software.amazon.awssdk.annotations.SdkInternalApi;
4242
import software.amazon.awssdk.auth.credentials.TokenUtils;
43-
import software.amazon.awssdk.auth.signer.Aws4Signer;
4443
import software.amazon.awssdk.auth.token.credentials.StaticTokenProvider;
4544
import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider;
46-
import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner;
4745
import software.amazon.awssdk.awscore.auth.AuthSchemePreferenceResolver;
4846
import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder;
4947
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
5048
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider;
5149
import software.amazon.awssdk.codegen.internal.Utils;
5250
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
5351
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
54-
import software.amazon.awssdk.codegen.model.service.AuthType;
5552
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
5653
import software.amazon.awssdk.codegen.poet.ClassSpec;
5754
import software.amazon.awssdk.codegen.poet.PoetExtension;
@@ -72,7 +69,6 @@
7269
import software.amazon.awssdk.core.checksums.RequestChecksumCalculationResolver;
7370
import software.amazon.awssdk.core.checksums.ResponseChecksumValidation;
7471
import software.amazon.awssdk.core.checksums.ResponseChecksumValidationResolver;
75-
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
7672
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
7773
import software.amazon.awssdk.core.client.config.SdkClientOption;
7874
import software.amazon.awssdk.core.endpointdiscovery.providers.DefaultEndpointDiscoveryProviderChain;
@@ -81,7 +77,6 @@
8177
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
8278
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
8379
import software.amazon.awssdk.core.retry.RetryMode;
84-
import software.amazon.awssdk.core.signer.Signer;
8580
import software.amazon.awssdk.http.Protocol;
8681
import software.amazon.awssdk.http.ProtocolNegotiation;
8782
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
@@ -147,15 +142,13 @@ public TypeSpec poetSpec() {
147142
.build());
148143
}
149144

150-
if (authSchemeSpecUtils.useSraAuth()) {
151-
builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class),
152-
ClassName.get(String.class),
153-
GENERIC_AUTH_SCHEME_TYPE),
154-
"additionalAuthSchemes")
155-
.addModifiers(PRIVATE, FINAL)
156-
.initializer("new $T<>()", HashMap.class)
157-
.build());
158-
}
145+
builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class),
146+
ClassName.get(String.class),
147+
GENERIC_AUTH_SCHEME_TYPE),
148+
"additionalAuthSchemes")
149+
.addModifiers(PRIVATE, FINAL)
150+
.initializer("new $T<>()", HashMap.class)
151+
.build());
159152

160153
builder.addMethod(serviceEndpointPrefixMethod());
161154
builder.addMethod(serviceNameMethod());
@@ -164,18 +157,13 @@ public TypeSpec poetSpec() {
164157
mergeInternalDefaultsMethod().ifPresent(builder::addMethod);
165158

166159
builder.addMethod(finalizeServiceConfigurationMethod());
167-
if (!authSchemeSpecUtils.useSraAuth()) {
168-
defaultAwsAuthSignerMethod().ifPresent(builder::addMethod);
169-
}
170160
builder.addMethod(signingNameMethod());
171161
builder.addMethod(defaultEndpointProviderMethod());
172162

173-
if (authSchemeSpecUtils.useSraAuth()) {
174-
builder.addMethod(authSchemeProviderMethod());
175-
builder.addMethod(defaultAuthSchemeProviderMethod());
176-
builder.addMethod(putAuthSchemeMethod());
177-
builder.addMethod(authSchemesMethod());
178-
}
163+
builder.addMethod(authSchemeProviderMethod());
164+
builder.addMethod(defaultAuthSchemeProviderMethod());
165+
builder.addMethod(putAuthSchemeMethod());
166+
builder.addMethod(authSchemesMethod());
179167

180168
if (hasRequestAlgorithmMember(model)) {
181169
builder.addMethod(requestChecksumCalculationMethod());
@@ -206,9 +194,6 @@ public TypeSpec poetSpec() {
206194

207195
if (AuthUtils.usesBearerAuth(model)) {
208196
builder.addMethod(defaultBearerTokenProviderMethod());
209-
if (!authSchemeSpecUtils.useSraAuth()) {
210-
builder.addMethod(defaultTokenAuthSignerMethod());
211-
}
212197
}
213198
addServiceHttpConfigIfNeeded(builder, model);
214199
builder.addMethod(invokePluginsMethod());
@@ -249,15 +234,6 @@ private MethodSpec signingNameMethod() {
249234
.build();
250235
}
251236

252-
private Optional<MethodSpec> defaultAwsAuthSignerMethod() {
253-
return awsAuthSignerDefinitionMethodBody().map(body -> MethodSpec.methodBuilder("defaultSigner")
254-
.returns(Signer.class)
255-
.addModifiers(PRIVATE)
256-
.addCode(body)
257-
.build());
258-
259-
}
260-
261237
private MethodSpec serviceEndpointPrefixMethod() {
262238
return MethodSpec.methodBuilder("serviceEndpointPrefix")
263239
.addAnnotation(Override.class)
@@ -288,14 +264,10 @@ private MethodSpec mergeServiceDefaultsMethod() {
288264
builder.beginControlFlow("return config.merge(c -> ");
289265
builder.addCode("c.option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())", SdkClientOption.class);
290266

291-
if (authSchemeSpecUtils.useSraAuth()) {
292-
if (!model.getCustomizationConfig().isEnableEnvironmentBearerToken()) {
293-
builder.addCode(".option($T.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config))", SdkClientOption.class);
294-
}
295-
builder.addCode(".option($T.AUTH_SCHEMES, authSchemes())", SdkClientOption.class);
296-
} else if (defaultAwsAuthSignerMethod().isPresent()) {
297-
builder.addCode(".option($T.SIGNER, defaultSigner())\n", SdkAdvancedClientOption.class);
267+
if (!model.getCustomizationConfig().isEnableEnvironmentBearerToken()) {
268+
builder.addCode(".option($T.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider(config))", SdkClientOption.class);
298269
}
270+
builder.addCode(".option($T.AUTH_SCHEMES, authSchemes())", SdkClientOption.class);
299271
builder.addCode(".option($T.CRC32_FROM_COMPRESSED_DATA_ENABLED, $L)\n",
300272
SdkClientOption.class, crc32FromCompressedDataEnabled);
301273

@@ -309,9 +281,6 @@ private MethodSpec mergeServiceDefaultsMethod() {
309281
builder.addCode(".lazyOption($1T.TOKEN_PROVIDER, p -> $2T.toSdkTokenProvider(p.get($1T.TOKEN_IDENTITY_PROVIDER)))",
310282
AwsClientOption.class, TokenUtils.class);
311283
builder.addCode(".option($T.TOKEN_IDENTITY_PROVIDER, defaultTokenProvider())\n", AwsClientOption.class);
312-
if (!authSchemeSpecUtils.useSraAuth()) {
313-
builder.addCode(".option($T.TOKEN_SIGNER, defaultTokenSigner())", SdkAdvancedClientOption.class);
314-
}
315284
}
316285
builder.addStatement("");
317286

@@ -323,14 +292,6 @@ private MethodSpec mergeServiceDefaultsMethod() {
323292
}
324293

325294
private void configureEnvironmentBearerToken(MethodSpec.Builder builder) {
326-
if (!authSchemeSpecUtils.useSraAuth()) {
327-
ValidationEntry entry = ValidationEntry.create(ValidationErrorId.INVALID_CODEGEN_CUSTOMIZATION,
328-
ValidationErrorSeverity.DANGER,
329-
"The enableEnvironmentBearerToken customization requires"
330-
+ " the useSraAuth customization but it is disabled.");
331-
332-
throw ModelInvalidException.fromEntry(entry);
333-
}
334295
if (!AuthUtils.usesBearerAuth(model)) {
335296
ValidationEntry entry =
336297
ValidationEntry.create(ValidationErrorId.INVALID_CODEGEN_CUSTOMIZATION,
@@ -409,9 +370,7 @@ private MethodSpec finalizeServiceConfigurationMethod() {
409370

410371
List<ClassName> builtInInterceptors = new ArrayList<>();
411372

412-
if (authSchemeSpecUtils.useSraAuth()) {
413-
builtInInterceptors.add(authSchemeSpecUtils.authSchemeInterceptor());
414-
}
373+
builtInInterceptors.add(authSchemeSpecUtils.authSchemeInterceptor());
415374
builtInInterceptors.add(endpointRulesSpecUtils.resolverInterceptorName());
416375
builtInInterceptors.add(endpointRulesSpecUtils.requestModifierInterceptorName());
417376

@@ -827,32 +786,6 @@ private CodeBlock serviceSpecificHttpConfigMethodBody(String serviceDefaultFqcn,
827786
return builder.build();
828787
}
829788

830-
private Optional<CodeBlock> awsAuthSignerDefinitionMethodBody() {
831-
AuthType authType = model.getMetadata().getAuthType();
832-
switch (authType) {
833-
case V4:
834-
return Optional.of(v4SignerDefinitionMethodBody());
835-
case S3:
836-
case S3V4:
837-
return Optional.of(s3SignerDefinitionMethodBody());
838-
case BEARER:
839-
case NONE:
840-
return Optional.empty();
841-
default:
842-
throw new UnsupportedOperationException("Unsupported signer type: " + authType);
843-
}
844-
}
845-
846-
private CodeBlock v4SignerDefinitionMethodBody() {
847-
return CodeBlock.of("return $T.create();", Aws4Signer.class);
848-
}
849-
850-
851-
private CodeBlock s3SignerDefinitionMethodBody() {
852-
return CodeBlock.of("return $T.create();\n",
853-
ClassName.get("software.amazon.awssdk.auth.signer", "AwsS3V4Signer"));
854-
}
855-
856789
private MethodSpec defaultEndpointProviderMethod() {
857790
return MethodSpec.methodBuilder("defaultEndpointProvider")
858791
.addModifiers(PRIVATE)
@@ -961,14 +894,6 @@ private MethodSpec defaultBearerTokenProviderMethod() {
961894
.build();
962895
}
963896

964-
private MethodSpec defaultTokenAuthSignerMethod() {
965-
return MethodSpec.methodBuilder("defaultTokenSigner")
966-
.returns(Signer.class)
967-
.addModifiers(PRIVATE)
968-
.addStatement("return $T.create()", BearerTokenSigner.class)
969-
.build();
970-
}
971-
972897
private MethodSpec authSchemesMethod() {
973898
TypeName returns = ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class),
974899
ParameterizedTypeName.get(ClassName.get(AuthScheme.class),
@@ -1133,21 +1058,7 @@ private MethodSpec validateClientOptionsMethod() {
11331058
.addParameter(SdkClientConfiguration.class, "c")
11341059
.returns(void.class);
11351060

1136-
if (AuthUtils.usesAwsAuth(model) && !authSchemeSpecUtils.useSraAuth()) {
1137-
builder.addStatement("$T.notNull(c.option($T.SIGNER), $S)",
1138-
Validate.class,
1139-
SdkAdvancedClientOption.class,
1140-
"The 'overrideConfiguration.advancedOption[SIGNER]' must be configured in the client builder.");
1141-
}
1142-
11431061
if (AuthUtils.usesBearerAuth(model)) {
1144-
if (!authSchemeSpecUtils.useSraAuth()) {
1145-
builder.addStatement("$T.notNull(c.option($T.TOKEN_SIGNER), $S)",
1146-
Validate.class,
1147-
SdkAdvancedClientOption.class,
1148-
"The 'overrideConfiguration.advancedOption[TOKEN_SIGNER]' "
1149-
+ "must be configured in the client builder.");
1150-
}
11511062
builder.addStatement("$T.notNull(c.option($T.TOKEN_IDENTITY_PROVIDER), $S)",
11521063
Validate.class,
11531064
AwsClientOption.class,

0 commit comments

Comments
 (0)