Skip to content

Commit b1dbeff

Browse files
authored
Make ProcessCredentialsProvider closeable, so that the internal credentials cache (which may be async and need to be closed) can be closed. I also verified that this is the only usage of CachedSupplier that is affected. (#2838)
1 parent be152db commit b1dbeff

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Make `ProcessCredentialsProvider` closeable, so that the internal credentials cache (which may be async and need to be closed) can be closed."
6+
}

core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProcessCredentialsProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import software.amazon.awssdk.utils.DateUtils;
3030
import software.amazon.awssdk.utils.IoUtils;
3131
import software.amazon.awssdk.utils.Platform;
32+
import software.amazon.awssdk.utils.SdkAutoCloseable;
3233
import software.amazon.awssdk.utils.Validate;
3334
import software.amazon.awssdk.utils.cache.CachedSupplier;
3435
import software.amazon.awssdk.utils.cache.NonBlocking;
@@ -53,7 +54,7 @@
5354
* </ul>
5455
*/
5556
@SdkPublicApi
56-
public final class ProcessCredentialsProvider implements AwsCredentialsProvider {
57+
public final class ProcessCredentialsProvider implements AwsCredentialsProvider, SdkAutoCloseable {
5758
private static final JsonNodeParser PARSER = JsonNodeParser.builder()
5859
.removeErrorLocations(true)
5960
.build();
@@ -204,6 +205,11 @@ private String executeCommand() throws IOException, InterruptedException {
204205
}
205206
}
206207

208+
@Override
209+
public void close() {
210+
processCredentialCache.close();
211+
}
212+
207213
/**
208214
* Used to configure and create a {@link ProcessCredentialsProvider}. See {@link #builder()} creation.
209215
*/

core/auth/src/test/java/software/amazon/awssdk/auth/credentials/ProcessCredentialsProviderTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ public void processOutputLimitDefaultPassesLargeInput() {
164164
Assertions.assertThat(sessionCredentials.accessKeyId()).isEqualTo("accessKeyId");
165165
Assertions.assertThat(sessionCredentials.sessionToken()).isNotNull();
166166
}
167+
168+
@Test
169+
public void closeDoesNotRaise() {
170+
ProcessCredentialsProvider credentialsProvider =
171+
ProcessCredentialsProvider.builder()
172+
.command(scriptLocation + " accessKeyId secretAccessKey sessionToken")
173+
.build();
174+
credentialsProvider.resolveCredentials();
175+
credentialsProvider.close();
176+
}
167177

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

0 commit comments

Comments
 (0)