Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-35983 - Add support to job import jobs in folders
- Loading branch information
1 parent
2b4a0f9
commit d33a547
Showing
19 changed files
with
1,025 additions
and
186 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
59 changes: 59 additions & 0 deletions
59
src/main/java/org/jenkins/ci/plugins/jobimport/CredentialsUtils.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,59 @@ | ||
package org.jenkins.ci.plugins.jobimport; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsMatchers; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; | ||
import com.cloudbees.plugins.credentials.domains.DomainRequirement; | ||
import com.google.common.base.Strings; | ||
import hudson.model.Item; | ||
import hudson.security.ACL; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.google.inject.internal.guava.base.$Preconditions.checkNotNull; | ||
|
||
/** | ||
* Created by evildethow on 28/06/2016. | ||
*/ | ||
final class CredentialsUtils { | ||
|
||
private CredentialsUtils() { | ||
throw new UnsupportedOperationException("Cannot instantiate utility class"); | ||
} | ||
|
||
static NullSafeCredentials getCredentials(String credentialId) { | ||
if (!Strings.isNullOrEmpty(credentialId)) { | ||
StandardUsernamePasswordCredentials cred = CredentialsMatchers.firstOrNull(allCredentials(), CredentialsMatchers.withId(credentialId)); | ||
if (cred != null) { | ||
return new NullSafeCredentials(cred.getUsername(), cred.getPassword().getPlainText()); | ||
} | ||
} | ||
return new NullSafeCredentials(); | ||
} | ||
|
||
static List<StandardUsernamePasswordCredentials> allCredentials() { | ||
return CredentialsProvider.lookupCredentials( | ||
StandardUsernamePasswordCredentials.class, | ||
(Item) null, | ||
ACL.SYSTEM, | ||
Collections.<DomainRequirement>emptyList() | ||
); | ||
} | ||
|
||
static final class NullSafeCredentials { | ||
|
||
final String username; | ||
final String password; | ||
|
||
NullSafeCredentials(String username, String password) { | ||
this.username = checkNotNull(username); | ||
this.password = checkNotNull(password); | ||
} | ||
|
||
NullSafeCredentials() { | ||
this.username = ""; | ||
this.password = ""; | ||
} | ||
} | ||
} |
Oops, something went wrong.