Skip to content

Commit

Permalink
fall back to DefaultCredentialsProvider if all blank
Browse files Browse the repository at this point in the history
  • Loading branch information
samholton committed Jan 9, 2025
1 parent 47e2ec6 commit 1fc2394
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.exception.SdkException;
Expand Down Expand Up @@ -168,10 +169,13 @@ public boolean requiresToken() {
@Override
public AwsCredentials resolveCredentials() {

if (StringUtils.isBlank(iamRoleArn)
&& !StringUtils.isBlank(accessKey)
&& !StringUtils.isBlank(secretKey.getPlainText())) {
return AwsBasicCredentials.create(accessKey, secretKey.getPlainText());
if (StringUtils.isBlank(iamRoleArn)) {
if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText())) {
// fall back to default credentials of node
return DefaultCredentialsProvider.builder().build().resolveCredentials();

Check warning on line 175 in src/main/java/com/cloudbees/jenkins/plugins/awscredentials/AWSCredentialsImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 173-175 are not covered by tests
} else {
return AwsBasicCredentials.create(accessKey, secretKey.getPlainText());
}
} else {
AwsCredentialsProvider baseProvider;
// Handle the case of delegation to instance profile
Expand Down

0 comments on commit 1fc2394

Please sign in to comment.