Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an mfaToken option to the credentials binding #160

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class AmazonWebServicesCredentialsBinding extends MultiBinding<AmazonWebS
@NonNull
private final String secretKeyVariable;

private String mfaToken;
private String roleArn;
private String roleSessionName;
private int roleSessionDurationSeconds;
Expand Down Expand Up @@ -94,6 +95,11 @@ public String getSecretKeyVariable() {
return secretKeyVariable;
}

@DataBoundSetter
public void setMfaToken(String mfaToken) {
this.mfaToken = mfaToken;
}

@DataBoundSetter
public void setRoleArn(String roleArn) {
this.roleArn = roleArn;
Expand Down Expand Up @@ -121,7 +127,13 @@ public MultiEnvironment bind(@Nonnull Run<?, ?> build, FilePath workspace, Launc
provider = this.assumeRoleProvider(provider);
}

AWSCredentials credentials = provider.getCredentials();
AWSCredentials credentials;
if (!StringUtils.isEmpty(this.mfaToken)) {
AmazonWebServicesCredentials awsProvider = (AmazonWebServicesCredentials) provider;
credentials = awsProvider.getCredentials(this.mfaToken);
} else {
credentials = provider.getCredentials();
}

Map<String,String> m = new HashMap<String,String>();
m.put(accessKeyVariable, credentials.getAWSAccessKeyId());
Expand Down