-
Notifications
You must be signed in to change notification settings - Fork 914
[Default Configuration Part 6]: apply default s3 us-east-1 regional setting #2825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 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 software.amazon.awssdk.regions; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.core.client.config.ClientOption; | ||
|
||
|
||
/** | ||
* A collection of advanced options that can be configured on a {@link ServiceMetadata} via | ||
* {@link ServiceMetadataConfiguration.Builder#putAdvancedOption(ServiceMetadataAdvancedOption, Object)}. | ||
* | ||
* @param <T> The type of value associated with the option. | ||
*/ | ||
@SdkPublicApi | ||
public class ServiceMetadataAdvancedOption<T> extends ClientOption<T> { | ||
|
||
/** | ||
* The S3 regional endpoint setting for the {@code us-east-1} region. Setting the value to {@code regional} causes | ||
* the SDK to use the {@code s3.us-east-1.amazonaws.com} endpoint when using the {@link Region#US_EAST_1} region instead of | ||
* the global {@code s3.amazonaws.com}. Using the regional endpoint is disabled by default. | ||
*/ | ||
public static final ServiceMetadataAdvancedOption<String> S3_US_EAST_1_REGIONAL_ENDPOINT = | ||
new ServiceMetadataAdvancedOption<>(String.class); | ||
|
||
protected ServiceMetadataAdvancedOption(Class<T> valueClass) { | ||
super(valueClass); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import software.amazon.awssdk.profiles.ProfileProperty; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.regions.ServiceMetadata; | ||
import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption; | ||
import software.amazon.awssdk.regions.ServiceMetadataConfiguration; | ||
import software.amazon.awssdk.regions.ServicePartitionMetadata; | ||
import software.amazon.awssdk.utils.Lazy; | ||
|
@@ -53,7 +54,7 @@ private EnhancedS3ServiceMetadata(ServiceMetadataConfiguration config) { | |
Supplier<String> profileName = config.profileName() != null ? () -> config.profileName() | ||
: ProfileFileSystemSetting.AWS_PROFILE::getStringValueOrThrow; | ||
|
||
this.useUsEast1RegionalEndpoint = new Lazy<>(() -> useUsEast1RegionalEndpoint(profileFile, profileName)); | ||
this.useUsEast1RegionalEndpoint = new Lazy<>(() -> useUsEast1RegionalEndpoint(profileFile, profileName, config)); | ||
this.s3ServiceMetadata = new S3ServiceMetadata().reconfigure(config); | ||
} | ||
|
||
|
@@ -80,7 +81,8 @@ public List<ServicePartitionMetadata> servicePartitions() { | |
return s3ServiceMetadata.servicePartitions(); | ||
} | ||
|
||
private boolean useUsEast1RegionalEndpoint(Supplier<ProfileFile> profileFile, Supplier<String> profileName) { | ||
private boolean useUsEast1RegionalEndpoint(Supplier<ProfileFile> profileFile, Supplier<String> profileName, | ||
ServiceMetadataConfiguration config) { | ||
String env = envVarSetting(); | ||
|
||
if (env != null) { | ||
|
@@ -93,7 +95,8 @@ private boolean useUsEast1RegionalEndpoint(Supplier<ProfileFile> profileFile, Su | |
return REGIONAL_SETTING.equalsIgnoreCase(profile); | ||
} | ||
|
||
return false; | ||
return config.advancedOption(ServiceMetadataAdvancedOption.S3_US_EAST_1_REGIONAL_ENDPOINT) | ||
.filter(REGIONAL_SETTING::equalsIgnoreCase).isPresent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually directly-configured options are higher priority than environment variables and system properties. I know in this case it's actually a default instead of a directly configured option (the customer can't configure this directly, right?), but should we name it accordingly to clarify it's the default, not the actual setting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point. Customers can't configure this if they are using the SDK client. I'll rename it to reflect that it's the default. |
||
} | ||
|
||
private static String envVarSetting() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does AttributeMap.Builder work for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but the public API
ServiceMetadataConfiguration
would need to take AttributeMap or AttributeMap.Builder instead, which is not consistent withClientOverrideConfiguration#advancedOptions
aws-sdk-java-v2/core/regions/src/main/java/software/amazon/awssdk/regions/ServiceMetadataConfiguration.java
Line 116 in 040b7fd
aws-sdk-java-v2/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/config/ClientOverrideConfiguration.java
Line 350 in 040b7fd