Skip to content

Skip avoidable conversion in CredentialsUtils #3878

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
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 @@ -97,6 +97,9 @@ public static AwsCredentialsProvider toCredentialsProvider(
if (identityProvider == null) {
return null;
}
if (identityProvider instanceof AwsCredentialsProvider) {
return (AwsCredentialsProvider) identityProvider;
}
return () -> {
// TODO: Exception handling for CompletionException thrown from join?
AwsCredentialsIdentity awsCredentialsIdentity = identityProvider.resolveIdentity().join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
import software.amazon.awssdk.identity.spi.AwsSessionCredentialsIdentity;
import software.amazon.awssdk.identity.spi.IdentityProvider;

public class CredentialUtilsTest {

Expand Down Expand Up @@ -83,7 +84,7 @@ public String sessionToken() {
}

@Test
public void toCredentials_AwsCredentials_doesNotCreateNewObject() {
public void toCredentials_AwsCredentials_returnsAsIs() {
AwsCredentialsIdentity input = AwsBasicCredentials.create("ak", "sk");
AwsCredentials output = CredentialUtils.toCredentials(input);
assertThat(output).isSameAs(input);
Expand Down Expand Up @@ -130,6 +131,14 @@ public void toCredentialsProvider_null_returnsNull() {
assertThat(CredentialUtils.toCredentialsProvider(null)).isNull();
}

@Test
public void toCredentialsProvider_AwsCredentialsProvider_returnsAsIs() {
IdentityProvider<AwsCredentialsIdentity> input =
StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"));
AwsCredentialsProvider output = CredentialUtils.toCredentialsProvider(input);
assertThat(output).isSameAs(input);
}

@Test
public void toCredentialsProvider_IdentityProvider_converts() {
AwsCredentialsProvider credentialsProvider = CredentialUtils.toCredentialsProvider(
Expand Down