Skip to content

Commit

Permalink
JENKINS-73398: Support credential snapshots (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtughan authored Aug 22, 2024
1 parent 48134f6 commit d49bf74
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.datapipe.jenkins.vault.credentials.common;

import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Item;
Expand Down Expand Up @@ -154,4 +155,48 @@ public ListBoxModel doFillEngineVersionItems(@AncestorInPath Item context) {
return engineVersions(context);
}
}

static class SelfContained extends VaultSSHUserPrivateKeyImpl {
private final String username;
private final String privateKey;
private final Secret passphrase;

public SelfContained(VaultSSHUserPrivateKeyImpl base) {
super(base.getScope(), base.getId(), base.getDescription());
username = base.getUsername();
privateKey = base.getPrivateKey();
passphrase = base.getPassphrase();
}

@NonNull
@Override
public String getUsername() {
return username;
}

@NonNull
@Override
public String getPrivateKey() {
return privateKey;
}

@NonNull
@Override
public Secret getPassphrase() {
return passphrase;
}
}

@Extension
public static class SnapshotTaker extends CredentialsSnapshotTaker<VaultSSHUserPrivateKeyImpl> {
@Override
public Class<VaultSSHUserPrivateKeyImpl> type() {
return VaultSSHUserPrivateKeyImpl.class;
}

@Override
public VaultSSHUserPrivateKeyImpl snapshot(VaultSSHUserPrivateKeyImpl credentials) {
return new SelfContained(credentials);

Check warning on line 199 in src/main/java/com/datapipe/jenkins/vault/credentials/common/VaultSSHUserPrivateKeyImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 165-199 are not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.datapipe.jenkins.vault.credentials.common;

import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Item;
Expand Down Expand Up @@ -83,4 +84,32 @@ public ListBoxModel doFillEngineVersionItems(@AncestorInPath Item context) {
}

}

static class SelfContained extends VaultStringCredentialImpl {
private final Secret secret;

public SelfContained(VaultStringCredentialImpl base) {
super(base.getScope(), base.getId(), base.getDescription());
secret = base.getSecret();
}

@NonNull
@Override
public Secret getSecret() {
return secret;
}
}

@Extension
public static class SnapshotTaker extends CredentialsSnapshotTaker<VaultStringCredentialImpl> {
@Override
public Class<VaultStringCredentialImpl> type() {
return VaultStringCredentialImpl.class;
}

@Override
public VaultStringCredentialImpl snapshot(VaultStringCredentialImpl credentials) {
return new SelfContained(credentials);

Check warning on line 112 in src/main/java/com/datapipe/jenkins/vault/credentials/common/VaultStringCredentialImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 92-112 are not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.datapipe.jenkins.vault.credentials.common;

import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Item;
Expand Down Expand Up @@ -112,4 +113,40 @@ public ListBoxModel doFillEngineVersionItems(@AncestorInPath Item context) {
return engineVersions(context);
}
}

static class SelfContained extends VaultUsernamePasswordCredentialImpl {
private final String username;
private final Secret password;

public SelfContained(VaultUsernamePasswordCredentialImpl base) {
super(base.getScope(), base.getId(), base.getDescription());
username = base.getUsername();
password = base.getPassword();
}

@NonNull
@Override
public String getUsername() {
return username;
}

@NonNull
@Override
public Secret getPassword() {
return password;
}
}

@Extension
public static class SnapshotTaker extends CredentialsSnapshotTaker<VaultUsernamePasswordCredentialImpl> {
@Override
public Class<VaultUsernamePasswordCredentialImpl> type() {
return VaultUsernamePasswordCredentialImpl.class;
}

@Override
public VaultUsernamePasswordCredentialImpl snapshot(VaultUsernamePasswordCredentialImpl credentials) {
return new SelfContained(credentials);

Check warning on line 149 in src/main/java/com/datapipe/jenkins/vault/credentials/common/VaultUsernamePasswordCredentialImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 122-149 are not covered by tests
}
}
}

0 comments on commit d49bf74

Please sign in to comment.