All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.s3.S3ClientOptions Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with Amazon Simple Storage Service

The newest version!
/*
 * Copyright 2010-2024 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.SdkClientException;

/**
 * S3 client configuration options such as the request access style.
 */
public class S3ClientOptions {

    /** The default setting for use of path-style access */
    public static final boolean DEFAULT_PATH_STYLE_ACCESS = false;
    /** The default setting for use of chunked encoding */
    public static final boolean DEFAULT_CHUNKED_ENCODING_DISABLED = false;
    /** The default setting for use of payload signing */
    public static final boolean DEFAULT_PAYLOAD_SIGNING_ENABLED = false;
    /** S3 accelerate is by default not enabled */
    public static final boolean DEFAULT_ACCELERATE_MODE_ENABLED = false;
    /** S3 dualstack endpoint is by default not enabled */
    public static final boolean DEFAULT_DUALSTACK_ENABLED = false;
    /** By default, clients should be created with a region. */
    public static final boolean DEFAULT_FORCE_GLOBAL_BUCKET_ACCESS_ENABLED = false;
    /** By default, clients will not allow a call to a different region that has been specified in an ARN */
    public static final boolean DEFAULT_USE_ARN_REGION = false;
    /** By default, region us-east-1 translates to the global endpoint */
    public static final boolean DEFAULT_US_EAST_1_REGION_ENDPOINT_ENABLED = false;

    /*
     * TODO: make it final after we remove the deprecated setters.
     */
    private boolean pathStyleAccess;
    private boolean chunkedEncodingDisabled;
    private final boolean accelerateModeEnabled;
    private final boolean payloadSigningEnabled;
    private final boolean dualstackEnabled;
    private final boolean forceGlobalBucketAccessEnabled;
    private final boolean useArnRegion;
    private final boolean regionalUsEast1EndpointEnabled;

    /**
     * @return a new S3ClientOptions builder.
     */
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private boolean pathStyleAccess = DEFAULT_PATH_STYLE_ACCESS;
        /** Flag for user of chunked encoding */
        private boolean chunkedEncodingDisabled = DEFAULT_CHUNKED_ENCODING_DISABLED;
        private boolean accelerateModeEnabled = DEFAULT_ACCELERATE_MODE_ENABLED;
        private boolean payloadSigningEnabled = DEFAULT_PAYLOAD_SIGNING_ENABLED;
        private boolean dualstackEnabled = DEFAULT_DUALSTACK_ENABLED;
        private boolean forceGlobalBucketAccessEnabled = DEFAULT_FORCE_GLOBAL_BUCKET_ACCESS_ENABLED;
        private Boolean useArnRegion = null;
        private boolean regionalUsEast1EndpointEnabled = DEFAULT_US_EAST_1_REGION_ENDPOINT_ENABLED;

        private Builder() {}

