|
23 | 23 | import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
|
24 | 24 | import software.amazon.awssdk.core.http.HttpResponseHandler;
|
25 | 25 | import software.amazon.awssdk.core.metrics.CoreMetric;
|
| 26 | +import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; |
26 | 27 | import software.amazon.awssdk.metrics.MetricCollector;
|
27 | 28 | import software.amazon.awssdk.metrics.MetricPublisher;
|
28 | 29 | import software.amazon.awssdk.metrics.NoOpMetricCollector;
|
@@ -175,26 +176,30 @@ public CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> testDiscovery
|
175 | 176 | throw new IllegalStateException(
|
176 | 177 | "This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
|
177 | 178 | }
|
178 |
| - URI cachedEndpoint = null; |
| 179 | + CompletableFuture<URI> endpointFuture = CompletableFuture.completedFuture(null); |
179 | 180 | if (endpointDiscoveryEnabled) {
|
180 |
| - String key = testDiscoveryIdentifiersRequiredRequest.overrideConfiguration() |
181 |
| - .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
182 |
| - .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
183 |
| - .resolveIdentity().join().accessKeyId(); |
184 |
| - EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true) |
185 |
| - .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
186 |
| - .overrideConfiguration(testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null)) |
187 |
| - .build(); |
188 |
| - cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest); |
| 181 | + CompletableFuture<? extends AwsCredentialsIdentity> identityFuture = |
| 182 | + testDiscoveryIdentifiersRequiredRequest.overrideConfiguration() |
| 183 | + .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
| 184 | + .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
| 185 | + .resolveIdentity(); |
| 186 | + endpointFuture = identityFuture.thenApply(credentials -> { |
| 187 | + EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true) |
| 188 | + .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
| 189 | + .overrideConfiguration(testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null)) |
| 190 | + .build(); |
| 191 | + return endpointDiscoveryCache.get(credentials.accessKeyId(), endpointDiscoveryRequest); |
| 192 | + }); |
189 | 193 | }
|
190 | 194 |
|
191 |
| - CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> executeFuture = clientHandler |
192 |
| - .execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>() |
| 195 | + CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> executeFuture = |
| 196 | + endpointFuture.thenCompose(cachedEndpoint -> |
| 197 | + clientHandler.execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>() |
193 | 198 | .withOperationName("TestDiscoveryIdentifiersRequired")
|
194 | 199 | .withMarshaller(new TestDiscoveryIdentifiersRequiredRequestMarshaller(protocolFactory))
|
195 | 200 | .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
|
196 | 201 | .withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint)
|
197 |
| - .withInput(testDiscoveryIdentifiersRequiredRequest)); |
| 202 | + .withInput(testDiscoveryIdentifiersRequiredRequest))); |
198 | 203 | CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
|
199 | 204 | metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
|
200 | 205 | });
|
@@ -243,25 +248,29 @@ public CompletableFuture<TestDiscoveryOptionalResponse> testDiscoveryOptional(
|
243 | 248 | operationMetadata);
|
244 | 249 | boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
|
245 | 250 | boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
|
246 |
| - URI cachedEndpoint = null; |
| 251 | + CompletableFuture<URI> endpointFuture = CompletableFuture.completedFuture(null); |
247 | 252 | if (endpointDiscoveryEnabled) {
|
248 |
| - String key = testDiscoveryOptionalRequest.overrideConfiguration() |
249 |
| - .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
250 |
| - .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
251 |
| - .resolveIdentity().join().accessKeyId(); |
252 |
| - EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false) |
253 |
| - .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
254 |
| - .overrideConfiguration(testDiscoveryOptionalRequest.overrideConfiguration().orElse(null)).build(); |
255 |
| - cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest); |
| 253 | + CompletableFuture<? extends AwsCredentialsIdentity> identityFuture = |
| 254 | + testDiscoveryOptionalRequest.overrideConfiguration() |
| 255 | + .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
| 256 | + .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
| 257 | + .resolveIdentity(); |
| 258 | + endpointFuture = identityFuture.thenApply(credentials -> { |
| 259 | + EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false) |
| 260 | + .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
| 261 | + .overrideConfiguration(testDiscoveryOptionalRequest.overrideConfiguration().orElse(null)).build(); |
| 262 | + return endpointDiscoveryCache.get(credentials.accessKeyId(), endpointDiscoveryRequest); |
| 263 | + }); |
256 | 264 | }
|
257 | 265 |
|
258 |
| - CompletableFuture<TestDiscoveryOptionalResponse> executeFuture = clientHandler |
259 |
| - .execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>() |
| 266 | + CompletableFuture<TestDiscoveryOptionalResponse> executeFuture = |
| 267 | + endpointFuture.thenCompose(cachedEndpoint -> |
| 268 | + clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>() |
260 | 269 | .withOperationName("TestDiscoveryOptional")
|
261 | 270 | .withMarshaller(new TestDiscoveryOptionalRequestMarshaller(protocolFactory))
|
262 | 271 | .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
|
263 | 272 | .withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint)
|
264 |
| - .withInput(testDiscoveryOptionalRequest)); |
| 273 | + .withInput(testDiscoveryOptionalRequest))); |
265 | 274 | CompletableFuture<TestDiscoveryOptionalResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
|
266 | 275 | metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
|
267 | 276 | });
|
@@ -318,25 +327,29 @@ public CompletableFuture<TestDiscoveryRequiredResponse> testDiscoveryRequired(
|
318 | 327 | throw new IllegalStateException(
|
319 | 328 | "This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
|
320 | 329 | }
|
321 |
| - URI cachedEndpoint = null; |
| 330 | + CompletableFuture<URI> endpointFuture = CompletableFuture.completedFuture(null); |
322 | 331 | if (endpointDiscoveryEnabled) {
|
323 |
| - String key = testDiscoveryRequiredRequest.overrideConfiguration() |
324 |
| - .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
325 |
| - .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
326 |
| - .resolveIdentity().join().accessKeyId(); |
327 |
| - EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true) |
328 |
| - .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
329 |
| - .overrideConfiguration(testDiscoveryRequiredRequest.overrideConfiguration().orElse(null)).build(); |
330 |
| - cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest); |
| 332 | + CompletableFuture<? extends AwsCredentialsIdentity> identityFuture = |
| 333 | + testDiscoveryRequiredRequest.overrideConfiguration() |
| 334 | + .flatMap(AwsRequestOverrideConfiguration::credentialsIdentityProvider) |
| 335 | + .orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER)) |
| 336 | + .resolveIdentity(); |
| 337 | + endpointFuture = identityFuture.thenApply(credentials -> { |
| 338 | + EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true) |
| 339 | + .defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)) |
| 340 | + .overrideConfiguration(testDiscoveryRequiredRequest.overrideConfiguration().orElse(null)).build(); |
| 341 | + return endpointDiscoveryCache.get(credentials.accessKeyId(), endpointDiscoveryRequest); |
| 342 | + }); |
331 | 343 | }
|
332 | 344 |
|
333 |
| - CompletableFuture<TestDiscoveryRequiredResponse> executeFuture = clientHandler |
334 |
| - .execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>() |
| 345 | + CompletableFuture<TestDiscoveryRequiredResponse> executeFuture = |
| 346 | + endpointFuture.thenCompose(cachedEndpoint -> |
| 347 | + clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>() |
335 | 348 | .withOperationName("TestDiscoveryRequired")
|
336 | 349 | .withMarshaller(new TestDiscoveryRequiredRequestMarshaller(protocolFactory))
|
337 | 350 | .withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
|
338 | 351 | .withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint)
|
339 |
| - .withInput(testDiscoveryRequiredRequest)); |
| 352 | + .withInput(testDiscoveryRequiredRequest))); |
340 | 353 | CompletableFuture<TestDiscoveryRequiredResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
|
341 | 354 | metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
|
342 | 355 | });
|
|
0 commit comments