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 @@ -207,9 +207,11 @@ public static MarshalledCredentials requestSessionCredentials(
stsEndpoint.isEmpty() ? null : stsEndpoint,
stsRegion)
.build();
return fromSTSCredentials(
STSClientFactory.createClientConnection(tokenService, invoker)
.requestSessionCredentials(duration, TimeUnit.SECONDS));
try (STSClientFactory.STSClient stsClient = STSClientFactory.createClientConnection(
tokenService, invoker)) {
return fromSTSCredentials(stsClient.requestSessionCredentials(duration,
TimeUnit.SECONDS));
}
} catch (SdkClientException e) {
if (stsRegion.isEmpty()) {
LOG.error("Region must be provided when requesting session credentials.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ public static AWSSecurityTokenServiceClientBuilder builder(
* @param tokenService STS instance
* @param invoker invoker to use
* @return an STS client bonded to that interface.
* @throws IOException on any failure
*/
public static STSClient createClientConnection(
final AWSSecurityTokenService tokenService,
final Invoker invoker)
throws IOException {
final Invoker invoker) {
return new STSClient(tokenService, invoker);
}

Expand All @@ -175,12 +173,9 @@ private STSClient(final AWSSecurityTokenService tokenService,

@Override
public void close() throws IOException {
try {
tokenService.shutdown();
} catch (UnsupportedOperationException ignored) {
// ignore this, as it is what the STS client currently
// does.
}
// Since we are not using AbstractAWSSecurityTokenService, we
// don't need to worry about catching UnsupportedOperationException.
tokenService.shutdown();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ public void testSTS() throws IOException {
credentials,
getStsEndpoint(conf),
getStsRegion(conf));
STSClientFactory.STSClient clientConnection =
STSClientFactory.createClientConnection(
builder.build(),
new Invoker(new S3ARetryPolicy(conf), Invoker.LOG_EVENT));
Credentials sessionCreds = clientConnection
.requestSessionCredentials(TEST_SESSION_TOKEN_DURATION_SECONDS,
TimeUnit.SECONDS);
Credentials sessionCreds;
try (STSClientFactory.STSClient clientConnection =
STSClientFactory.createClientConnection(builder.build(),
new Invoker(new S3ARetryPolicy(conf), Invoker.LOG_EVENT))) {
sessionCreds = clientConnection
.requestSessionCredentials(
TEST_SESSION_TOKEN_DURATION_SECONDS, TimeUnit.SECONDS);
}

// clone configuration so changes here do not affect the base FS.
Configuration conf2 = new Configuration(conf);
Expand Down Expand Up @@ -379,11 +380,12 @@ public <E extends Exception> E expectedSessionRequestFailure(
Invoker invoker = new Invoker(new S3ARetryPolicy(conf),
LOG_AT_ERROR);

STSClientFactory.STSClient stsClient
= STSClientFactory.createClientConnection(tokenService,
invoker);

return stsClient.requestSessionCredentials(30, TimeUnit.MINUTES);
try (STSClientFactory.STSClient stsClient =
STSClientFactory.createClientConnection(
tokenService, invoker)) {
return stsClient.requestSessionCredentials(
30, TimeUnit.MINUTES);
}
});
}
}
Expand Down Expand Up @@ -413,6 +415,7 @@ public void testTemporaryCredentialValidationOnLoad() throws Throwable {
return sc.toString();
});
}

@Test
public void testEmptyTemporaryCredentialValidation() throws Throwable {
Configuration conf = new Configuration();
Expand Down