Skip to content

Commit 94d89b0

Browse files
authored
Add singletons for AwsCredentialsResolver impls (#1059)
1 parent c3fddb7 commit 94d89b0

5 files changed

Lines changed: 7 additions & 3 deletions

File tree

aws/client/aws-client-core/src/main/java/software/amazon/smithy/java/aws/client/core/identity/EnvironmentVariableIdentityResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* </dl>
2626
*/
2727
public final class EnvironmentVariableIdentityResolver implements AwsCredentialsResolver {
28+
public static final EnvironmentVariableIdentityResolver INSTANCE = new EnvironmentVariableIdentityResolver();
29+
2830
private static final String ACCESS_KEY_PROPERTY = "AWS_ACCESS_KEY_ID";
2931
private static final String SECRET_KEY_PROPERTY = "AWS_SECRET_ACCESS_KEY";
3032
private static final String SESSION_TOKEN_PROPERTY = "AWS_SESSION_TOKEN";

aws/client/aws-client-core/src/main/java/software/amazon/smithy/java/aws/client/core/identity/SystemPropertiesIdentityResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* @see <a href="https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html">Java System Properties</a>
2828
*/
2929
public final class SystemPropertiesIdentityResolver implements AwsCredentialsResolver {
30+
public static final SystemPropertiesIdentityResolver INSTANCE = new SystemPropertiesIdentityResolver();
31+
3032
private static final String ACCESS_KEY_PROPERTY = "aws.accessKeyId";
3133
private static final String SECRET_KEY_PROPERTY = "aws.secretAccessKey";
3234
private static final String SESSION_TOKEN_PROPERTY = "aws.sessionToken";

aws/client/aws-client-core/src/test/java/software/amazon/smithy/java/aws/client/core/identity/EnvironmentVariableIdentityResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class EnvironmentVariableIdentityResolverTest {
1515

1616
@Test
1717
void resolverReturnsExpectedIdentity() {
18-
var resolver = new EnvironmentVariableIdentityResolver();
18+
var resolver = EnvironmentVariableIdentityResolver.INSTANCE;
1919
var value = resolver.resolveIdentity(Context.empty());
2020
var expected = AwsCredentialsIdentity.create(
2121
"env_access_key",

aws/client/aws-client-core/src/test/java/software/amazon/smithy/java/aws/client/core/identity/SystemPropertiesIdentityResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class SystemPropertiesIdentityResolverTest {
1515
@Test
1616
void resolverReturnsExpectedIdentity() {
17-
var resolver = new SystemPropertiesIdentityResolver();
17+
var resolver = SystemPropertiesIdentityResolver.INSTANCE;
1818
var value = resolver.resolveIdentity(Context.empty());
1919
var expected = AwsCredentialsIdentity.create(
2020
"property_access_key",

cli/src/main/java/software/amazon/smithy/java/cli/SmithyCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void configureAuth(DynamicClient.Builder builder, ShapeId serviceInput,
284284
.profileName(auth.awsProfile);
285285
builder.addIdentityResolver(new SdkCredentialsResolver(profileBuilder.build()));
286286
} else {
287-
builder.addIdentityResolver(new EnvironmentVariableIdentityResolver());
287+
builder.addIdentityResolver(EnvironmentVariableIdentityResolver.INSTANCE);
288288
}
289289
break;
290290
case "none":

0 commit comments

Comments
 (0)