Skip to content

Make ProcessCredentialsProvider closeable, so that the internal cre… #2838

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

Merged
merged 9 commits into from
Dec 10, 2021
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
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-84c738e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "bugfix",
"description": "Make `ProcessCredentialsProvider` closeable, so that the internal credentials cache (which may be async and need to be closed) can be closed."
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import software.amazon.awssdk.utils.DateUtils;
import software.amazon.awssdk.utils.IoUtils;
import software.amazon.awssdk.utils.Platform;
import software.amazon.awssdk.utils.SdkAutoCloseable;
import software.amazon.awssdk.utils.Validate;
import software.amazon.awssdk.utils.cache.CachedSupplier;
import software.amazon.awssdk.utils.cache.NonBlocking;
Expand All @@ -53,7 +54,7 @@
* </ul>
*/
@SdkPublicApi
public final class ProcessCredentialsProvider implements AwsCredentialsProvider {
public final class ProcessCredentialsProvider implements AwsCredentialsProvider, SdkAutoCloseable {
private static final JsonNodeParser PARSER = JsonNodeParser.builder()
.removeErrorLocations(true)
.build();
Expand Down Expand Up @@ -204,6 +205,11 @@ private String executeCommand() throws IOException, InterruptedException {
}
}

@Override
public void close() {
processCredentialCache.close();
}

/**
* Used to configure and create a {@link ProcessCredentialsProvider}. See {@link #builder()} creation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ public void processOutputLimitDefaultPassesLargeInput() {
Assertions.assertThat(sessionCredentials.accessKeyId()).isEqualTo("accessKeyId");
Assertions.assertThat(sessionCredentials.sessionToken()).isNotNull();
}

@Test
public void closeDoesNotRaise() {
ProcessCredentialsProvider credentialsProvider =
ProcessCredentialsProvider.builder()
.command(scriptLocation + " accessKeyId secretAccessKey sessionToken")
.build();
credentialsProvider.resolveCredentials();
credentialsProvider.close();
}

public static String copyProcessCredentialsScript() {
String scriptClasspathFilename = Platform.isWindows() ? "windows-credentials-script.bat"
Expand Down