1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.core.client.config;
17 
18 import java.net.URI;
19 import java.time.Duration;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.concurrent.ScheduledExecutorService;
23 import java.util.function.Supplier;
24 import software.amazon.awssdk.annotations.SdkProtectedApi;
25 import software.amazon.awssdk.core.ClientType;
26 import software.amazon.awssdk.core.CompressionConfiguration;
27 import software.amazon.awssdk.core.SdkClient;
28 import software.amazon.awssdk.core.ServiceConfiguration;
29 import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
30 import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
31 import software.amazon.awssdk.core.retry.RetryMode;
32 import software.amazon.awssdk.core.retry.RetryPolicy;
33 import software.amazon.awssdk.endpoints.EndpointProvider;
34 import software.amazon.awssdk.http.SdkHttpClient;
35 import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
36 import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme;
37 import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeProvider;
38 import software.amazon.awssdk.identity.spi.IdentityProviders;
39 import software.amazon.awssdk.metrics.MetricPublisher;
40 import software.amazon.awssdk.profiles.ProfileFile;
41 import software.amazon.awssdk.utils.AttributeMap;
42 
43 /**
44  * A set of internal options required by the SDK via {@link SdkClientConfiguration}.
45  */
46 @SdkProtectedApi
47 public final class SdkClientOption<T> extends ClientOption<T> {
48     /**
49      * @see ClientOverrideConfiguration#headers()
50      */
51     public static final SdkClientOption<Map<String, List<String>>> ADDITIONAL_HTTP_HEADERS =
52             new SdkClientOption<>(new UnsafeValueType(Map.class));
53 
54     /**
55      * @see ClientOverrideConfiguration#retryPolicy()
56      */
57     public static final SdkClientOption<RetryPolicy> RETRY_POLICY = new SdkClientOption<>(RetryPolicy.class);
58 
59     /**
60      * @see ClientOverrideConfiguration#executionInterceptors()
61      */
62     public static final SdkClientOption<List<ExecutionInterceptor>> EXECUTION_INTERCEPTORS =
63             new SdkClientOption<>(new UnsafeValueType(List.class));
64 
65     /**
66      * The effective endpoint the client is configured to make requests to. If the client has been configured with
67      * an endpoint override then this value will be the provided endpoint value.
68      */
69     public static final SdkClientOption<URI> ENDPOINT = new SdkClientOption<>(URI.class);
70 
71     /**
72      * A flag that when set to true indicates the endpoint stored in {@link SdkClientOption#ENDPOINT} was a customer
73      * supplied value and not generated by the client based on Region metadata.
74      */
75     public static final SdkClientOption<Boolean> ENDPOINT_OVERRIDDEN = new SdkClientOption<>(Boolean.class);
76 
77     /**
78      * Service-specific configuration used by some services, like S3.
79      */
80     public static final SdkClientOption<ServiceConfiguration> SERVICE_CONFIGURATION =
81             new SdkClientOption<>(ServiceConfiguration.class);
82 
83     /**
84      * Whether to calculate the CRC 32 checksum of a message based on the uncompressed data. By default, this is false.
85      */
86     public static final SdkClientOption<Boolean> CRC32_FROM_COMPRESSED_DATA_ENABLED =
87         new SdkClientOption<>(Boolean.class);
88 
89     /**
90      * The internal SDK scheduled executor service that is used for scheduling tasks such as async retry attempts
91      * and timeout task.
92      */
93     public static final SdkClientOption<ScheduledExecutorService> SCHEDULED_EXECUTOR_SERVICE =
94             new SdkClientOption<>(ScheduledExecutorService.class);
95 
96     /**
97      * The internal SDK scheduled executor service that is set by the customer. This is likely only useful within configuration
98      * classes, and will be converted into a {@link #SCHEDULED_EXECUTOR_SERVICE} for the SDK's runtime.
99      */
100     public static final SdkClientOption<ScheduledExecutorService> CONFIGURED_SCHEDULED_EXECUTOR_SERVICE =
101         new SdkClientOption<>(ScheduledExecutorService.class);
102 
103     /**
104      * The asynchronous HTTP client implementation to make HTTP requests with.
105      */
106     public static final SdkClientOption<SdkAsyncHttpClient> ASYNC_HTTP_CLIENT =
107             new SdkClientOption<>(SdkAsyncHttpClient.class);
108 
109     /**
110      * An asynchronous HTTP client set by the customer. This is likely only useful within configuration classes, and
111      * will be converted into a {@link #ASYNC_HTTP_CLIENT} for the SDK's runtime.
112      */
113     public static final SdkClientOption<SdkAsyncHttpClient> CONFIGURED_ASYNC_HTTP_CLIENT =
114         new SdkClientOption<>(SdkAsyncHttpClient.class);
115 
116     /**
117      * An asynchronous HTTP client builder set by the customer. This is likely only useful within configuration classes, and
118      * will be converted into a {@link #ASYNC_HTTP_CLIENT} for the SDK's runtime.
119      */
120     public static final SdkClientOption<SdkAsyncHttpClient.Builder<?>> CONFIGURED_ASYNC_HTTP_CLIENT_BUILDER =
121         new SdkClientOption<>(new UnsafeValueType(SdkAsyncHttpClient.Builder.class));
122 
123     /**
124      * The HTTP client implementation to make HTTP requests with.
125      */
126     public static final SdkClientOption<SdkHttpClient> SYNC_HTTP_CLIENT =
127             new SdkClientOption<>(SdkHttpClient.class);
128 
129     /**
130      * An HTTP client set by the customer. This is likely only useful within configuration classes, and
131      * will be converted into a {@link #SYNC_HTTP_CLIENT} for the SDK's runtime.
132      */
133     public static final SdkClientOption<SdkHttpClient> CONFIGURED_SYNC_HTTP_CLIENT =
134         new SdkClientOption<>(SdkHttpClient.class);
135 
136     /**
137      * An HTTP client builder set by the customer. This is likely only useful within configuration classes, and
138      * will be converted into a {@link #SYNC_HTTP_CLIENT} for the SDK's runtime.
139      */
140     public static final SdkClientOption<SdkHttpClient.Builder<?>> CONFIGURED_SYNC_HTTP_CLIENT_BUILDER =
141         new SdkClientOption<>(new UnsafeValueType(SdkAsyncHttpClient.Builder.class));
142 
143     /**
144      * Configuration that should be used to build the {@link #SYNC_HTTP_CLIENT} or {@link #ASYNC_HTTP_CLIENT}.
145      */
146     public static final SdkClientOption<AttributeMap> HTTP_CLIENT_CONFIG = new SdkClientOption<>(AttributeMap.class);
147 
148     /**
149      * The type of client used to make requests.
150      */
151     public static final SdkClientOption<ClientType> CLIENT_TYPE = new SdkClientOption<>(ClientType.class);
152 
153     /**
154      * @see ClientOverrideConfiguration#apiCallAttemptTimeout()
155      */
156     public static final SdkClientOption<Duration> API_CALL_ATTEMPT_TIMEOUT = new SdkClientOption<>(Duration.class);
157 
158     /**
159      * @see ClientOverrideConfiguration#apiCallTimeout()
160      */
161     public static final SdkClientOption<Duration> API_CALL_TIMEOUT = new SdkClientOption<>(Duration.class);
162 
163     /**
164      * Descriptive name for the service. Used primarily for metrics and also in metadata like AwsErrorDetails.
165      */
166     public static final SdkClientOption<String> SERVICE_NAME = new SdkClientOption<>(String.class);
167 
168     /**
169      * Whether or not endpoint discovery is enabled for this client.
170      */
171     public static final SdkClientOption<Boolean> ENDPOINT_DISCOVERY_ENABLED = new SdkClientOption<>(Boolean.class);
172 
173     /**
174      * The profile file to use for this client.
175      *
176      * @deprecated This option was used to:
177      *             - Read configuration options in profile files in aws-core, sdk-core
178      *             - Build service configuration objects from profile files in codegen, s3control
179      *             - Build service configuration objects from profile files, set endpoint options in s3
180      *             - Set retry mode in dynamodb, kinesis
181      * This has been replaced with {@code PROFILE_FILE_SUPPLIER.get()}.
182      */
183     @Deprecated
184     public static final SdkClientOption<ProfileFile> PROFILE_FILE = new SdkClientOption<>(ProfileFile.class);
185 
186     /**
187      * The profile file supplier to use for this client.
188      */
189     public static final SdkClientOption<Supplier<ProfileFile>> PROFILE_FILE_SUPPLIER =
190         new SdkClientOption<>(new UnsafeValueType(Supplier.class));
191 
192     /**
193      * The profile name to use for this client.
194      */
195     public static final SdkClientOption<String> PROFILE_NAME = new SdkClientOption<>(String.class);
196 
197     public static final SdkClientOption<List<MetricPublisher>> METRIC_PUBLISHERS =
198             new SdkClientOption<>(new UnsafeValueType(List.class));
199 
200     /**
201      * Option to specify if the default signer has been overridden on the client.
202      */
203     public static final SdkClientOption<Boolean> SIGNER_OVERRIDDEN = new SdkClientOption<>(Boolean.class);
204 
205     /**
206      * Option to specify additional execution attributes to each client call.
207      */
208     public static final SdkClientOption<ExecutionAttributes> EXECUTION_ATTRIBUTES =
209             new SdkClientOption<>(new UnsafeValueType(ExecutionAttributes.class));
210     /**
211      * Option to specify the internal user agent.
212      */
213     public static final SdkClientOption<String> INTERNAL_USER_AGENT = new SdkClientOption<>(String.class);
214 
215     /**
216      * A user agent prefix that is specific to the client (agnostic of the request).
217      */
218     public static final SdkClientOption<String> CLIENT_USER_AGENT = new SdkClientOption<>(String.class);
219 
220     /**
221      * Option to specify the default retry mode.
222      *
223      * @see RetryMode.Resolver#defaultRetryMode(RetryMode)
224      */
225     public static final SdkClientOption<RetryMode> DEFAULT_RETRY_MODE = new SdkClientOption<>(RetryMode.class);
226 
227     /**
228      * The {@link EndpointProvider} configured on the client.
229      */
230     public static final SdkClientOption<EndpointProvider> ENDPOINT_PROVIDER = new SdkClientOption<>(EndpointProvider.class);
231 
232     /**
233      * The {@link AuthSchemeProvider} configured on the client.
234      */
235     public static final SdkClientOption<AuthSchemeProvider> AUTH_SCHEME_PROVIDER =
236         new SdkClientOption<>(AuthSchemeProvider.class);
237 
238     /**
239      * The {@link AuthScheme}s configured on the client.
240      */
241     public static final SdkClientOption<Map<String, AuthScheme<?>>> AUTH_SCHEMES =
242         new SdkClientOption<>(new UnsafeValueType(Map.class));
243 
244     /**
245      * The IdentityProviders configured on the client.
246      */
247     public static final SdkClientOption<IdentityProviders> IDENTITY_PROVIDERS = new SdkClientOption<>(IdentityProviders.class);
248 
249     /**
250      * The container for any client contexts parameters set on the client.
251      */
252     public static final SdkClientOption<AttributeMap> CLIENT_CONTEXT_PARAMS =
253         new SdkClientOption<>(AttributeMap.class);
254 
255     /**
256      * Configuration of the COMPRESSION_CONFIGURATION. Unlike {@link #COMPRESSION_CONFIGURATION}, this may contain null values.
257      */
258     public static final SdkClientOption<CompressionConfiguration> CONFIGURED_COMPRESSION_CONFIGURATION =
259         new SdkClientOption<>(CompressionConfiguration.class);
260 
261     /**
262      * Option used by the rest of the SDK to read the {@link CompressionConfiguration}. This will never contain null values.
263      */
264     public static final SdkClientOption<CompressionConfiguration> COMPRESSION_CONFIGURATION =
265         new SdkClientOption<>(CompressionConfiguration.class);
266 
267     /**
268      * Option to specify a reference to the SDK client in use.
269      */
270     public static final SdkClientOption<SdkClient> SDK_CLIENT = new SdkClientOption<>(SdkClient.class);
271 
SdkClientOption(Class<T> valueClass)272     private SdkClientOption(Class<T> valueClass) {
273         super(valueClass);
274     }
275 
SdkClientOption(UnsafeValueType valueType)276     private SdkClientOption(UnsafeValueType valueType) {
277         super(valueType);
278     }
279 }
280