/*
* Copyright 2011-2023 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 com.amazonaws.services.s3;
import com.amazonaws.ClientConfigurationFactory;
import com.amazonaws.annotation.NotThreadSafe;
import com.amazonaws.annotation.SdkTestInternalApi;
import com.amazonaws.client.builder.AwsSyncClientBuilder;
import com.amazonaws.internal.SdkFunction;
import com.amazonaws.regions.AwsRegionProvider;
import com.amazonaws.services.s3.model.CreateBucketRequest;
import com.amazonaws.services.s3.model.PutObjectRequest;
@NotThreadSafe
public abstract class AmazonS3Builder Configures the client to use path-style access for all requests. Amazon S3 supports virtual-hosted-style and path-style access in all Regions. The
* path-style syntax, however, requires that you use the region-specific endpoint when
* attempting to access a bucket. The default behaviour is to detect which access style to use based on the configured
* endpoint (an IP will result in path-style access) and the bucket being accessed (some buckets
* are not valid DNS names). Setting this flag will result in path-style access being used for
* all requests. Configures the client to use path-style access for all requests. Amazon S3 supports virtual-hosted-style and path-style access in all Regions. The
* path-style syntax, however, requires that you use the region-specific endpoint when
* attempting to access a bucket. The default behaviour is to detect which access style to use based on the configured
* endpoint (an IP will result in path-style access) and the bucket being accessed (some buckets
* are not valid DNS names). Setting this flag will result in path-style access being used for
* all requests. Enables path style access for clients built via this builder. Amazon S3 supports virtual-hosted-style and path-style access in all Regions. The
* path-style syntax, however, requires that you use the region-specific endpoint when
* attempting to access a bucket. The default behaviour is to detect which access style to use based on the configured
* endpoint (an IP will result in path-style access) and the bucket being accessed (some buckets
* are not valid DNS names). Setting this flag will result in path-style access being used for
* all requests. Configures the client to disable chunked encoding for all requests. The default behavior is to enable chunked encoding automatically for PutObjectRequest and
* UploadPartRequest. Setting this flag will result in disabling chunked encoding for all
* requests. Note: Enabling this option has performance implications since the checksum for the
* payload will have to be pre-calculated before sending the data. If your payload is large this
* will affect the overall time required to upload an object. Using this option is recommended
* only if your endpoint does not implement chunked uploading. Configures the client to disable chunked encoding for all requests. The default behavior is to enable chunked encoding automatically for PutObjectRequest and
* UploadPartRequest. Setting this flag will result in disabling chunked encoding for all
* requests. Note: Enabling this option has performance implications since the checksum for the
* payload will have to be pre-calculated before sending the data. If your payload is large this
* will affect the overall time required to upload an object. Using this option is recommended
* only if your endpoint does not implement chunked uploading. Disables chunked encoding on clients built via the builder. The default behavior is to enable chunked encoding automatically for PutObjectRequest and
* UploadPartRequest. Setting this flag will result in disabling chunked encoding for all
* requests. Note: Enabling this option has performance implications since the checksum for the
* payload will have to be pre-calculated before sending the data. If your payload is large this
* will affect the overall time required to upload an object. Using this option is recommended
* only if your endpoint does not implement chunked uploading. Configures the client to use S3 accelerate endpoint for all requests. A bucket by default cannot be accessed in accelerate mode. If you wish to do so, you need
* to enable the accelerate configuration for the bucket in advance. To enable accelerate mode
* see {@link com.amazonaws.services.s3.AmazonS3Client#setBucketAccelerateConfiguration(com.amazonaws.services.s3.model.SetBucketAccelerateConfigurationRequest)}.
* Configures the client to use S3 accelerate endpoint for all requests. A bucket by default cannot be accessed in accelerate mode. If you wish to do so, you need
* to enable the accelerate configuration for the bucket in advance. To enable accelerate mode
* see {@link com.amazonaws.services.s3.AmazonS3Client#setBucketAccelerateConfiguration(com.amazonaws.services.s3.model.SetBucketAccelerateConfigurationRequest)}.
* Enables accelerate mode on clients built with the builder. A bucket by default cannot be accessed in accelerate mode. If you wish to do so, you need
* to enable the accelerate configuration for the bucket in advance. To enable accelerate mode
* see {@link com.amazonaws.services.s3.AmazonS3Client#setBucketAccelerateConfiguration(com.amazonaws.services.s3.model.SetBucketAccelerateConfigurationRequest)}.
* Configures the client to sign payloads in all situations. Payload signing is optional when chunked encoding is not used and requests are made
* against an HTTPS endpoint. Under these conditions the client will by default opt to not sign
* payloads to optimize performance. If this flag is set to true the client will instead always
* sign payloads. Note: Payload signing can be expensive, particularly if transferring large payloads
* in a single chunk. Enabling this option will result in a performance penalty. Configures the client to sign payloads in all situations. Payload signing is optional when chunked encoding is not used and requests are made
* against an HTTPS endpoint. Under these conditions the client will by default opt to not sign
* payloads to optimize performance. If this flag is set to true the client will instead always
* sign payloads. Note: Payload signing can be expensive, particularly if transferring large payloads
* in a single chunk. Enabling this option will result in a performance penalty. Enables payload signing for all situations on clients built via this builder. Payload signing is optional when chunked encoding is not used and requests are made
* against an HTTPS endpoint. Under these conditions the client will by default opt to not sign
* payloads to optimize performance. If this flag is set to true the client will instead always
* sign payloads. Note: Payload signing can be expensive, particularly if transferring large payloads
* in a single chunk. Enabling this option will result in a performance penalty. Configures the client to use Amazon S3 dualstack mode for all requests. Configures the client to use Amazon S3 dualstack mode for all requests. Enables dualstack mode on clients built with the builder. Configure whether global bucket access is enabled for clients generated by this builder. When global bucket access is enabled, the region to which a request is routed may differ from the region that
* is configured in {@link #setRegion(String)} in order to make the request succeed.
* The following behavior is currently used when this mode is enabled:
*
*
*
Enabling this mode has several drawbacks, because it has the potential to increase latency in the event that * the location of the bucket is physically far from the location from which the request was invoked. For this * reason, it is strongly advised when possible to know the location of your buckets and create a region-specific * client to access that bucket.
* * @param forceGlobalBucketAccessEnabled Whether global bucket access should be enabled. */ public void setForceGlobalBucketAccessEnabled(Boolean forceGlobalBucketAccessEnabled) { this.forceGlobalBucketAccessEnabled = forceGlobalBucketAccessEnabled; } /** *Configure whether global bucket access is enabled for clients generated by this builder.
* * @see #setForceGlobalBucketAccessEnabled(Boolean) * @param forceGlobalBucketAccessEnabled Whether global bucket access should be enabled. * @return This object for method chaining. */ public Subclass withForceGlobalBucketAccessEnabled(Boolean forceGlobalBucketAccessEnabled) { setForceGlobalBucketAccessEnabled(forceGlobalBucketAccessEnabled); return getSubclass(); } /** *Enable global bucket access for clients generated by this builder.
* * @see #setForceGlobalBucketAccessEnabled(Boolean) * @return This object for method chaining. */ public Subclass enableForceGlobalBucketAccess() { setForceGlobalBucketAccessEnabled(Boolean.TRUE); return getSubclass(); } /** * @return The current setting for useArnRegion mode configured in the builder. */ public Boolean isUseArnRegionEnabled() { return useArnRegionEnabled; } /** *Enables using the region from ARNs on clients built with the builder.
* @return This object for method chaining. */ public Subclass enableUseArnRegion() { this.useArnRegionEnabled = true; return getSubclass(); } /** * @return Whether us-east-1 should resolve to its regional endpoint or the default global endpoint. * @see #setRegionalUsEast1EndpointEnabled(Boolean) */ public Boolean isRegionalUsEast1EndpointEnabled() { return regionalUsEast1EndpointEnabled; } /** *Configures the client to resolve region us-east-1 region to its regional endpoint instead of the * global endpoint for all requests.
* *The default value for this value is false, configuring this region resolve to the global s3 endpoint.
* ** There are three ways to enable this option. In order of precedence: *
Configures the client to resolve region us-east-1 region to its regional endpoint instead of the * global endpoint for all requests.
* * @param regionalUsEast1EndpointEnabled True to enable us-east-1 regional mode. * @return This object for method chaining. * @see #setRegionalUsEast1EndpointEnabled(Boolean) */ public Subclass withRegionalUsEast1EndpointEnabled(Boolean regionalUsEast1EndpointEnabled) { setRegionalUsEast1EndpointEnabled(regionalUsEast1EndpointEnabled); return getSubclass(); } /** *Enables us-east-1 regional mode on clients built with the builder.
* @return This object for method chaining. */ public Subclass enableRegionalUsEast1Endpoint() { setRegionalUsEast1EndpointEnabled(Boolean.TRUE); return getSubclass(); } protected S3ClientOptions resolveS3ClientOptions() { final S3ClientOptions.Builder builder = S3ClientOptions.builder(); if (Boolean.TRUE.equals(this.chunkedEncodingDisabled)) { builder.disableChunkedEncoding(); } if (this.payloadSigningEnabled != null) { builder.setPayloadSigningEnabled(this.payloadSigningEnabled); } if (this.accelerateModeEnabled != null) { builder.setAccelerateModeEnabled(this.accelerateModeEnabled); } if (this.pathStyleAccessEnabled != null) { builder.setPathStyleAccess(this.pathStyleAccessEnabled); } if(Boolean.TRUE.equals(this.dualstackEnabled)) { builder.enableDualstack(); } if(Boolean.TRUE.equals(this.forceGlobalBucketAccessEnabled)) { builder.enableForceGlobalBucketAccess(); } if(Boolean.TRUE.equals(this.useArnRegionEnabled)) { builder.enableUseArnRegion(); } if(Boolean.TRUE.equals(this.regionalUsEast1EndpointEnabled)) { builder.enableRegionalUsEast1Endpoint(); } return builder.build(); } }