software.amazon.awssdk.services.ssooidc.DefaultSsoOidcAsyncClient Maven / Gradle / Ivy
Show all versions of ssooidc Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.ssooidc;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkPlugin;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.ssooidc.internal.SsoOidcServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.ssooidc.model.AccessDeniedException;
import software.amazon.awssdk.services.ssooidc.model.AuthorizationPendingException;
import software.amazon.awssdk.services.ssooidc.model.CreateTokenRequest;
import software.amazon.awssdk.services.ssooidc.model.CreateTokenResponse;
import software.amazon.awssdk.services.ssooidc.model.CreateTokenWithIamRequest;
import software.amazon.awssdk.services.ssooidc.model.CreateTokenWithIamResponse;
import software.amazon.awssdk.services.ssooidc.model.ExpiredTokenException;
import software.amazon.awssdk.services.ssooidc.model.InternalServerException;
import software.amazon.awssdk.services.ssooidc.model.InvalidClientException;
import software.amazon.awssdk.services.ssooidc.model.InvalidClientMetadataException;
import software.amazon.awssdk.services.ssooidc.model.InvalidGrantException;
import software.amazon.awssdk.services.ssooidc.model.InvalidRedirectUriException;
import software.amazon.awssdk.services.ssooidc.model.InvalidRequestException;
import software.amazon.awssdk.services.ssooidc.model.InvalidRequestRegionException;
import software.amazon.awssdk.services.ssooidc.model.InvalidScopeException;
import software.amazon.awssdk.services.ssooidc.model.RegisterClientRequest;
import software.amazon.awssdk.services.ssooidc.model.RegisterClientResponse;
import software.amazon.awssdk.services.ssooidc.model.SlowDownException;
import software.amazon.awssdk.services.ssooidc.model.SsoOidcException;
import software.amazon.awssdk.services.ssooidc.model.StartDeviceAuthorizationRequest;
import software.amazon.awssdk.services.ssooidc.model.StartDeviceAuthorizationResponse;
import software.amazon.awssdk.services.ssooidc.model.UnauthorizedClientException;
import software.amazon.awssdk.services.ssooidc.model.UnsupportedGrantTypeException;
import software.amazon.awssdk.services.ssooidc.transform.CreateTokenRequestMarshaller;
import software.amazon.awssdk.services.ssooidc.transform.CreateTokenWithIamRequestMarshaller;
import software.amazon.awssdk.services.ssooidc.transform.RegisterClientRequestMarshaller;
import software.amazon.awssdk.services.ssooidc.transform.StartDeviceAuthorizationRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;
/**
* Internal implementation of {@link SsoOidcAsyncClient}.
*
* @see SsoOidcAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultSsoOidcAsyncClient implements SsoOidcAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultSsoOidcAsyncClient.class);
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
.serviceProtocol(AwsServiceProtocol.REST_JSON).build();
private final AsyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultSsoOidcAsyncClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this).build();
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
}
/**
*
* Creates and returns access and refresh tokens for clients that are authenticated using client secrets. The access
* token can be used to fetch short-term credentials for the assigned AWS accounts or to access application APIs
* using bearer
authentication.
*
*
* @param createTokenRequest
* @return A Java Future containing the result of the CreateToken operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - InvalidRequestException Indicates that something is wrong with the input to the request. For example,
* a required parameter might be missing or out of range.
* - InvalidClientException Indicates that the
clientId
or clientSecret
in the
* request is invalid. For example, this can occur when a client sends an incorrect clientId
or
* an expired clientSecret
.
* - InvalidGrantException Indicates that a request contains an invalid grant. This can occur if a client
* makes a CreateToken request with an invalid grant type.
* - UnauthorizedClientException Indicates that the client is not currently authorized to make the
* request. This can happen when a
clientId
is not issued for a public client.
* - UnsupportedGrantTypeException Indicates that the grant type in the request is not supported by the
* service.
* - InvalidScopeException Indicates that the scope provided in the request is invalid.
* - AuthorizationPendingException Indicates that a request to authorize a client with an access user
* session token is pending.
* - SlowDownException Indicates that the client is making the request too frequently and is more than the
* service can handle.
* - AccessDeniedException You do not have sufficient access to perform this action.
* - ExpiredTokenException Indicates that the token issued by the service is expired and is no longer
* valid.
* - InternalServerException Indicates that an error from the service occurred while trying to process a
* request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - SsoOidcException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample SsoOidcAsyncClient.CreateToken
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture createToken(CreateTokenRequest createTokenRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createTokenRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createTokenRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SSO OIDC");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateToken");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
CreateTokenResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateToken").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateTokenRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createTokenRequest));
CompletableFuture 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);
}
}
/**
*
* Creates and returns access and refresh tokens for clients and applications that are authenticated using IAM
* entities. The access token can be used to fetch short-term credentials for the assigned Amazon Web Services
* accounts or to access application APIs using bearer
authentication.
*
*
* @param createTokenWithIamRequest
* @return A Java Future containing the result of the CreateTokenWithIAM operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - InvalidRequestException Indicates that something is wrong with the input to the request. For example,
* a required parameter might be missing or out of range.
* - InvalidClientException Indicates that the
clientId
or clientSecret
in the
* request is invalid. For example, this can occur when a client sends an incorrect clientId
or
* an expired clientSecret
.
* - InvalidGrantException Indicates that a request contains an invalid grant. This can occur if a client
* makes a CreateToken request with an invalid grant type.
* - UnauthorizedClientException Indicates that the client is not currently authorized to make the
* request. This can happen when a
clientId
is not issued for a public client.
* - UnsupportedGrantTypeException Indicates that the grant type in the request is not supported by the
* service.
* - InvalidScopeException Indicates that the scope provided in the request is invalid.
* - AuthorizationPendingException Indicates that a request to authorize a client with an access user
* session token is pending.
* - SlowDownException Indicates that the client is making the request too frequently and is more than the
* service can handle.
* - AccessDeniedException You do not have sufficient access to perform this action.
* - ExpiredTokenException Indicates that the token issued by the service is expired and is no longer
* valid.
* - InternalServerException Indicates that an error from the service occurred while trying to process a
* request.
* - InvalidRequestRegionException Indicates that a token provided as input to the request was issued by
* and is only usable by calling IAM Identity Center endpoints in another region.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - SsoOidcException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample SsoOidcAsyncClient.CreateTokenWithIAM
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createTokenWithIAM(CreateTokenWithIamRequest createTokenWithIamRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createTokenWithIamRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createTokenWithIamRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SSO OIDC");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateTokenWithIAM");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateTokenWithIamResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateTokenWithIAM").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateTokenWithIamRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createTokenWithIamRequest));
CompletableFuture 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);
}
}
/**
*
* Registers a client with IAM Identity Center. This allows clients to initiate device authorization. The output
* should be persisted for reuse through many authentication requests.
*
*
* @param registerClientRequest
* @return A Java Future containing the result of the RegisterClient operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - InvalidRequestException Indicates that something is wrong with the input to the request. For example,
* a required parameter might be missing or out of range.
* - InvalidScopeException Indicates that the scope provided in the request is invalid.
* - InvalidClientMetadataException Indicates that the client information sent in the request during
* registration is invalid.
* - InternalServerException Indicates that an error from the service occurred while trying to process a
* request.
* - InvalidRedirectUriException Indicates that one or more redirect URI in the request is not supported
* for this operation.
* - UnsupportedGrantTypeException Indicates that the grant type in the request is not supported by the
* service.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - SsoOidcException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample SsoOidcAsyncClient.RegisterClient
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture registerClient(RegisterClientRequest registerClientRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(registerClientRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, registerClientRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SSO OIDC");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "RegisterClient");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, RegisterClientResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("RegisterClient").withProtocolMetadata(protocolMetadata)
.withMarshaller(new RegisterClientRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(registerClientRequest));
CompletableFuture 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);
}
}
/**
*
* Initiates device authorization by requesting a pair of verification codes from the authorization service.
*
*
* @param startDeviceAuthorizationRequest
* @return A Java Future containing the result of the StartDeviceAuthorization operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - InvalidRequestException Indicates that something is wrong with the input to the request. For example,
* a required parameter might be missing or out of range.
* - InvalidClientException Indicates that the
clientId
or clientSecret
in the
* request is invalid. For example, this can occur when a client sends an incorrect clientId
or
* an expired clientSecret
.
* - UnauthorizedClientException Indicates that the client is not currently authorized to make the
* request. This can happen when a
clientId
is not issued for a public client.
* - SlowDownException Indicates that the client is making the request too frequently and is more than the
* service can handle.
* - InternalServerException Indicates that an error from the service occurred while trying to process a
* request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - SsoOidcException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample SsoOidcAsyncClient.StartDeviceAuthorization
* @see AWS API Documentation
*/
@Override
public CompletableFuture startDeviceAuthorization(
StartDeviceAuthorizationRequest startDeviceAuthorizationRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(startDeviceAuthorizationRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, startDeviceAuthorizationRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "SSO OIDC");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StartDeviceAuthorization");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, StartDeviceAuthorizationResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("StartDeviceAuthorization").withProtocolMetadata(protocolMetadata)
.withMarshaller(new StartDeviceAuthorizationRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(startDeviceAuthorizationRequest));
CompletableFuture 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);
}
}
@Override
public final SsoOidcServiceClientConfiguration serviceClientConfiguration() {
return new SsoOidcServiceClientConfigurationBuilder(this.clientConfiguration.toBuilder()).build();
}
@Override
public final String serviceName() {
return SERVICE_NAME;
}
private > T init(T builder) {
return builder
.clientConfiguration(clientConfiguration)
.defaultServiceExceptionSupplier(SsoOidcException::builder)
.protocol(AwsJsonProtocol.REST_JSON)
.protocolVersion("1.1")
.registerModeledException(
ExceptionMetadata.builder().errorCode("SlowDownException")
.exceptionBuilderSupplier(SlowDownException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidRedirectUriException")
.exceptionBuilderSupplier(InvalidRedirectUriException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("AccessDeniedException")
.exceptionBuilderSupplier(AccessDeniedException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("ExpiredTokenException")
.exceptionBuilderSupplier(ExpiredTokenException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InternalServerException")
.exceptionBuilderSupplier(InternalServerException::builder).httpStatusCode(500).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidClientMetadataException")
.exceptionBuilderSupplier(InvalidClientMetadataException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidGrantException")
.exceptionBuilderSupplier(InvalidGrantException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("UnauthorizedClientException")
.exceptionBuilderSupplier(UnauthorizedClientException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidClientException")
.exceptionBuilderSupplier(InvalidClientException::builder).httpStatusCode(401).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("AuthorizationPendingException")
.exceptionBuilderSupplier(AuthorizationPendingException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidRequestException")
.exceptionBuilderSupplier(InvalidRequestException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidScopeException")
.exceptionBuilderSupplier(InvalidScopeException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("UnsupportedGrantTypeException")
.exceptionBuilderSupplier(UnsupportedGrantTypeException::builder).httpStatusCode(400).build())
.registerModeledException(
ExceptionMetadata.builder().errorCode("InvalidRequestRegionException")
.exceptionBuilderSupplier(InvalidRequestRegionException::builder).httpStatusCode(400).build());
}
private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
RequestOverrideConfiguration requestOverrideConfiguration) {
List publishers = null;
if (requestOverrideConfiguration != null) {
publishers = requestOverrideConfiguration.metricPublishers();
}
if (publishers == null || publishers.isEmpty()) {
publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS);
}
if (publishers == null) {
publishers = Collections.emptyList();
}
return publishers;
}
private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) {
ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder();
RetryMode retryMode = builder.retryMode();
if (retryMode != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, AwsRetryStrategy.forRetryMode(retryMode));
} else {
Consumer> configurator = builder.retryStrategyConfigurator();
if (configurator != null) {
RetryStrategy.Builder, ?> defaultBuilder = AwsRetryStrategy.defaultRetryStrategy().toBuilder();
configurator.accept(defaultBuilder);
configuration.option(SdkClientOption.RETRY_STRATEGY, defaultBuilder.build());
} else {
RetryStrategy retryStrategy = builder.retryStrategy();
if (retryStrategy != null) {
configuration.option(SdkClientOption.RETRY_STRATEGY, retryStrategy);
}
}
}
configuration.option(SdkClientOption.CONFIGURED_RETRY_MODE, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_STRATEGY, null);
configuration.option(SdkClientOption.CONFIGURED_RETRY_CONFIGURATOR, null);
}
private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) {
List plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList());
SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();
if (plugins.isEmpty()) {
return configuration.build();
}
SsoOidcServiceClientConfigurationBuilder serviceConfigBuilder = new SsoOidcServiceClientConfigurationBuilder(
configuration);
for (SdkPlugin plugin : plugins) {
plugin.configureClient(serviceConfigBuilder);
}
updateRetryStrategyClientConfiguration(configuration);
return configuration.build();
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata) {
return protocolFactory.createErrorResponseHandler(operationMetadata);
}
private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
JsonOperationMetadata operationMetadata, Function> exceptionMetadataMapper) {
return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper);
}
@Override
public void close() {
clientHandler.close();
}
}