Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkProtectedApi;
import software.amazon.awssdk.core.ClientType;
import software.amazon.awssdk.core.ServiceConfiguration;
Expand Down Expand Up @@ -129,6 +130,12 @@ public final class SdkClientOption<T> extends ClientOption<T> {
*/
public static final SdkClientOption<ProfileFile> PROFILE_FILE = new SdkClientOption<>(ProfileFile.class);

/**
* The profile file supplier to use for this client.
*/
public static final SdkClientOption<Supplier<ProfileFile>> PROFILE_FILE_SUPPLIER =
new SdkClientOption<>(new UnsafeValueType(Supplier.class));

/**
* The profile name to use for this client.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
Expand Down Expand Up @@ -68,7 +69,7 @@ public final class DefaultPollyPresigner implements PollyPresigner {
private static final String SERVICE_NAME = "polly";
private static final Aws4Signer DEFAULT_SIGNER = Aws4Signer.create();

private final ProfileFile profileFile;
private final Supplier<ProfileFile> profileFile;
private final String profileName;
private final Region region;
private final AwsCredentialsProvider credentialsProvider;
Expand All @@ -77,11 +78,11 @@ public final class DefaultPollyPresigner implements PollyPresigner {
private final Boolean fipsEnabled;

private DefaultPollyPresigner(BuilderImpl builder) {
this.profileFile = ProfileFile.defaultProfileFile();
this.profileFile = ProfileFile::defaultProfileFile;
this.profileName = ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
this.region = builder.region != null ? builder.region
: DefaultAwsRegionProviderChain.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.getRegion();
Expand All @@ -93,14 +94,14 @@ private DefaultPollyPresigner(BuilderImpl builder) {
this.endpointOverride = builder.endpointOverride;
this.dualstackEnabled = builder.dualstackEnabled != null ? builder.dualstackEnabled
: DualstackEnabledProvider.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.isDualstackEnabled()
.orElse(false);
this.fipsEnabled = builder.fipsEnabled != null ? builder.fipsEnabled
: FipsEnabledProvider.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.isFipsEnabled()
Expand Down Expand Up @@ -245,7 +246,7 @@ private URI resolveEndpoint() {

return new DefaultServiceEndpointBuilder(SERVICE_NAME, "https")
.withRegion(region())
.withProfileFile(() -> profileFile)
.withProfileFile(profileFile)
.withProfileName(profileName)
.withDualstackEnabled(dualstackEnabled)
.withFipsEnabled(fipsEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Tests for {@link DefaultPollyPresigner}.
*/
public class DefaultPollyPresignerTest {
class DefaultPollyPresignerTest {
private static final SynthesizeSpeechRequest BASIC_SYNTHESIZE_SPEECH_REQUEST = SynthesizeSpeechRequest.builder()
.voiceId("Salli")
.outputFormat(OutputFormat.PCM)
Expand All @@ -56,7 +56,7 @@ public void methodSetup() {
}

@Test
public void presign_requestLevelCredentials_honored() {
void presign_requestLevelCredentials_honored() {
AwsCredentials requestCredentials = AwsBasicCredentials.create("akid2", "skid2");

PollyPresigner presigner = DefaultPollyPresigner.builder()
Expand All @@ -80,7 +80,7 @@ public void presign_requestLevelCredentials_honored() {
}

@Test
public void presign_requestLevelHeaders_included() {
void presign_requestLevelHeaders_included() {
PollyPresigner presigner = DefaultPollyPresigner.builder()
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider)
Expand All @@ -104,7 +104,7 @@ public void presign_requestLevelHeaders_included() {
}

@Test
public void presign_includesRequestLevelHeaders_notBrowserCompatible() {
void presign_includesRequestLevelHeaders_notBrowserCompatible() {
PollyPresigner presigner = DefaultPollyPresigner.builder()
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider)
Expand All @@ -128,7 +128,7 @@ public void presign_includesRequestLevelHeaders_notBrowserCompatible() {
}

@Test
public void presign_includesRequestLevelQueryParams_included() {
void presign_includesRequestLevelQueryParams_included() {
PollyPresigner presigner = DefaultPollyPresigner.builder()
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider)
Expand All @@ -151,7 +151,7 @@ public void presign_includesRequestLevelQueryParams_included() {
}

@Test
public void presign_endpointOverriden() {
void presign_endpointOverriden() {
PollyPresigner presigner = DefaultPollyPresigner.builder()
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider)
Expand All @@ -173,7 +173,7 @@ public void presign_endpointOverriden() {
}

@Test
public void close_closesCustomCloseableCredentialsProvider() throws IOException {
void close_closesCustomCloseableCredentialsProvider() throws IOException {
TestCredentialsProvider mockCredentialsProvider = mock(TestCredentialsProvider.class);

PollyPresigner presigner = DefaultPollyPresigner.builder()
Expand All @@ -186,6 +186,19 @@ public void close_closesCustomCloseableCredentialsProvider() throws IOException
verify(mockCredentialsProvider).close();
}

@Test
void presigner_credentialsProviderSetToNullByBuilder_createsDefaultCredentialsProvider() {
DefaultPollyPresigner presigner = (DefaultPollyPresigner)
DefaultPollyPresigner.builder()
.region(Region.US_EAST_1)
.credentialsProvider(null)
.build();


AwsCredentialsProvider awsCredentialsProvider = presigner.credentialsProvider();
assertThat(awsCredentialsProvider).isNotNull();
}

private interface TestCredentialsProvider extends AwsCredentialsProvider, Closeable {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public UseGlobalEndpointResolver(SdkClientConfiguration config) {
String defaultS3UsEast1RegionalEndpointFromSmartDefaults =
config.option(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT);
this.useUsEast1RegionalEndpoint =
new Lazy<>(() -> useUsEast1RegionalEndpoint(() -> config.option(SdkClientOption.PROFILE_FILE),
new Lazy<>(() -> useUsEast1RegionalEndpoint(config.option(SdkClientOption.PROFILE_FILE_SUPPLIER) != null ?
config.option(SdkClientOption.PROFILE_FILE_SUPPLIER) :
() -> config.option(SdkClientOption.PROFILE_FILE),
() -> config.option(SdkClientOption.PROFILE_NAME),
defaultS3UsEast1RegionalEndpointFromSmartDefaults));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private DefaultS3Presigner(Builder b) {

S3Configuration serviceConfiguration = b.serviceConfiguration != null ? b.serviceConfiguration :
S3Configuration.builder()
.profileFile(profileFile())
.profileFile(profileFileSupplier())
.profileName(profileName())
.checksumValidationEnabled(false)
.build();
Expand Down Expand Up @@ -214,7 +214,7 @@ private SdkClientConfiguration createClientConfiguration() {
} else {
URI defaultEndpoint = new DefaultServiceEndpointBuilder(SERVICE_NAME, "https")
.withRegion(region())
.withProfileFile(this::profileFile)
.withProfileFile(profileFileSupplier())
.withProfileName(profileName())
.withDualstackEnabled(serviceConfiguration.dualstackEnabled())
.withFipsEnabled(fipsEnabled())
Expand Down Expand Up @@ -533,7 +533,7 @@ private UseGlobalEndpointResolver createUseGlobalEndpointResolver() {

SdkClientConfiguration config = clientConfiguration.toBuilder()
.option(ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT, legacyOption)
.option(SdkClientOption.PROFILE_FILE, profileFile())
.option(SdkClientOption.PROFILE_FILE_SUPPLIER, profileFileSupplier())
.option(SdkClientOption.PROFILE_NAME, profileName())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.awssdk.services.s3.internal.signing;

import java.net.URI;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
Expand All @@ -30,14 +31,14 @@

/**
* The base class implementing the {@link SdkPresigner} interface.
* <p/>
* <p>
* TODO: This should get moved to aws-core (or split and moved to sdk-core and aws-core) when we support presigning from
* multiple services.
* TODO: After moving, this should get marked as an @SdkProtectedApi.
*/
@SdkInternalApi
public abstract class DefaultSdkPresigner implements SdkPresigner {
private final ProfileFile profileFile;
private final Supplier<ProfileFile> profileFile;
private final String profileName;
private final Region region;
private final URI endpointOverride;
Expand All @@ -46,10 +47,10 @@ public abstract class DefaultSdkPresigner implements SdkPresigner {
private final boolean fipsEnabled;

protected DefaultSdkPresigner(Builder<?> b) {
this.profileFile = ProfileFile.defaultProfileFile();
this.profileFile = ProfileFile::defaultProfileFile;
this.profileName = ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
this.region = b.region != null ? b.region : DefaultAwsRegionProviderChain.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.getRegion();
Expand All @@ -61,21 +62,21 @@ protected DefaultSdkPresigner(Builder<?> b) {
this.endpointOverride = b.endpointOverride;
this.dualstackEnabled = b.dualstackEnabled != null ? b.dualstackEnabled
: DualstackEnabledProvider.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.isDualstackEnabled()
.orElse(null);
this.fipsEnabled = b.fipsEnabled != null ? b.fipsEnabled
: FipsEnabledProvider.builder()
.profileFile(() -> profileFile)
.profileFile(profileFile)
.profileName(profileName)
.build()
.isFipsEnabled()
.orElse(false);
}

protected ProfileFile profileFile() {
protected Supplier<ProfileFile> profileFileSupplier() {
return profileFile;
}

Expand Down
Loading