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.services.s3.internal.client; 17 18 import java.util.ArrayList; 19 import java.util.List; 20 import java.util.function.Predicate; 21 import software.amazon.awssdk.annotations.SdkInternalApi; 22 import software.amazon.awssdk.core.client.config.SdkClientConfiguration; 23 import software.amazon.awssdk.core.client.config.SdkClientOption; 24 import software.amazon.awssdk.services.s3.S3Client; 25 import software.amazon.awssdk.services.s3.endpoints.S3ClientContextParams; 26 import software.amazon.awssdk.services.s3.internal.crossregion.S3CrossRegionSyncClient; 27 import software.amazon.awssdk.utils.AttributeMap; 28 import software.amazon.awssdk.utils.ConditionalDecorator; 29 30 @SdkInternalApi 31 public class S3SyncClientDecorator { 32 S3SyncClientDecorator()33 public S3SyncClientDecorator() { 34 } 35 decorate(S3Client base, SdkClientConfiguration clientConfiguration)36 public S3Client decorate(S3Client base, 37 SdkClientConfiguration clientConfiguration) { 38 AttributeMap clientContextParams = clientConfiguration.option(SdkClientOption.CLIENT_CONTEXT_PARAMS); 39 List<ConditionalDecorator<S3Client>> decorators = new ArrayList<>(); 40 decorators.add(ConditionalDecorator.create(isCrossRegionEnabledSync(clientContextParams), 41 S3CrossRegionSyncClient::new)); 42 43 return ConditionalDecorator.decorate(base, decorators); 44 } 45 isCrossRegionEnabledSync(AttributeMap clientContextParams)46 private Predicate<S3Client> isCrossRegionEnabledSync(AttributeMap clientContextParams) { 47 Boolean crossRegionEnabled = clientContextParams.get(S3ClientContextParams.CROSS_REGION_ACCESS_ENABLED); 48 return client -> crossRegionEnabled != null && crossRegionEnabled.booleanValue(); 49 } 50 } 51