Class SecretUtils
java.lang.Object
com.cloudbees.jenkins.plugins.kubernetes_credentials_provider.SecretUtils
Collection of utilities for working with
Secrets.
Note: API may be subject to change.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Convert a String representation of the base64 encoded bytes back to a byte[].static StringConvert a String representation of the base64 encoded bytes of a UTF-8 String back to a String.static StringgetCredentialDescription(io.fabric8.kubernetes.api.model.Secret s) Obtain the credential description from a givenSecret.static StringgetCredentialId(io.fabric8.kubernetes.api.model.Secret s) Obtain the credential ID from a givenSecret.getCredentialItemScopes(io.fabric8.kubernetes.api.model.Secret s) Gets all item-group scopes from a secret.static com.cloudbees.plugins.credentials.CredentialsScopegetCredentialScope(io.fabric8.kubernetes.api.model.Secret s) Get the scope from a givenSecret.static StringgetKeyName(io.fabric8.kubernetes.api.model.Secret s, String key) Get the mapping for the specified key name.static StringgetNonNullSecretData(io.fabric8.kubernetes.api.model.Secret s, String key, String exceptionMessage) Get the data for the specified key (or the mapped key if key is mapped), or throw a CredentialsConvertionException if the data for the given key was not present..getOptionalSecretData(io.fabric8.kubernetes.api.model.Secret s, String key, String exceptionMessage) Get optional data for the specified key (or the mapped key if key is mapped)static <T> TrequireNonNull(T obj, String exceptionMessage) Checks thatobjis notnull.static <T> TrequireNonNull(T obj, String exceptionMessage, String mapped) Checks thatobjis notnull.
-
Constructor Details
-
SecretUtils
public SecretUtils()
-
-
Method Details
-
base64DecodeToString
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String base64DecodeToString(String s) Convert a String representation of the base64 encoded bytes of a UTF-8 String back to a String.- Parameters:
s- the base64 encoded String representation of the bytes.- Returns:
- the String or
nullif the string could not be converted.
-
base64Decode
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static byte[] base64Decode(String s) Convert a String representation of the base64 encoded bytes back to a byte[].- Parameters:
s- the base64 encoded representation of the bytes.- Returns:
- the byte[] or
nullif the string could not be converted.
-
getCredentialScope
public static com.cloudbees.plugins.credentials.CredentialsScope getCredentialScope(io.fabric8.kubernetes.api.model.Secret s) throws CredentialsConvertionException Get the scope from a givenSecret. If the label is empty, then it defaults to global scope.- Parameters:
s- the secret whose scope we want to obtain.- Returns:
- the scope for a given secret.
- Throws:
CredentialsConvertionException- if scope is invalid.
-
getCredentialItemScopes
Gets all item-group scopes from a secret. Format of the annotation: "['thisIsJobA', 'thisIsJobB', 'thisIsJobC/thisIsJobD']"- Parameters:
s- the secret whose item-group scope we want to obtain.- Returns:
- a set of all item-group scopes
-
getCredentialId
Obtain the credential ID from a givenSecret.- Parameters:
s- the secret whose id we want to obtain.- Returns:
- the credential ID for a given secret.
-
getCredentialDescription
@CheckForNull public static String getCredentialDescription(io.fabric8.kubernetes.api.model.Secret s) Obtain the credential description from a givenSecret.- Parameters:
s- the secret whose description we want to obtain.- Returns:
- the credential description for a given secret.
-
requireNonNull
public static <T> T requireNonNull(@Nullable T obj, String exceptionMessage) throws CredentialsConvertionException Checks thatobjis notnull.- Type Parameters:
T- the type of the obj.- Parameters:
obj- the Object to check fornull.exceptionMessage- detail message to be used in the event that a CredentialsConvertionException is thrown.- Returns:
objif notnull.- Throws:
CredentialsConvertionException- iffobjisnull.
-
requireNonNull
public static <T> T requireNonNull(@Nullable T obj, String exceptionMessage, @Nullable String mapped) throws CredentialsConvertionException Checks thatobjis notnull.- Type Parameters:
T- the type of the obj.- Parameters:
obj- the Object to check fornull.exceptionMessage- detail message to be used in the event that a CredentialsConvertionException is thrown.mapped- an optional mapping (adds a"mapped to " + mappedto the exception message if this is non null.- Returns:
objif notnull.- Throws:
CredentialsConvertionException- iffobjisnull.
-
getNonNullSecretData
public static String getNonNullSecretData(io.fabric8.kubernetes.api.model.Secret s, String key, String exceptionMessage) throws CredentialsConvertionException Get the data for the specified key (or the mapped key if key is mapped), or throw a CredentialsConvertionException if the data for the given key was not present..- Parameters:
s- the Secretkey- the key to get the data for (which may be mapped to another key).exceptionMessage- the detailMessage of the exception if the data for the key (or mapped key) was not present.- Returns:
- The data for the given key.
- Throws:
CredentialsConvertionException- if the data was not present.
-
getOptionalSecretData
public static Optional<String> getOptionalSecretData(io.fabric8.kubernetes.api.model.Secret s, String key, String exceptionMessage) throws CredentialsConvertionException Get optional data for the specified key (or the mapped key if key is mapped)- Parameters:
s- the Secretkey- the key to get the data for (which may be mapped to another key).exceptionMessage- the detailMessage of the exception if the data for the key (or mapped key) was not present.- Returns:
- Optional data for specified key
- Throws:
CredentialsConvertionException- if the data was not present.
-
getKeyName
Get the mapping for the specified key name. Secrets can override the defaults used by the plugin by specifying an attribute of the typejenkins.io/credentials-keybinding-namecontaining the custom name - for examplejenkins.io/credentials-keybinding-foo=wibble.- Parameters:
s- the secret to inspect for a custom name.key- the name of the key we are looking for.- Returns:
- the custom mapping for the key or
key(identical object) if there is no custom mapping.
-