Skip to content

Commit ac0c45e

Browse files
committed
Revert "Updated endpoint discovery behavior for operations that require endpoint discovery."
This reverts commit c2c0e28.
1 parent 7ce6281 commit ac0c45e

File tree

15 files changed

+13
-684
lines changed

15 files changed

+13
-684
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ public class CustomizationConfig {
165165
*/
166166
private boolean enableEndpointDiscoveryMethodRequired = false;
167167

168-
/**
169-
* Allow a customer to set an endpoint override AND bypass endpoint discovery on their client even when endpoint discovery
170-
* enabled is true and endpoint discovery is required for an operation. This customization should almost never be "true"
171-
* because it creates a confusing customer experience.
172-
*/
173-
private boolean allowEndpointOverrideForEndpointDiscoveryRequiredOperations = false;
174-
175168
private CustomizationConfig() {
176169
}
177170

@@ -427,14 +420,4 @@ public boolean isEnableEndpointDiscoveryMethodRequired() {
427420
public void setEnableEndpointDiscoveryMethodRequired(boolean enableEndpointDiscoveryMethodRequired) {
428421
this.enableEndpointDiscoveryMethodRequired = enableEndpointDiscoveryMethodRequired;
429422
}
430-
431-
public boolean allowEndpointOverrideForEndpointDiscoveryRequiredOperations() {
432-
return allowEndpointOverrideForEndpointDiscoveryRequiredOperations;
433-
}
434-
435-
public void setAllowEndpointOverrideForEndpointDiscoveryRequiredOperations(
436-
boolean allowEndpointOverrideForEndpointDiscoveryRequiredOperations) {
437-
this.allowEndpointOverrideForEndpointDiscoveryRequiredOperations =
438-
allowEndpointOverrideForEndpointDiscoveryRequiredOperations;
439-
}
440423
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,6 @@ private MethodSpec constructor(Builder classBuilder) {
166166
EndpointDiscoveryRefreshCache.class,
167167
poetExtensions.getClientClass(model.getNamingStrategy().getServiceName() +
168168
"AsyncEndpointDiscoveryCacheLoader"));
169-
170-
if (model.getCustomizationConfig().allowEndpointOverrideForEndpointDiscoveryRequiredOperations()) {
171-
builder.beginControlFlow("if (clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == "
172-
+ "Boolean.TRUE)");
173-
builder.addStatement("log.warn($S)",
174-
"Endpoint discovery is enabled for this client, and an endpoint override was also "
175-
+ "specified. This will disable endpoint discovery for methods that require it, instead "
176-
+ "using the specified endpoint override. This may or may not be what you intended.");
177-
builder.endControlFlow();
178-
}
179-
180169
builder.endControlFlow();
181170
}
182171

@@ -231,37 +220,8 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation
231220
builder.addCode(eventToByteBufferPublisher(opModel));
232221

233222
if (opModel.getEndpointDiscovery() != null) {
234-
builder.addStatement("boolean endpointDiscoveryEnabled = "
235-
+ "clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)");
236-
builder.addStatement("boolean endpointOverridden = "
237-
+ "clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE");
238-
239-
if (opModel.getEndpointDiscovery().isRequired()) {
240-
if (!model.getCustomizationConfig().allowEndpointOverrideForEndpointDiscoveryRequiredOperations()) {
241-
builder.beginControlFlow("if (endpointOverridden)");
242-
builder.addStatement("throw new $T($S)", IllegalStateException.class,
243-
"This operation requires endpoint discovery, but an endpoint override was specified "
244-
+ "when the client was created. This is not supported.");
245-
builder.endControlFlow();
246-
247-
builder.beginControlFlow("if (!endpointDiscoveryEnabled)");
248-
builder.addStatement("throw new $T($S)", IllegalStateException.class,
249-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the "
250-
+ "client.");
251-
builder.endControlFlow();
252-
} else {
253-
builder.beginControlFlow("if (endpointOverridden)");
254-
builder.addStatement("endpointDiscoveryEnabled = false");
255-
builder.nextControlFlow("else if (!endpointDiscoveryEnabled)");
256-
builder.addStatement("throw new $T($S)", IllegalStateException.class,
257-
"This operation requires endpoint discovery to be enabled, or for you to specify an "
258-
+ "endpoint override when the client is created.");
259-
builder.endControlFlow();
260-
}
261-
}
262-
263223
builder.addStatement("$T cachedEndpoint = null", URI.class);
264-
builder.beginControlFlow("if (endpointDiscoveryEnabled)");
224+
builder.beginControlFlow("if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED))");
265225
builder.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER).resolveCredentials()" +
266226
".accessKeyId()", AwsClientOption.class);
267227
builder.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L)" +

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import software.amazon.awssdk.metrics.MetricCollector;
6161
import software.amazon.awssdk.metrics.MetricPublisher;
6262
import software.amazon.awssdk.metrics.NoOpMetricCollector;
63-
import software.amazon.awssdk.utils.Logger;
6463

