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;
17 
18 import software.amazon.awssdk.annotations.SdkProtectedApi;
19 import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
20 import software.amazon.awssdk.core.retry.RetryMode;
21 import software.amazon.awssdk.core.retry.RetryPolicy;
22 import software.amazon.awssdk.utils.SystemSetting;
23 
24 /**
25  * System properties to configure the SDK runtime.
26  */
27 @SdkProtectedApi
28 public enum SdkSystemSetting implements SystemSetting {
29     /**
30      * Configure the AWS access key ID.
31      *
32      * This value will not be ignored if the {@link #AWS_SECRET_ACCESS_KEY} is not specified.
33      */
34     AWS_ACCESS_KEY_ID("aws.accessKeyId", null),
35 
36     /**
37      * Configure the AWS secret access key.
38      *
39      * This value will not be ignored if the {@link #AWS_ACCESS_KEY_ID} is not specified.
40      */
41     AWS_SECRET_ACCESS_KEY("aws.secretAccessKey", null),
42 
43     /**
44      * Configure the AWS session token.
45      */
46     AWS_SESSION_TOKEN("aws.sessionToken", null),
47 
48     /**
49      * Configure the AWS web identity token file path.
50      */
51     AWS_WEB_IDENTITY_TOKEN_FILE("aws.webIdentityTokenFile", null),
52 
53     /**
54      * Configure the AWS role arn.
55      */
56     AWS_ROLE_ARN("aws.roleArn", null),
57 
58     /**
59      * Configure the session name for a role.
60      */
61     AWS_ROLE_SESSION_NAME("aws.roleSessionName", null),
62 
63     /**
64      * Configure the default region.
65      */
66     AWS_REGION("aws.region", null),
67 
68     /**
69      * Whether to load information such as credentials, regions from EC2 Metadata instance service.
70      */
71     AWS_EC2_METADATA_DISABLED("aws.disableEc2Metadata", "false"),
72 
73     /**
74      * Whether to disable fallback to insecure EC2 Metadata instance service v1 on errors or timeouts.
75      */
76     AWS_EC2_METADATA_V1_DISABLED("aws.disableEc2MetadataV1", null),
77 
78     /**
79      * The EC2 instance metadata service endpoint.
80      *
81      * This allows a service running in EC2 to automatically load its credentials and region without needing to configure them
82      * in the SdkClientBuilder.
83      */
84     AWS_EC2_METADATA_SERVICE_ENDPOINT("aws.ec2MetadataServiceEndpoint", "http://169.254.169.254"),
85 
86     AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE("aws.ec2MetadataServiceEndpointMode", "IPv4"),
87 
88     /**
89      * The elastic container metadata service endpoint that should be called by the ContainerCredentialsProvider
90      * when loading data from the container metadata service.
91      *
92      * This allows a service running in an elastic container to automatically load its credentials without needing to configure
93      * them in the SdkClientBuilder.
94      *
95      * This is not used if the {@link #AWS_CONTAINER_CREDENTIALS_RELATIVE_URI} is not specified.
96      */
97     AWS_CONTAINER_SERVICE_ENDPOINT("aws.containerServiceEndpoint", "http://169.254.170.2"),
98 
99     /**
100      * The elastic container metadata service path that should be called by the ContainerCredentialsProvider when
101      * loading credentials form the container metadata service. If this is not specified, credentials will not be automatically
102      * loaded from the container metadata service.
103      *
104      * @see #AWS_CONTAINER_SERVICE_ENDPOINT
105      */
106     AWS_CONTAINER_CREDENTIALS_RELATIVE_URI("aws.containerCredentialsPath", null),
107 
108     /**
109      * The full URI path to a localhost metadata service to be used.
110      */
111     AWS_CONTAINER_CREDENTIALS_FULL_URI("aws.containerCredentialsFullUri", null),
112 
113     /**
114      * An authorization token to pass to a container metadata service, only used when {@link #AWS_CONTAINER_CREDENTIALS_FULL_URI}
115      * is specified.
116      *
117      * @see #AWS_CONTAINER_CREDENTIALS_FULL_URI
118      */
119     AWS_CONTAINER_AUTHORIZATION_TOKEN("aws.containerAuthorizationToken", null),
120 
121     /**
122      * The absolute file path containing the authorization token in plain text to pass to a container metadata
123      * service, only used when {@link #AWS_CONTAINER_CREDENTIALS_FULL_URI} is specified.
124      * @see #AWS_CONTAINER_CREDENTIALS_FULL_URI
125      */
126     AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE("aws.containerAuthorizationTokenFile", null),
127 
128     /**
129      * Explicitly identify the default synchronous HTTP implementation the SDK will use. Useful
130      * when there are multiple implementations on the classpath or as a performance optimization
131      * since implementation discovery requires classpath scanning.
132      */
133     SYNC_HTTP_SERVICE_IMPL("software.amazon.awssdk.http.service.impl", null),
134 
135     /**
136      * Explicitly identify the default Async HTTP implementation the SDK will use. Useful
137      * when there are multiple implementations on the classpath or as a performance optimization
138      * since implementation discovery requires classpath scanning.
139      */
140     ASYNC_HTTP_SERVICE_IMPL("software.amazon.awssdk.http.async.service.impl", null),
141 
142     /**
143      * Whether CBOR optimization should automatically be used if its support is found on the classpath and the service supports
144      * CBOR-formatted JSON.
145      */
146     CBOR_ENABLED("aws.cborEnabled", "true"),
147 
148     /**
149      * Whether binary ION representation optimization should automatically be used if the service supports ION.
150      */
151     BINARY_ION_ENABLED("aws.binaryIonEnabled", "true"),
152 
153     /**
154      * The execution environment of the SDK user. This is automatically set in certain environments by the underlying AWS service.
155      * For example, AWS Lambda will automatically specify a runtime indicating that the SDK is being used within Lambda.
156      */
157     AWS_EXECUTION_ENV("aws.executionEnvironment", null),
158 
159     /**
160      * Whether endpoint discovery should be enabled.
161      */
162     AWS_ENDPOINT_DISCOVERY_ENABLED("aws.endpointDiscoveryEnabled", null),
163 
164     /**
165      * The S3 regional endpoint setting for the {@code us-east-1} region. Setting the value to {@code regional} causes
166      * the SDK to use the {@code s3.us-east-1.amazonaws.com} endpoint when using the {@code US_EAST_1} region instead of
167      * the global {@code s3.amazonaws.com}. Using the regional endpoint is disabled by default.
168      */
169     AWS_S3_US_EAST_1_REGIONAL_ENDPOINT("aws.s3UseUsEast1RegionalEndpoint", null),
170 
171     AWS_S3_DISABLE_EXPRESS_SESSION_AUTH("aws.disableS3ExpressAuth", null),
172 
173     /**
174      * Which {@link RetryMode} to use for the default {@link RetryPolicy}, when one is not specified at the client level.
175      */
176     AWS_RETRY_MODE("aws.retryMode", null),
177 
178     /**
179      * Defines the default value for {@link RetryPolicy.Builder#numRetries(Integer)}, if the retry count is not overridden in the
180      * retry policy configured via {@link ClientOverrideConfiguration.Builder#retryPolicy(RetryPolicy)}. This is one more than
181      * the number of retries, so aws.maxAttempts = 1 is 0 retries.
182      */
183     AWS_MAX_ATTEMPTS("aws.maxAttempts", null),
184 
185     /**
186      * Which {@code DefaultsMode} to use, case insensitive
187      */
188     AWS_DEFAULTS_MODE("aws.defaultsMode", null),
189 
190     /**
191      * Defines whether dualstack endpoints should be resolved during default endpoint resolution instead of non-dualstack
192      * endpoints.
193      */
194     AWS_USE_DUALSTACK_ENDPOINT("aws.useDualstackEndpoint", null),
195 
196     /**
197      * Defines whether fips endpoints should be resolved during default endpoint resolution instead of non-fips endpoints.
198      */
199     AWS_USE_FIPS_ENDPOINT("aws.useFipsEndpoint", null),
200 
201     /**
202      * Whether request compression is disabled for operations marked with the RequestCompression trait. The default value is
203      * false, i.e., request compression is enabled.
204      */
205     AWS_DISABLE_REQUEST_COMPRESSION("aws.disableRequestCompression", null),
206 
207     /**
208      * Defines the minimum compression size in bytes, inclusive, for a request to be compressed. The default value is 10_240.
209      * The value must be non-negative and no greater than 10_485_760.
210      */
211     AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES("aws.requestMinCompressionSizeBytes", null),
212 
213     ;
214 
215     private final String systemProperty;
216     private final String defaultValue;
217 
SdkSystemSetting(String systemProperty, String defaultValue)218     SdkSystemSetting(String systemProperty, String defaultValue) {
219         this.systemProperty = systemProperty;
220         this.defaultValue = defaultValue;
221     }
222 
223     @Override
property()224     public String property() {
225         return systemProperty;
226     }
227 
228     @Override
environmentVariable()229     public String environmentVariable() {
230         return name();
231     }
232 
233     @Override
defaultValue()234     public String defaultValue() {
235         return defaultValue;
236     }
237 }
238