|
16 | 16 | package software.amazon.awssdk.services.s3.internal.s3express;
|
17 | 17 |
|
18 | 18 | import java.time.Duration;
|
19 |
| -import java.util.function.Consumer; |
| 19 | +import java.util.Optional; |
20 | 20 | import software.amazon.awssdk.annotations.SdkInternalApi;
|
21 | 21 | import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
22 | 22 | import software.amazon.awssdk.auth.credentials.CredentialUtils;
|
23 | 23 | import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
24 | 24 | import software.amazon.awssdk.core.SdkClient;
|
| 25 | +import software.amazon.awssdk.core.SdkServiceClientConfiguration; |
25 | 26 | import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
|
26 | 27 | import software.amazon.awssdk.identity.spi.IdentityProvider;
|
27 | 28 | import software.amazon.awssdk.services.s3.S3AsyncClient;
|
@@ -75,28 +76,42 @@ private CachedS3ExpressCredentials getCachedCredentials(S3ExpressIdentityKey key
|
75 | 76 | .build();
|
76 | 77 | }
|
77 | 78 |
|
78 |
| - //TODO (s3express) user experience and error messaging when calls fail |
79 | 79 | SessionCredentials getCredentials(S3ExpressIdentityKey key, IdentityProvider<AwsCredentialsIdentity> provider) {
|
80 | 80 | SdkClient client = key.client();
|
81 | 81 | String bucket = key.bucket();
|
| 82 | + SdkServiceClientConfiguration serviceClientConfiguration = client.serviceClientConfiguration(); |
82 | 83 |
|
83 | 84 | if (client instanceof S3AsyncClient) {
|
84 | 85 | // 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(); |
86 | 89 | }
|
87 | 90 | if (client instanceof S3Client) {
|
88 |
| - return ((S3Client) client).createSession(createSessionRequest(bucket, provider)).credentials(); |
| 91 | + return ((S3Client) client).createSession(createSessionRequest(bucket, provider, serviceClientConfiguration)) |
| 92 | + .credentials(); |
89 | 93 | }
|
90 | 94 | throw new UnsupportedOperationException("SdkClient must be either an S3Client or an S3AsyncClient, but was " +
|
91 | 95 | client.getClass());
|
92 | 96 | }
|
93 | 97 |
|
94 |
| - private static Consumer<CreateSessionRequest.Builder> |
| 98 | + private static CreateSessionRequest |
95 | 99 | 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) |
98 | 106 | .sessionMode(SessionMode.READ_WRITE)
|
99 | 107 | .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(); |
101 | 116 | }
|
102 | 117 | }
|
0 commit comments