-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snapshot credentials so they work on agents (#96)
- Loading branch information
Showing
7 changed files
with
215 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ buildNumber.properties | |
!/.mvn/wrapper/maven-wrapper.jar | ||
work/ | ||
*.dylib | ||
deployment.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/jenkinsci/plugins/azurekeyvaultplugin/credentials/Snapshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.credentials; | ||
|
||
import java.io.Serializable; | ||
import java.util.function.Supplier; | ||
|
||
public class Snapshot<T> implements Supplier<T>, Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final T value; | ||
|
||
public Snapshot(T value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public T get() { | ||
return value; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...enkinsci/plugins/azurekeyvaultplugin/credentials/string/AzureSecretStringCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.credentials.string; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.util.Secret; | ||
import java.util.function.Supplier; | ||
import org.jenkinsci.plugins.azurekeyvaultplugin.AzureCredentialsProvider; | ||
import org.jenkinsci.plugins.plaincredentials.StringCredentials; | ||
import org.jenkinsci.plugins.plaincredentials.impl.Messages; | ||
import org.jvnet.localizer.ResourceBundleHolder; | ||
|
||
public class AzureSecretStringCredentials extends BaseStandardCredentials implements StringCredentials { | ||
|
||
private final Supplier<Secret> value; | ||
|
||
public AzureSecretStringCredentials(String id, String description, Supplier<Secret> value) { | ||
super(id, description); | ||
this.value = value; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Secret getSecret() { | ||
return value.get(); | ||
} | ||
|
||
@Extension | ||
@SuppressWarnings("unused") | ||
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor { | ||
@Override | ||
@NonNull | ||
public String getDisplayName() { | ||
return ResourceBundleHolder.get(Messages.class).format("StringCredentialsImpl.secret_text"); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(CredentialsProvider provider) { | ||
return provider instanceof AzureCredentialsProvider; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ins/azurekeyvaultplugin/credentials/string/AzureSecretStringCredentialsSnapshotTaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.credentials.string; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker; | ||
import hudson.Extension; | ||
import hudson.util.Secret; | ||
import org.jenkinsci.plugins.azurekeyvaultplugin.credentials.Snapshot; | ||
|
||
@Extension | ||
@SuppressWarnings("unused") | ||
public class AzureSecretStringCredentialsSnapshotTaker extends CredentialsSnapshotTaker<AzureSecretStringCredentials> { | ||
@Override | ||
public Class<AzureSecretStringCredentials> type() { | ||
return AzureSecretStringCredentials.class; | ||
} | ||
|
||
@Override | ||
public AzureSecretStringCredentials snapshot(AzureSecretStringCredentials credential) { | ||
SecretSnapshot secretSnapshot = new SecretSnapshot(credential.getSecret()); | ||
return new AzureSecretStringCredentials(credential.getId(), credential.getDescription(), secretSnapshot); | ||
} | ||
|
||
private static class SecretSnapshot extends Snapshot<Secret> { | ||
SecretSnapshot(Secret value) { | ||
super(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ultplugin/credentials/usernamepassword/AzureUsernamePasswordCredentialsSnapshotTaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.credentials.usernamepassword; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker; | ||
import hudson.Extension; | ||
import hudson.util.Secret; | ||
import org.jenkinsci.plugins.azurekeyvaultplugin.credentials.Snapshot; | ||
|
||
@Extension | ||
@SuppressWarnings("unused") | ||
public class AzureUsernamePasswordCredentialsSnapshotTaker extends CredentialsSnapshotTaker<AzureUsernamePasswordCredentials> { | ||
@Override | ||
public Class<AzureUsernamePasswordCredentials> type() { | ||
return AzureUsernamePasswordCredentials.class; | ||
} | ||
|
||
@Override | ||
public AzureUsernamePasswordCredentials snapshot(AzureUsernamePasswordCredentials credential) { | ||
SecretSnapshot secretSnapshot = new SecretSnapshot(credential.getPassword()); | ||
return new AzureUsernamePasswordCredentials(credential.getId(), credential.getUsername(), credential.getDescription(), secretSnapshot); | ||
} | ||
|
||
private static class SecretSnapshot extends Snapshot<Secret> { | ||
SecretSnapshot(Secret value) { | ||
super(value); | ||
} | ||
} | ||
} |