use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.
the class DefaultEndpointDiscoveryTestAsyncClient method testDiscoveryIdentifiersRequired.
/**
* Invokes the TestDiscoveryIdentifiersRequired operation asynchronously.
*
* @param testDiscoveryIdentifiersRequiredRequest
* @return A Java Future containing the result of the TestDiscoveryIdentifiersRequired operation returned by the
* service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>EndpointDiscoveryTestException Base class for all service exceptions. Unknown exceptions will be
* thrown as an instance of this type.</li>
* </ul>
* @sample EndpointDiscoveryTestAsyncClient.TestDiscoveryIdentifiersRequired
*/
@Override
public CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> testDiscoveryIdentifiersRequired(TestDiscoveryIdentifiersRequiredRequest testDiscoveryIdentifiersRequiredRequest) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryIdentifiersRequired");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
HttpResponseHandler<TestDiscoveryIdentifiersRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryIdentifiersRequiredResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
if (endpointOverridden) {
throw new IllegalStateException("This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
}
if (!endpointDiscoveryEnabled) {
throw new IllegalStateException("This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
}
URI cachedEndpoint = null;
if (endpointDiscoveryEnabled) {
String key = testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null)).build();
cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
}
CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>().withOperationName("TestDiscoveryIdentifiersRequired").withMarshaller(new TestDiscoveryIdentifiersRequiredRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryIdentifiersRequiredRequest));
CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.
the class S3PresignerTest method getObject_CredentialsCanBeOverriddenAtTheRequestLevel.
@Test
public void getObject_CredentialsCanBeOverriddenAtTheRequestLevel() {
AwsCredentials clientCredentials = AwsBasicCredentials.create("a", "a");
AwsCredentials requestCredentials = AwsBasicCredentials.create("b", "b");
S3Presigner presigner = presignerBuilder().credentialsProvider(() -> clientCredentials).build();
AwsRequestOverrideConfiguration overrideConfiguration = AwsRequestOverrideConfiguration.builder().credentialsProvider(() -> requestCredentials).build();
PresignedGetObjectRequest presignedWithClientCredentials = presigner.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(5)).getObjectRequest(go -> go.bucket("foo34343434").key("bar")));
PresignedGetObjectRequest presignedWithRequestCredentials = presigner.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(5)).getObjectRequest(go -> go.bucket("foo34343434").key("bar").overrideConfiguration(overrideConfiguration)));
assertThat(presignedWithClientCredentials.httpRequest().rawQueryParameters().get("X-Amz-Credential").get(0)).startsWith("a");
assertThat(presignedWithRequestCredentials.httpRequest().rawQueryParameters().get("X-Amz-Credential").get(0)).startsWith("b");
}
use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.
the class EndpointDiscoveryTestAsyncEndpointDiscoveryCacheLoader method discoverEndpoint.
@Override
public CompletableFuture<EndpointDiscoveryEndpoint> discoverEndpoint(EndpointDiscoveryRequest endpointDiscoveryRequest) {
AwsRequestOverrideConfiguration requestConfig = AwsRequestOverrideConfiguration.from(endpointDiscoveryRequest.overrideConfiguration().orElse(null));
return client.describeEndpoints(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsRequest.builder().overrideConfiguration(requestConfig).build()).thenApply(r -> {
List<Endpoint> endpoints = r.endpoints();
Validate.notEmpty(endpoints, "Endpoints returned by service for endpoint discovery must not be empty.");
Endpoint endpoint = endpoints.get(0);
return EndpointDiscoveryEndpoint.builder().endpoint(toUri(endpoint.address(), endpointDiscoveryRequest.defaultEndpoint())).expirationTime(Instant.now().plus(endpoint.cachePeriodInMinutes(), ChronoUnit.MINUTES)).build();
});
}
use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.
the class EndpointDiscoveryTestEndpointDiscoveryCacheLoader method discoverEndpoint.
@Override
public CompletableFuture<EndpointDiscoveryEndpoint> discoverEndpoint(EndpointDiscoveryRequest endpointDiscoveryRequest) {
return CompletableFuture.supplyAsync(() -> {
AwsRequestOverrideConfiguration requestConfig = AwsRequestOverrideConfiguration.from(endpointDiscoveryRequest.overrideConfiguration().orElse(null));
DescribeEndpointsResponse response = client.describeEndpoints(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsRequest.builder().overrideConfiguration(requestConfig).build());
List<Endpoint> endpoints = response.endpoints();
Validate.notEmpty(endpoints, "Endpoints returned by service for endpoint discovery must not be empty.");
Endpoint endpoint = endpoints.get(0);
return EndpointDiscoveryEndpoint.builder().endpoint(toUri(endpoint.address(), endpointDiscoveryRequest.defaultEndpoint())).expirationTime(Instant.now().plus(endpoint.cachePeriodInMinutes(), ChronoUnit.MINUTES)).build();
});
}
use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.
the class DefaultQueryAsyncWaiter method applyWaitersUserAgent.
private <T extends QueryRequest> T applyWaitersUserAgent(T request) {
Consumer<AwsRequestOverrideConfiguration.Builder> userAgentApplier = b -> b.addApiName(ApiName.builder().version("waiter").name("hll").build());
AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration().map(c -> c.toBuilder().applyMutation(userAgentApplier).build()).orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build()));
return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
}
Aggregations