Skip to content

Commit 46ae955

Browse files
committed
Propagating client apiCallTimeout values to S3Express createSession request configuration
1 parent 6ca7903 commit 46ae955

File tree

4 files changed

+506
-9
lines changed

4 files changed

+506
-9
lines changed

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/s3express/S3ExpressIdentityCache.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
package software.amazon.awssdk.services.s3.internal.s3express;
1717

1818
import java.time.Duration;
19-
import java.util.function.Consumer;
19+
import java.util.Optional;
2020
import software.amazon.awssdk.annotations.SdkInternalApi;
2121
import software.amazon.awssdk.auth.credentials.AwsCredentials;
2222
import software.amazon.awssdk.auth.credentials.CredentialUtils;
2323
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
2424
import software.amazon.awssdk.core.SdkClient;
25+
import software.amazon.awssdk.core.SdkServiceClientConfiguration;
2526
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
2627
import software.amazon.awssdk.identity.spi.IdentityProvider;
2728
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -75,28 +76,42 @@ private CachedS3ExpressCredentials getCachedCredentials(S3ExpressIdentityKey key
7576
.build();
7677
}
7778

78-
//TODO (s3express) user experience and error messaging when calls fail
7979
SessionCredentials getCredentials(S3ExpressIdentityKey key, IdentityProvider<AwsCredentialsIdentity> provider) {
8080
SdkClient client = key.client();
8181
String bucket = key.bucket();
82+
SdkServiceClientConfiguration serviceClientConfiguration = client.serviceClientConfiguration();
8283

8384
if (client instanceof S3AsyncClient) {
8485
// TODO (s3express) don't join here
85-
return ((S3AsyncClient) client).createSession(createSessionRequest(bucket, provider)).join().credentials();
86+
return ((S3AsyncClient) client).createSession(createSessionRequest(bucket, provider, serviceClientConfiguration))
87+
.join()
88+
.credentials();
8689
}
8790
if (client instanceof S3Client) {
88-
return ((S3Client) client).createSession(createSessionRequest(bucket, provider)).credentials();
91+
return ((S3Client) client).createSession(createSessionRequest(bucket, provider, serviceClientConfiguration))
92+
.credentials();
8993
}
9094
throw new UnsupportedOperationException("SdkClient must be either an S3Client or an S3AsyncClient, but was " +
9195
client.getClass());
9296
}
9397

94-
private static Consumer<CreateSessionRequest.Builder>
98+
private static CreateSessionRequest
9599
createSessionRequest(String bucket,
96-
IdentityProvider<AwsCredentialsIdentity> provider) {
97-
return r -> r.bucket(bucket)
100+
IdentityProvider<AwsCredentialsIdentity> provider,
101+
SdkServiceClientConfiguration serviceClientConfiguration) {
102+
103+
Duration requestApiCallTimeout = clientSetTimeoutIfExists(serviceClientConfiguration).orElse(DEFAULT_API_CALL_TIMEOUT);
104+
105+
return CreateSessionRequest.builder().bucket(bucket)
98106
.sessionMode(SessionMode.READ_WRITE)
99107
.overrideConfiguration(o -> o.credentialsProvider(provider)
100-
.apiCallTimeout(DEFAULT_API_CALL_TIMEOUT));
108+
.apiCallTimeout(requestApiCallTimeout)).build();
109+
}
110+
111+
private static Optional<Duration> clientSetTimeoutIfExists(SdkServiceClientConfiguration serviceClientConfiguration) {
112+
if (serviceClientConfiguration != null && serviceClientConfiguration.overrideConfiguration() != null) {
113+
return serviceClientConfiguration.overrideConfiguration().apiCallTimeout();
114+
}
115+
return Optional.empty();
101116
}
102117
}

services/s3/src/test/java/software/amazon/awssdk/services/s3/S3PresignerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ private void verifyS3ExpressGetRequest(PresignedGetObjectRequest presigned, Stri
950950

951951
private S3Presigner presignerWithS3ExpressWithMockS3Client(boolean disableS3ExpressSessionAuth) {
952952
S3Client mockS3SyncClient = mock(S3Client.class);
953-
when(mockS3SyncClient.createSession((Consumer<CreateSessionRequest.Builder>) any())).thenReturn(
953+
when(mockS3SyncClient.createSession((CreateSessionRequest) any())).thenReturn(
954954
createS3ExpressSessionResponse());
955955

956956
return presignerForS3Express(disableS3ExpressSessionAuth, mockS3SyncClient);

0 commit comments

Comments
 (0)