Skip to content

Commit

Permalink
Store Perforce Ticket as a Secret, but support old clear text ticket …
Browse files Browse the repository at this point in the history
…credentials.

JENKINS-49474
  • Loading branch information
p4paul committed Apr 17, 2018
1 parent 9bfd097 commit 31e3ecf
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -4,6 +4,7 @@
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.util.Secret;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -14,16 +15,23 @@ public class TicketModeImpl extends AbstractDescribableImpl<TicketModeImpl> impl

private static final long serialVersionUID = 1L;

@NonNull private final String value;
@NonNull
private final String value;

@NonNull private final String ticketValue;
@NonNull
private final Secret ticketSecret;

@NonNull private final String ticketPath;
@Deprecated
private final String ticketValue;

@NonNull
private final String ticketPath;

@DataBoundConstructor
public TicketModeImpl(String value, String ticketValue, String ticketPath) {
this.value = value;
this.ticketValue = (ticketValue != null) ? ticketValue : "";
this.ticketValue = "";
this.ticketSecret = Secret.fromString(ticketValue);
this.ticketPath = (ticketPath != null) ? ticketPath : "";
}

Expand All @@ -32,9 +40,16 @@ public String getValue() {
}

public String getTicketValue() {
if (ticketSecret != null && !getTicketSecret().isEmpty()) {
return getTicketSecret();
}
return ticketValue;
}

public String getTicketSecret() {
return ticketSecret.getPlainText();
}

public String getTicketPath() {
return ticketPath;
}
Expand Down

0 comments on commit 31e3ecf

Please sign in to comment.