        public S3ClientOptions build() {
            if (pathStyleAccess && accelerateModeEnabled) {
                throw new SdkClientException("Both accelerate mode and path style access are being enabled either through "
                                             + "S3ClientOptions or AmazonS3ClientBuilder. These options are mutually exclusive "
                                             + "and cannot be enabled together. Please disable one of them");
            }

            return new S3ClientOptions(this);
        }
        /**
         * 

* 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. *

* * @param pathStyleAccess * True to always use path-style access. * @return this Builder instance that can be used for method chaining */ public Builder setPathStyleAccess(boolean pathStyleAccess) { this.pathStyleAccess = pathStyleAccess; return this; } /** *

* 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. *

* * @see AmazonS3#setBucketAccelerateConfiguration(com.amazonaws.services.s3.model.SetBucketAccelerateConfigurationRequest) */ public Builder setAccelerateModeEnabled(boolean accelerateModeEnabled) { this.accelerateModeEnabled = accelerateModeEnabled; return this; } /** *

* 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. *

* * @param payloadSigningEnabled * True to explicitly enable payload signing in all situations */ public Builder setPayloadSigningEnabled(boolean payloadSigningEnabled) { this.payloadSigningEnabled = payloadSigningEnabled; return this; } /** *

* 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. *

* * @return this Builder instance that can be used for method chaining */ public Builder disableChunkedEncoding() { this.chunkedEncodingDisabled = true; return this; } /** *

* Configures the client to use the dualstack endpoint for a region *

* S3 supports dualstack endpoints which return both IPv6 and IPv4 values. * Use of these endpoints is optional. *

* * @return this Builder instance that can be used for method chaining */ public Builder enableDualstack() { this.dualstackEnabled = true; return this; } /** *

* Force-enable global bucket access on the S3 client. Any bucket-related operations invoked against a client * with this option enabled will potentially be executed against other regions than the one configured in the * client in order to succeed. *

* * @see AmazonS3ClientBuilder#setForceGlobalBucketAccessEnabled(Boolean) * @return this Builder instance that can be used for method chaining */ public Builder enableForceGlobalBucketAccess() { this.forceGlobalBucketAccessEnabled = true; return this; } /** *

* If global bucket access is not enabled, this setting will enable the client to make calls to a region * specified in an ARN that represents an S3 resource even if that region is different to the region the client * was initialized with. This setting is disabled by default. *

* * @return this Builder instance that can be used for method chaining */ public Builder enableUseArnRegion() { this.useArnRegion = true; return this; } /** *

* Enable resolving region us-east-1 as a regional endpoint instead of defaulting to the global endpoint. *

* * @see AmazonS3ClientBuilder#setRegionalUsEast1EndpointEnabled(Boolean) * @return this Builder instance that can be used for method chaining */ public Builder enableRegionalUsEast1Endpoint() { this.regionalUsEast1EndpointEnabled = true; return this; } } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public S3ClientOptions() { this.pathStyleAccess = DEFAULT_PATH_STYLE_ACCESS; this.chunkedEncodingDisabled = DEFAULT_CHUNKED_ENCODING_DISABLED; this.accelerateModeEnabled = DEFAULT_ACCELERATE_MODE_ENABLED; this.payloadSigningEnabled = DEFAULT_PAYLOAD_SIGNING_ENABLED; this.dualstackEnabled = DEFAULT_DUALSTACK_ENABLED; this.forceGlobalBucketAccessEnabled = DEFAULT_FORCE_GLOBAL_BUCKET_ACCESS_ENABLED; this.useArnRegion = DEFAULT_USE_ARN_REGION; this.regionalUsEast1EndpointEnabled = DEFAULT_US_EAST_1_REGION_ENDPOINT_ENABLED; } /** * @deprecated Will be removed once S3ClientOptions is made an immutable * class. */ @Deprecated public S3ClientOptions( S3ClientOptions other ) { this.pathStyleAccess = other.pathStyleAccess; this.chunkedEncodingDisabled = other.chunkedEncodingDisabled; this.accelerateModeEnabled = other.accelerateModeEnabled; this.payloadSigningEnabled = other.payloadSigningEnabled; this.dualstackEnabled = other.dualstackEnabled; this.forceGlobalBucketAccessEnabled = other.forceGlobalBucketAccessEnabled; this.useArnRegion = other.useArnRegion; this.regionalUsEast1EndpointEnabled = other.regionalUsEast1EndpointEnabled; } private S3ClientOptions(Builder b) { this.pathStyleAccess = b.pathStyleAccess; this.chunkedEncodingDisabled = b.chunkedEncodingDisabled; this.accelerateModeEnabled = b.accelerateModeEnabled; this.payloadSigningEnabled = b.payloadSigningEnabled; this.dualstackEnabled = b.dualstackEnabled; this.forceGlobalBucketAccessEnabled = b.forceGlobalBucketAccessEnabled; this.useArnRegion = Boolean.TRUE.equals(b.useArnRegion); this.regionalUsEast1EndpointEnabled = b.regionalUsEast1EndpointEnabled; } /** *

* Returns whether the client uses 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. *

* @return True is the client should always use path-style access */ public boolean isPathStyleAccess() { return pathStyleAccess; } /** *

* Returns whether the client has chunked encoding disabled 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. *

* * @return True if chunked encoding is explicitly disabled for all requests */ public boolean isChunkedEncodingDisabled() { return chunkedEncodingDisabled; } /** *

* Returns whether the client has enabled accelerate mode for getting and putting objects. *

*

* The default behavior is to disable accelerate mode for any operations (GET, PUT, DELETE). You need to call * {@link com.amazonaws.services.s3.AmazonS3Client#setBucketAccelerateConfiguration(com.amazonaws.services.s3.model.SetBucketAccelerateConfigurationRequest)} * first to use this feature. *

* * @return True if accelerate mode is enabled. */ public boolean isAccelerateModeEnabled() { return accelerateModeEnabled; } /** *

* Returns whether the client is configured 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. *

* * @return True if body signing is explicitly enabled for all requests */ public boolean isPayloadSigningEnabled() { return payloadSigningEnabled; } /** *

* Returns whether the client is configured to use dualstack mode for * accessing S3. *

* * @return True if the client will use the dualstack mode */ public boolean isDualstackEnabled() { return dualstackEnabled; } /** *

* Returns whether the client should be configured with global bucket access enabled. *

* @see Builder#enableForceGlobalBucketAccess() */ public boolean isForceGlobalBucketAccessEnabled() { return this.forceGlobalBucketAccessEnabled; } /** *

* Returns whether the client should be configured to allow calls to different regions specified in an ARN. *

* @see Builder#enableUseArnRegion() */ public boolean isUseArnRegion() { return this.useArnRegion; } /** *

* Returns whether the client has enabled resolving us-east-1 to a regional endpoint. *

* * @return True if regional endpoint translation is enabled */ public boolean isRegionalUsEast1EndpointEnabled() { return this.regionalUsEast1EndpointEnabled; } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public void setPathStyleAccess(boolean pathStyleAccess) { this.pathStyleAccess = pathStyleAccess; } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public S3ClientOptions withPathStyleAccess(boolean pathStyleAccess) { setPathStyleAccess(pathStyleAccess); return this; } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public void setChunkedEncodingDisabled(boolean chunkedEncodingDisabled) { this.chunkedEncodingDisabled = chunkedEncodingDisabled; } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public S3ClientOptions withChunkedEncodingDisabled(boolean chunkedEncodingDisabled) { setChunkedEncodingDisabled(chunkedEncodingDisabled); return this; } /** * @deprecated Use {@link S3ClientOptions#builder()} to build new * S3ClientOptions instead. */ @Deprecated public S3ClientOptions disableChunkedEncoding() { return withChunkedEncodingDisabled(true); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy