Skip to content

Commit

Permalink
JENKINS-28344 Converting the persistence of the Chef keys from using …
Browse files Browse the repository at this point in the history
…Scramble to using Secret. And in a reverse compatible way too.
  • Loading branch information
Tyler Fitch committed May 11, 2015
1 parent 8032db6 commit 50bd169
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/io/chef/jenkins/ChefIdentity.java
Expand Up @@ -23,6 +23,7 @@
package io.chef.jenkins;

import hudson.util.Scrambler;
import hudson.util.Secret;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.Serializable;
Expand All @@ -38,31 +39,42 @@ public class ChefIdentity implements Serializable {
private static final Logger log = Logger.getLogger(ChefIdentity.class.getName());

private final String idName;
private final String pemKey;
private final String knifeRb;
private Secret pemKey;
private Secret knifeRb;
private final boolean convertedSecret;

public ChefIdentity() {
this.idName = null;
this.pemKey = null;
this.knifeRb = null;
this.convertedSecret = false;
}

@DataBoundConstructor
public ChefIdentity(String idName, String pemKey, String knifeRb) {
this.idName = idName;
this.pemKey = Scrambler.scramble(pemKey);
this.knifeRb = Scrambler.scramble(knifeRb);
if (this.pemKey == null) this.pemKey = Secret.fromString(pemKey);
if (this.knifeRb == null) this.knifeRb = Secret.fromString(knifeRb);
this.convertedSecret = true;
}

public String getIdName() {
return idName;
}

public String getPemKey() {
return Scrambler.descramble(pemKey);
if (convertedSecret) {
return Secret.toString(pemKey);
} else {
return Scrambler.descramble(pemKey.getPlainText());
}
}

public String getKnifeRb() {
return Scrambler.descramble(knifeRb);
if (convertedSecret) {
return Secret.toString(knifeRb);
} else {
return Scrambler.descramble(knifeRb.getPlainText());
}
}
}

0 comments on commit 50bd169

Please sign in to comment.