Package com.parallels.jenkins
Class CredentialsHelper
java.lang.Object
com.parallels.jenkins.CredentialsHelper
Centralised credential lookup for the Parallels DevOps plugin.
All calls to CredentialsProvider.lookupCredentials(java.lang.Class<C>) are funnelled
through this class so that no inline lookups are scattered across
PrlDevopsCloud or PrlDevopsComputerLauncher.
Methods prefixed find return null when the credential is
absent; methods prefixed require throw CredentialsNotFoundException
instead of returning null, preventing silent NullPointerExceptions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.jenkinsci.plugins.plaincredentials.StringCredentialsfindStringCredential(String credentialsId, ItemGroup<?> context) Looks up aStringCredentialsby ID.static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentialsfindUsernamePasswordCredential(String credentialsId, ItemGroup<?> context) Looks up aStandardUsernamePasswordCredentialsby ID.static com.cloudbees.plugins.credentials.common.StandardUsernameCredentialsrequireSshCredential(String credentialsId, ItemGroup<?> context) Looks up an SSH credential (StandardUsernameCredentials) by ID, throwing if absent.static org.jenkinsci.plugins.plaincredentials.StringCredentialsrequireStringCredential(String credentialsId, ItemGroup<?> context) Looks up aStringCredentialsby ID, throwing if absent.static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentialsrequireUsernamePasswordCredential(String credentialsId, ItemGroup<?> context) Looks up aStandardUsernamePasswordCredentialsby ID, throwing if absent.
-
Method Details
-
findStringCredential
@CheckForNull public static org.jenkinsci.plugins.plaincredentials.StringCredentials findStringCredential(@NonNull String credentialsId, @NonNull ItemGroup<?> context) Looks up aStringCredentialsby ID.- Returns:
- the credential, or
nullif not found
-
requireStringCredential
@NonNull public static org.jenkinsci.plugins.plaincredentials.StringCredentials requireStringCredential(@NonNull String credentialsId, @NonNull ItemGroup<?> context) throws CredentialsNotFoundException Looks up aStringCredentialsby ID, throwing if absent.- Throws:
CredentialsNotFoundException- if the credential cannot be resolved
-
findUsernamePasswordCredential
@CheckForNull public static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials findUsernamePasswordCredential(@NonNull String credentialsId, @NonNull ItemGroup<?> context) Looks up aStandardUsernamePasswordCredentialsby ID.- Returns:
- the credential, or
nullif not found
-
requireUsernamePasswordCredential
@NonNull public static com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials requireUsernamePasswordCredential(@NonNull String credentialsId, @NonNull ItemGroup<?> context) throws CredentialsNotFoundException Looks up aStandardUsernamePasswordCredentialsby ID, throwing if absent.- Throws:
CredentialsNotFoundException- if the credential cannot be resolved
-
requireSshCredential
@NonNull public static com.cloudbees.plugins.credentials.common.StandardUsernameCredentials requireSshCredential(@NonNull String credentialsId, @NonNull ItemGroup<?> context) throws CredentialsNotFoundException Looks up an SSH credential (StandardUsernameCredentials) by ID, throwing if absent.StandardUsernameCredentialsis the common supertype for bothStandardUsernamePasswordCredentials(username + password) andBasicSSHUserPrivateKey(username + private key), so a single lookup covers all SSH authentication modes.- Throws:
CredentialsNotFoundException- if the credential cannot be resolved
-