6564
//TODO Make SyncClientClass extend SyncClientInterface (similar to what we do in AsyncClientClass)
6665
public class SyncClientClass implements ClassSpec {
@@ -87,7 +86,6 @@ public TypeSpec poetSpec() {
8786
.addSuperinterface(interfaceClass)
8887
.addJavadoc("Internal implementation of {@link $1T}.\n\n@see $1T#builder()",
8988
interfaceClass)
90-
.addField(logger())
9189
.addField(SyncClientHandler.class, "clientHandler", PRIVATE, FINAL)
9290
.addField(protocolSpec.protocolFactory(model))
9391
.addField(SdkClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL)
@@ -121,12 +119,6 @@ public TypeSpec poetSpec() {
121119
return classBuilder.build();
122120
}
123121

124-
private FieldSpec logger() {
125-
return FieldSpec.builder(Logger.class, "log", PRIVATE, STATIC, FINAL)
126-
.initializer("$T.loggerFor($T.class)", Logger.class, className)
127-
.build();
128-
}
129-
130122
private MethodSpec nameMethod() {
131123
return MethodSpec.methodBuilder("serviceName")
132124
.addAnnotation(Override.class)
@@ -162,17 +154,6 @@ private MethodSpec constructor() {
162154
EndpointDiscoveryRefreshCache.class,
163155
poetExtensions.getClientClass(model.getNamingStrategy().getServiceName() +
164156
"EndpointDiscoveryCacheLoader"));
165-
166-
if (model.getCustomizationConfig().allowEndpointOverrideForEndpointDiscoveryRequiredOperations()) {
167-
builder.beginControlFlow("if (clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == "
168-
+ "Boolean.TRUE)");
169-
builder.addStatement("log.warn(() -> $S)",
170-
"Endpoint discovery is enabled for this client, and an endpoint override was also "
171-
+ "specified. This will disable endpoint discovery for methods that require it, instead "
172-
+ "using the specified endpoint override. This may or may not be what you intended.");
173-
builder.endControlFlow();
174-
}
175-
176157
builder.endControlFlow();
177158
}
178159

@@ -200,37 +181,8 @@ private List<MethodSpec> operationMethodSpecs(OperationModel opModel) {
200181
protocolSpec.errorResponseHandler(opModel).ifPresent(method::addCode);
201182

202183
if (opModel.getEndpointDiscovery() != null) {
203-
method.addStatement("boolean endpointDiscoveryEnabled = "
204-
+ "clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)");
205-
method.addStatement("boolean endpointOverridden = "
206-
+ "clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE");
207-
208-
if (opModel.getEndpointDiscovery().isRequired()) {
209-
if (!model.getCustomizationConfig().allowEndpointOverrideForEndpointDiscoveryRequiredOperations()) {
210-
method.beginControlFlow("if (endpointOverridden)");
211-
method.addStatement("throw new $T($S)", IllegalStateException.class,
212-
"This operation requires endpoint discovery, but an endpoint override was specified "
213-
+ "when the client was created. This is not supported.");
214-
method.endControlFlow();
215-
216-
method.beginControlFlow("if (!endpointDiscoveryEnabled)");
217-
method.addStatement("throw new $T($S)", IllegalStateException.class,
218-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the "
219-
+ "client.");
220-
method.endControlFlow();
221-
} else {
222-
method.beginControlFlow("if (endpointOverridden)");
223-
method.addStatement("endpointDiscoveryEnabled = false");
224-
method.nextControlFlow("else if (!endpointDiscoveryEnabled)");
225-
method.addStatement("throw new $T($S)", IllegalStateException.class,
226-
"This operation requires endpoint discovery to be enabled, or for you to specify an "
227-
+ "endpoint override when the client is created.");
228-
method.endControlFlow();
229-
}
230-
}
231-
232184
method.addStatement("$T cachedEndpoint = null", URI.class);
233-
method.beginControlFlow("if (endpointDiscoveryEnabled)");
185+
method.beginControlFlow("if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED))");
234186
method.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER)." +
235187
"resolveCredentials().accessKeyId()", AwsClientOption.class);
236188
method.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L)" +

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-endpoint-discovery-async.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,8 @@ public CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> testDiscovery
167167

168168
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
169169
operationMetadata);
170-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
171-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
172-
if (endpointOverridden) {
173-
throw new IllegalStateException(
174-
"This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
175-
}
176-
if (!endpointDiscoveryEnabled) {
177-
throw new IllegalStateException(
178-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
179-
}
180170
URI cachedEndpoint = null;
181-
if (endpointDiscoveryEnabled) {
171+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
182172

183173
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
184174
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true)
@@ -241,10 +231,8 @@ public CompletableFuture<TestDiscoveryOptionalResponse> testDiscoveryOptional(
241231

242232
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
243233
operationMetadata);
244-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
245-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
246234
URI cachedEndpoint = null;
247-
if (endpointDiscoveryEnabled) {
235+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
248236

249237
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
250238
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false)
@@ -307,18 +295,8 @@ public CompletableFuture<TestDiscoveryRequiredResponse> testDiscoveryRequired(
307295

308296
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
309297
operationMetadata);
310-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
311-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
312-
if (endpointOverridden) {
313-
throw new IllegalStateException(
314-
"This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
315-
}
316-
if (!endpointDiscoveryEnabled) {
317-
throw new IllegalStateException(
318-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
319-
}
320298
URI cachedEndpoint = null;
321-
if (endpointDiscoveryEnabled) {
299+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
322300

323301
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
324302
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true)

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-endpoint-discovery-sync.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryIdentifiersRequiredRequestMarshaller;
3939
import software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryOptionalRequestMarshaller;
4040
import software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryRequiredRequestMarshaller;
41-
import software.amazon.awssdk.utils.Logger;
4241

4342
/**
4443
* Internal implementation of {@link EndpointDiscoveryTestClient}.
@@ -48,8 +47,6 @@
4847
@Generated("software.amazon.awssdk:codegen")
4948
@SdkInternalApi
5049
final class DefaultEndpointDiscoveryTestClient implements EndpointDiscoveryTestClient {
51-
private static final Logger log = Logger.loggerFor(DefaultEndpointDiscoveryTestClient.class);
52-
5350
private final SyncClientHandler clientHandler;
5451

5552
private final AwsJsonProtocolFactory protocolFactory;
@@ -142,18 +139,8 @@ public TestDiscoveryIdentifiersRequiredResponse testDiscoveryIdentifiersRequired
142139

143140
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
144141
operationMetadata);
145-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
146-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
147-
if (endpointOverridden) {
148-
throw new IllegalStateException(
149-
"This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
150-
}
151-
if (!endpointDiscoveryEnabled) {
152-
throw new IllegalStateException(
153-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
154-
}
155142
URI cachedEndpoint = null;
156-
if (endpointDiscoveryEnabled) {
143+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
157144

158145
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
159146
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true)
@@ -204,10 +191,8 @@ public TestDiscoveryOptionalResponse testDiscoveryOptional(TestDiscoveryOptional
204191

205192
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
206193
operationMetadata);
207-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
208-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
209194
URI cachedEndpoint = null;
210-
if (endpointDiscoveryEnabled) {
195+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
211196

212197
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
213198
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false)
@@ -257,18 +242,8 @@ public TestDiscoveryRequiredResponse testDiscoveryRequired(TestDiscoveryRequired
257242

258243
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
259244
operationMetadata);
260-
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
261-
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
262-
if (endpointOverridden) {
263-
throw new IllegalStateException(
264-
"This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
265-
}
266-
if (!endpointDiscoveryEnabled) {
267-
throw new IllegalStateException(
268-
"This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
269-
}
270245
URI cachedEndpoint = null;
271-
if (endpointDiscoveryEnabled) {
246+
if (clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED)) {
272247

273248
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
274249
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true)

0 commit comments

Comments
 (0)