diff --git a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java index 0c60f15d41b1..ef7df9fbd3b4 100644 --- a/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java +++ b/codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java @@ -643,11 +643,6 @@ private MethodSpec authSchemesMethod() { .returns(returns); Set> concreteAuthSchemeClasses = authSchemeSpecUtils.allServiceConcreteAuthSchemeClasses(); - if (concreteAuthSchemeClasses.isEmpty()) { - builder.addStatement("return $T.emptyMap()", Collections.class); - return builder.build(); - } - builder.addStatement("$T schemes = new $T<>($L + this.additionalAuthSchemes.size())", returns, HashMap.class, concreteAuthSchemeClasses.size()); for (Class concreteAuthScheme : concreteAuthSchemeClasses) { diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java index d5015a2a2952..28903e5dedaf 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java @@ -214,7 +214,7 @@ public static IntermediateModel allOperationsWithAuthDifferentValueServiceModels return new IntermediateModelBuilder(models).build(); } - public static IntermediateModel serviceWithNoAuth() { + public static IntermediateModel operationWithNoAuth() { File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/ops-with-no-auth/service-2.json").getFile()); File customizationModel = @@ -229,6 +229,21 @@ public static IntermediateModel serviceWithNoAuth() { return new IntermediateModelBuilder(models).build(); } + public static IntermediateModel serviceWithNoAuth() { + File serviceModel = + new File(ClientTestModels.class.getResource("client/c2j/service-with-no-auth/service-2.json").getFile()); + File customizationModel = + new File(ClientTestModels.class.getResource("client/c2j/service-with-no-auth/customization.config") + .getFile()); + C2jModels models = C2jModels + .builder() + .serviceModel(getServiceModel(serviceModel)) + .customizationConfig(getCustomizationConfig(customizationModel)) + .build(); + + return new IntermediateModelBuilder(models).build(); + } + public static IntermediateModel serviceMiniS3() { File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/mini-s3/service-2.json").getFile()); diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecTest.java index c5deb6c9b9ea..15b061f9a835 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeSpecTest.java @@ -150,9 +150,9 @@ static List parameters() { .build(), // Service with operations with auth none TestCase.builder() - .modelProvider(ClientTestModels::serviceWithNoAuth) + .modelProvider(ClientTestModels::operationWithNoAuth) .classSpecProvider(ModelBasedAuthSchemeProviderSpec::new) - .caseName("service-with-no-auth") + .caseName("ops-with-no-auth") .outputFileSuffix("default-provider") .build(), // Service with signature version with the same value as S3 diff --git a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BuilderClassTest.java b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BuilderClassTest.java index 4d4f3f20ab87..60706c36051a 100644 --- a/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BuilderClassTest.java +++ b/codegen/src/test/java/software/amazon/awssdk/codegen/poet/builder/BuilderClassTest.java @@ -39,18 +39,23 @@ public void baseClientBuilderClass() throws Exception { } @Test - public void baseClientBuilderInterfaceWithBearerAuthClass() throws Exception { + public void baseClientBuilderInterfaceWithBearerAuth() throws Exception { validateBearerAuthGeneration(BaseClientBuilderInterface::new, "test-bearer-auth-client-builder-interface.java"); } @Test - public void baseClientBuilderInterfaceWithNoAuthClass() throws Exception { - validateNoAuthAuthGeneration(BaseClientBuilderClass::new, "test-no-auth-auth-client-builder-class.java"); + public void baseClientBuilderClassWithBearerAuth() throws Exception { + validateBearerAuthGeneration(BaseClientBuilderClass::new, "test-bearer-auth-client-builder-class.java"); } @Test - public void baseClientBuilderWithBearerAuthClass() throws Exception { - validateBearerAuthGeneration(BaseClientBuilderClass::new, "test-bearer-auth-client-builder-class.java"); + public void baseClientBuilderClassWithNoAuthOperation() throws Exception { + validateNoAuthOperationAuthGeneration(BaseClientBuilderClass::new, "test-no-auth-ops-client-builder-class.java"); + } + + @Test + public void baseClientBuilderClassWithNoAuthService() throws Exception { + validateNoAuthServiceAuthGeneration(BaseClientBuilderClass::new, "test-no-auth-service-client-builder-class.java"); } @Test @@ -123,8 +128,13 @@ private void validateBearerAuthGeneration(Function assertThat(generatorConstructor.apply(ClientTestModels.bearerAuthServiceModels()), generatesTo(expectedClassName)); } - private void validateNoAuthAuthGeneration(Function generatorConstructor, - String expectedClassName) { + private void validateNoAuthOperationAuthGeneration(Function generatorConstructor, + String expectedClassName) { + assertThat(generatorConstructor.apply(ClientTestModels.operationWithNoAuth()), generatesTo(expectedClassName)); + } + + private void validateNoAuthServiceAuthGeneration(Function generatorConstructor, + String expectedClassName) { assertThat(generatorConstructor.apply(ClientTestModels.serviceWithNoAuth()), generatesTo(expectedClassName)); } diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/service-with-no-auth-auth-scheme-default-provider.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/ops-with-no-auth-auth-scheme-default-provider.java similarity index 100% rename from codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/service-with-no-auth-auth-scheme-default-provider.java rename to codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/ops-with-no-auth-auth-scheme-default-provider.java diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-auth-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-ops-client-builder-class.java similarity index 100% rename from codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-auth-client-builder-class.java rename to codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-ops-client-builder-class.java diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java new file mode 100644 index 000000000000..d45eae4e8efd --- /dev/null +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-no-auth-service-client-builder-class.java @@ -0,0 +1,103 @@ +package software.amazon.awssdk.services.database; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import software.amazon.awssdk.annotations.Generated; +import software.amazon.awssdk.annotations.SdkInternalApi; +import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; +import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory; +import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; +import software.amazon.awssdk.http.auth.spi.AuthScheme; +import software.amazon.awssdk.http.auth.spi.NoAuthAuthScheme; +import software.amazon.awssdk.services.database.auth.scheme.DatabaseAuthSchemeProvider; +import software.amazon.awssdk.services.database.auth.scheme.internal.DatabaseAuthSchemeInterceptor; +import software.amazon.awssdk.services.database.endpoints.DatabaseEndpointProvider; +import software.amazon.awssdk.services.database.endpoints.internal.DatabaseRequestSetEndpointInterceptor; +import software.amazon.awssdk.services.database.endpoints.internal.DatabaseResolveEndpointInterceptor; +import software.amazon.awssdk.utils.CollectionUtils; + +/** + * Internal base class for {@link DefaultDatabaseClientBuilder} and {@link DefaultDatabaseAsyncClientBuilder}. + */ +@Generated("software.amazon.awssdk:codegen") +@SdkInternalApi +abstract class DefaultDatabaseBaseClientBuilder, C> extends + AwsDefaultClientBuilder { + private final Map> additionalAuthSchemes = new HashMap<>(); + + @Override + protected final String serviceEndpointPrefix() { + return "database-service-endpoint"; + } + + @Override + protected final String serviceName() { + return "Database"; + } + + @Override + protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { + return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider()) + .option(SdkClientOption.AUTH_SCHEME_PROVIDER, defaultAuthSchemeProvider()) + .option(SdkClientOption.AUTH_SCHEMES, authSchemes()) + .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)); + } + + @Override + protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) { + List endpointInterceptors = new ArrayList<>(); + endpointInterceptors.add(new DatabaseAuthSchemeInterceptor()); + endpointInterceptors.add(new DatabaseResolveEndpointInterceptor()); + endpointInterceptors.add(new DatabaseRequestSetEndpointInterceptor()); + ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory(); + List interceptors = interceptorFactory + .getInterceptors("software/amazon/awssdk/services/database/execution.interceptors"); + List additionalInterceptors = new ArrayList<>(); + interceptors = CollectionUtils.mergeLists(endpointInterceptors, interceptors); + interceptors = CollectionUtils.mergeLists(interceptors, additionalInterceptors); + interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS)); + SdkClientConfiguration.Builder builder = config.toBuilder(); + builder.option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors); + return builder.build(); + } + + @Override + protected final String signingName() { + return "database-service"; + } + + private DatabaseEndpointProvider defaultEndpointProvider() { + return DatabaseEndpointProvider.defaultProvider(); + } + + public B authSchemeProvider(DatabaseAuthSchemeProvider authSchemeProvider) { + clientConfiguration.option(SdkClientOption.AUTH_SCHEME_PROVIDER, authSchemeProvider); + return thisBuilder(); + } + + private DatabaseAuthSchemeProvider defaultAuthSchemeProvider() { + return DatabaseAuthSchemeProvider.defaultProvider(); + } + + @Override + public B putAuthScheme(AuthScheme authScheme) { + additionalAuthSchemes.put(authScheme.schemeId(), authScheme); + return thisBuilder(); + } + + private Map> authSchemes() { + Map> schemes = new HashMap<>(1 + this.additionalAuthSchemes.size()); + NoAuthAuthScheme noAuthAuthScheme = NoAuthAuthScheme.create(); + schemes.put(noAuthAuthScheme.schemeId(), noAuthAuthScheme); + schemes.putAll(this.additionalAuthSchemes); + return Collections.unmodifiableMap(schemes); + } + + protected static void validateClientOptions(SdkClientConfiguration c) { + } +} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/customization.config b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/customization.config new file mode 100644 index 000000000000..2c63c0851048 --- /dev/null +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/customization.config @@ -0,0 +1,2 @@ +{ +} diff --git a/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/service-2.json b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/service-2.json new file mode 100644 index 000000000000..c7a4987ed99c --- /dev/null +++ b/codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/service-with-no-auth/service-2.json @@ -0,0 +1,55 @@ +{ + "version": "2.0", + "metadata": { + "apiVersion": "2023-06-08", + "endpointPrefix": "database-service-endpoint", + "globalEndpoint": "database-service.amazonaws.com", + "protocol": "rest-json", + "serviceAbbreviation": "Database Service", + "serviceFullName": "Some Service That Has No Auth At All", + "serviceId": "Database Service", + "signingName": "database-service", + "signatureVersion": "none", + "auth": [], + "uid": "database-service-2023-06-08", + "xmlNamespace": "https://database-service.amazonaws.com/doc/2023-06-08/" + }, + "operations": { + "GetDatabaseVersion": { + "name": "GetDatabaseVersion", + "http": { + "method": "GET", + "requestUri": "/get-version/" + }, + "input": { + "shape": "GetDatabaseVersionRequest" + }, + "output": { + "shape": "GetDatabaseVersionResponse" + }, + "documentation": "

Performs a get database version operation

" + } + }, + "shapes": { + "GetDatabaseVersionRequest": { + "type": "structure", + "members": { + "StringMember": { + "shape": "String", + "documentation": "

A string Member

" + } + } + }, + "GetDatabaseVersionResponse": { + "type": "structure", + "members": { + "StringMember": { + "shape": "String", + "documentation": "

A string Member

" + } + } + }, + "String":{"type":"string"} + }, + "documentation": "A Database Service with no auth on the service at all" +}