@@ -205,7 +205,7 @@ private RefreshResult<AwsCredentials> refreshCredentials() {
205
205
if (apiVersion == ApiVersion .UNKNOWN ) {
206
206
apiVersion = ApiVersion .LEGACY ;
207
207
return refreshCredentials ();
208
- } else if (ec2InstanceProfileName == null && configProvider . ec2InstanceProfileName () == null ) {
208
+ } else if (resolveProfileName () == null ) {
209
209
// Resolved profile name is invalid, reset it and try again
210
210
resolvedProfile = null ;
211
211
@@ -348,14 +348,16 @@ private boolean isInsecureFallbackDisabled() {
348
348
return configProvider .isMetadataV1Disabled ();
349
349
}
350
350
351
- private String [] getSecurityCredentials (String imdsHostname , String metadataToken ) {
352
- if (ec2InstanceProfileName != null ) {
353
- return new String []{ec2InstanceProfileName };
354
- }
351
+ private String resolveProfileName () {
352
+ return ec2InstanceProfileName != null ?
353
+ ec2InstanceProfileName :
354
+ configProvider .ec2InstanceProfileName ();
355
+ }
355
356
356
- String configuredProfileName = this .configProvider .ec2InstanceProfileName ();
357
- if (configuredProfileName != null ) {
358
- return new String []{configuredProfileName };
357
+ private String [] getSecurityCredentials (String imdsHostname , String metadataToken ) {
358
+ String profileName = resolveProfileName ();
359
+ if (profileName != null ) {
360
+ return new String []{profileName };
359
361
}
360
362
361
363
if (resolvedProfile != null ) {
@@ -417,12 +419,9 @@ public interface Builder extends HttpCredentialsProvider.Builder<InstanceProfile
417
419
* Configure the EC2 instance profile name to use for retrieving credentials.
418
420
*
419
421
* <p>When this is set, the provider will skip fetching the list of available instance profiles
420
- * and use this name directly. This can improve performance by reducing the number of calls to IMDS.
421
- *
422
- * <p>By default, this is not set and the provider will discover the instance profile name from IMDS.
422
+ * and use this name directly.
423
423
*
424
424
* @param ec2InstanceProfileName The EC2 instance profile name to use
425
- * @return This builder for method chaining
426
425
*/
427
426
Builder ec2InstanceProfileName (String ec2InstanceProfileName );
428
427
0 commit comments