Skip to content

Commit

Permalink
Merge pull request #327 from jamesrobson-secondmind/add-username-pwd-…
Browse files Browse the repository at this point in the history
…snapshottaker

Add snapshot taker for special `StandardUsernamePasswordCredentials` impls
  • Loading branch information
jglick authored Jul 1, 2022
2 parents b3b2f1c + 69e3682 commit eb9579f
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cloudbees.plugins.credentials.impl;

import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;

import hudson.Extension;
import hudson.util.Secret;

@Extension
public class UsernamePasswordCredentialsSnapshotTaker extends CredentialsSnapshotTaker<StandardUsernamePasswordCredentials> {

/**
* {@inheritDoc}
*/
@Override
public Class<StandardUsernamePasswordCredentials> type() {
return StandardUsernamePasswordCredentials.class;
}

/**
* {@inheritDoc}
*/
@Override
public StandardUsernamePasswordCredentials snapshot(StandardUsernamePasswordCredentials credentials) {
if (credentials instanceof UsernamePasswordCredentialsImpl) {
return credentials;
}
UsernamePasswordCredentialsImpl snapshot = new UsernamePasswordCredentialsImpl(credentials.getScope(), credentials.getId(), credentials.getDescription(), credentials.getUsername(), Secret.toString(credentials.getPassword()));
snapshot.setUsernameSecret(credentials.isUsernameSecret());
return snapshot;
}
}

0 comments on commit eb9579f

Please sign in to comment.