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 12bc4ec commit 1bae0e6
Showing 1 changed file with 7 additions and 1 deletion.
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 @@ -169,7 +170,12 @@ public boolean requiresToken() {
public AwsCredentials resolveCredentials() {

if (StringUtils.isBlank(iamRoleArn)) {
return AwsBasicCredentials.create(accessKey, secretKey.getPlainText());
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 1bae0e6

Please sign in to comment.