private String getApiToken(String apiTokenId) { StandardCredentials credentials = CredentialsMatchers.firstOrNull( lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, new ArrayList<DomainRequirement>()), CredentialsMatchers.withId(apiTokenId)); if (credentials != null) { if (credentials instanceof GitLabApiToken) { return ((GitLabApiToken) credentials).getApiToken().getPlainText(); } if (credentials instanceof StringCredentials) { return ((StringCredentials) credentials).getSecret().getPlainText(); } } throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId); }
@CheckForNull public static AmazonWebServicesCredentials getCredentials(@Nullable String credentialsId, ItemGroup context) { if (StringUtils.isBlank(credentialsId)) { return null; } return (AmazonWebServicesCredentials) CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, context, ACL.SYSTEM, Collections.EMPTY_LIST), CredentialsMatchers.withId(credentialsId)); }
/** * @return null when the credentials are not found. */ public static @CheckForNull OpenstackCredential getCredential(@CheckForNull String credentialId) { if (credentialId == null) return null; List<OpenstackCredential> credentials = CredentialsProvider.lookupCredentials( OpenstackCredential.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.emptyList() ); return CredentialsMatchers.firstOrNull(credentials, CredentialsMatchers.withId(credentialId)); }
private StandardCredentials retrieveCredential(String credentialId) { if (StringUtils.isNotEmpty(credentialId)) { return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList() ), CredentialsMatchers.withId(credentialId) ); } return null; }
static StandardUsernamePasswordCredentials findCredential(final String hostName, final String credentialsId) { final List<StandardUsernamePasswordCredentials> matches = findCredentials(hostName); final CredentialsMatcher matcher = CredentialsMatchers.withId(credentialsId); final StandardUsernamePasswordCredentials result = CredentialsMatchers.firstOrNull(matches, matcher); return result; }
private StandardUsernameCredentials lookupCredentialsById(final String credentialId) { final List<StandardUsernameCredentials> all = CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, (Item) null, ACL.SYSTEM, NO_REQUIREMENTS); return CredentialsMatchers.firstOrNull(all, CredentialsMatchers.withId(credentialId)); }
private StandardCredentials getCredentials(String credentials) { return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(credentials) ); }
private static String gitLabApiToken(String id) { StandardCredentials credentials = CredentialsMatchers.firstOrNull( lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, new ArrayList<DomainRequirement>()), CredentialsMatchers.withId(id)); if (credentials != null) { if (credentials instanceof GitLabApiToken) { return ((GitLabApiToken) credentials).getApiToken().getPlainText(); } } throw new IllegalStateException("No gitlab-api-token found for id: " + id); } }
private String getPrivateKeyFromCredential(final String id) { if (!Strings.isNullOrEmpty(id)) { SSHUserPrivateKey supk = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(id)); return CredentialsHelper.getPrivateKey(supk); } return ""; }
private static SSLConfig toSSlConfig(String credentialsId) { if (credentialsId == null) return null; DockerServerCredentials credentials = firstOrNull( lookupCredentials( DockerServerCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), withId(credentialsId)); return credentials == null ? null : new DockerServerCredentialsSSLConfig(credentials); }
public static StandardUsernameCredentials lookupSystemCredentials(String credentialsId) { return CredentialsMatchers.firstOrNull( CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, SSH_SCHEME), CredentialsMatchers.withId(credentialsId) ); }
@CheckForNull private static AmazonWebServicesCredentials getCredentials(@Nullable String credentialsId) { if (StringUtils.isBlank(credentialsId)) { return null; } return (AmazonWebServicesCredentials) CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.emptyList()), CredentialsMatchers.withId(credentialsId)); }
public static StandardUsernameCredentials lookupSystemCredentials(String credentialsId) { return CredentialsMatchers.firstOrNull( CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, SSH_SCHEME), CredentialsMatchers.withId(credentialsId) ); }
private <T extends StandardCredentials> T credentials(AbstractGitSCMSource source, @Nonnull Class<T> type) { String credentialsId = source.getCredentialsId(); if (credentialsId == null) { return null; } return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials( type, source.getOwner(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId), CredentialsMatchers.instanceOf(type))); } }
public static StandardUsernameCredentials lookupSystemCredentials(String credentialsId, String host, int port) { return CredentialsMatchers.firstOrNull( CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, SSH_SCHEME, new HostnamePortRequirement(host, port)), CredentialsMatchers.withId(credentialsId) ); }
public static StandardUsernameCredentials lookupSystemCredentials(String credentialsId, String host, int port) { return CredentialsMatchers.firstOrNull( CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, SSH_SCHEME, new HostnamePortRequirement(host, port)), CredentialsMatchers.withId(credentialsId) ); }
private static StandardCredentials lookupCredentials(@CheckForNull Item project, String credentialId, String uri) { return (credentialId == null) ? null : CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, project, ACL.SYSTEM, GitURIRequirementsBuilder.fromUri(uri).build()), CredentialsMatchers.withId(credentialId)); }
private static StandardCredentials lookupCredentials(Item context, String credentialsId, SVNURL repoURL) { return credentialsId == null ? null : CredentialsMatchers.firstOrNull(CredentialsProvider .lookupCredentials(StandardCredentials.class, context, ACL.SYSTEM, URIRequirementBuilder.fromUri(repoURL.toString()).build()), CredentialsMatchers.withId(credentialsId)); }
public String getJenkinsPrivateKey() { if (isNullOrEmpty(credentialsId)) { return getCloud().getGlobalPrivateKey(); } SSHUserPrivateKey supk = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(credentialsId)); return CredentialsHelper.getPrivateKey(supk); }
private SVNRepositoryView openSession(SVNURL repoURL) throws SVNException, IOException { return new SVNRepositoryView(repoURL, credentialsId == null ? null : CredentialsMatchers .firstOrNull(CredentialsProvider.lookupCredentials(StandardCredentials.class, getOwner(), ACL.SYSTEM, URIRequirementBuilder.fromUri(repoURL.toString()).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardCredentials.class), CredentialsMatchers.instanceOf(SSHUserPrivateKey.class))))); }