Skip to content

Commit

Permalink
Convert AWS Secret Key to use Secret rather than String primitive type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmcfar committed May 17, 2018
1 parent 5e07b16 commit 4bef706
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import hudson.util.DirScanner;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;

Expand Down Expand Up @@ -101,7 +102,7 @@ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep
private final int proxyPort;

private final String awsAccessKey;
private final String awsSecretKey;
private final Secret awsSecretKey;
private final String credentials;
private final String deploymentMethod;
private final String versionFileName;
Expand All @@ -125,7 +126,7 @@ public AWSCodeDeployPublisher(
String versionFileName,
String deploymentMethod,
String awsAccessKey,
String awsSecretKey,
Secret awsSecretKey,
String iamRoleArn,
String externalId,
String includes,
Expand Down Expand Up @@ -194,7 +195,7 @@ public void perform(@Nonnull Run<?,?> build, @Nonnull FilePath workspace, @Nonnu

final AWSClients aws;
if ("awsAccessKey".equals(credentials)) {
if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(this.awsSecretKey)) {
if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(Secret.toString(this.awsSecretKey))) {
aws = AWSClients.fromDefaultCredentialChain(
this.region,
this.proxyHost,
Expand All @@ -203,7 +204,7 @@ public void perform(@Nonnull Run<?,?> build, @Nonnull FilePath workspace, @Nonnu
aws = AWSClients.fromBasicCredentials(
this.region,
this.awsAccessKey,
this.awsSecretKey,
Secret.toString(this.awsSecretKey),
this.proxyHost,
this.proxyPort);
}
Expand Down Expand Up @@ -504,7 +505,7 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>

private String externalId;
private String awsAccessKey;
private String awsSecretKey;
private Secret awsSecretKey;
private String proxyHost;
private int proxyPort;

Expand Down Expand Up @@ -543,7 +544,7 @@ public String getDisplayName() {
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {

awsAccessKey = formData.getString("awsAccessKey");
awsSecretKey = formData.getString("awsSecretKey");
awsSecretKey = Secret.fromString(formData.getString("awsSecretKey"));
proxyHost = formData.getString("proxyHost");
proxyPort = Integer.parseInt(formData.getString("proxyPort"));

Expand Down Expand Up @@ -618,12 +619,12 @@ public ListBoxModel doFillRegionItems() {

public String getAwsSecretKey()
{
return awsSecretKey;
return Secret.toString(awsSecretKey);
}

public void setAwsSecretKey(String awsSecretKey)
{
this.awsSecretKey = awsSecretKey;
this.awsSecretKey = Secret.fromString(awsSecretKey);
}

public String getAwsAccessKey()
Expand Down Expand Up @@ -671,7 +672,7 @@ public String getAwsAccessKey() {
}

public String getAwsSecretKey() {
return awsSecretKey;
return Secret.toString(awsSecretKey);
}

public Long getPollingFreqSec() {
Expand Down

0 comments on commit 4bef706

Please sign in to comment.