Skip to content

Commit e078d8d

Browse files
committed
Changed to use lazy value for credential provider
1 parent 06f92db commit e078d8d

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ public final class InstanceProfileCredentialsProvider
8989
private final Supplier<ProfileFile> profileFile;
9090

9191
private final String profileName;
92-
private final Object lock = new Object();
93-
private volatile Boolean isInsecureFallbackDisabled;
9492

9593
/**
9694
* @see #builder()
@@ -273,14 +271,7 @@ private String handleTokenErrorResponse(Exception e) {
273271
}
274272

275273
private boolean isInsecureFallbackDisabled() {
276-
if (isInsecureFallbackDisabled == null) {
277-
synchronized (lock) {
278-
if (isInsecureFallbackDisabled == null) {
279-
isInsecureFallbackDisabled = ec2MetadataDisableV1Resolver.resolve();
280-
}
281-
}
282-
}
283-
return isInsecureFallbackDisabled;
274+
return ec2MetadataDisableV1Resolver.resolve();
284275
}
285276

286277
private String[] getSecurityCredentials(String imdsHostname, String metadataToken) {

core/auth/src/main/java/software/amazon/awssdk/auth/credentials/internal/Ec2MetadataDisableV1Resolver.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,30 @@
2121
import software.amazon.awssdk.core.SdkSystemSetting;
2222
import software.amazon.awssdk.profiles.ProfileFile;
2323
import software.amazon.awssdk.profiles.ProfileProperty;
24+
import software.amazon.awssdk.utils.Lazy;
2425
import software.amazon.awssdk.utils.OptionalUtils;
2526

2627
@SdkInternalApi
2728
public final class Ec2MetadataDisableV1Resolver {
2829
private final Supplier<ProfileFile> profileFile;
2930
private final String profileName;
31+
private final Lazy<Boolean> resolvedValue;
3032

3133
private Ec2MetadataDisableV1Resolver(Supplier<ProfileFile> profileFile, String profileName) {
3234
this.profileFile = profileFile;
3335
this.profileName = profileName;
36+
this.resolvedValue = new Lazy<>(this::doResolve);
3437
}
3538

3639
public static Ec2MetadataDisableV1Resolver create(Supplier<ProfileFile> profileFile, String profileName) {
3740
return new Ec2MetadataDisableV1Resolver(profileFile, profileName);
3841
}
3942

4043
public boolean resolve() {
44+
return resolvedValue.getValue();
45+
}
46+
47+
public boolean doResolve() {
4148
return OptionalUtils.firstPresent(fromSystemSettings(),
4249
() -> fromProfileFile(profileFile, profileName))
4350
.orElse(false);

core/regions/src/test/java/software/amazon/awssdk/regions/internal/util/EC2MetadataUtilsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.assertj.core.api.Assertions.assertThat;
2727

2828
import com.github.tomakehurst.wiremock.client.WireMock;
29+
import com.github.tomakehurst.wiremock.http.Fault;
2930
import com.github.tomakehurst.wiremock.junit.WireMockRule;
3031
import org.junit.Before;
3132
import org.junit.Rule;

0 commit comments

Comments
 (0)