Class ImageNameValidator
- java.lang.Object
-
- org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator
-
public class ImageNameValidator extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
VALID_DIGEST
A content digest specified by open container spec.static Pattern
VALID_DIGEST_SHA256
A SHA-256 content digest specified by open container spec.static Pattern
VALID_DIGEST_SHA512
A SHA-512 content digest specified by open container spec.static Pattern
VALID_NAME_COMPONENT
Name components may contain lowercase letters, digits and separators.static Pattern
VALID_TAG
A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
-
Constructor Summary
Constructors Constructor Description ImageNameValidator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkName(String name)
CallsvalidateName(String)
and if not OK throws the exception.static void
checkTag(String tag)
CallsvalidateTag(String)
and if not OK throws the exception.static void
checkUserAndRepo(String userAndRepo)
CallsvalidateUserAndRepo(String)
and if the result is not OK throws it as an exception.static boolean
skipped()
If the validation is set to be skipped.static String[]
splitUserAndRepo(String userAndRepo)
Splits a repository id namespace/name into it's four components (repo/namespace[/*],name,tag, digest)static FormValidation
validateDigest(String digest)
Validates a digest is following the rules.static FormValidation
validateName(String name)
Validates a docker image name that it is following the rules as a single name component.static FormValidation
validateTag(String tag)
Validates a tag is following the rules.static FormValidation
validateUserAndRepo(String userAndRepo)
Validates the string as[registry/repo/]name[:tag]
-
-
-
Field Detail
-
VALID_DIGEST
public static final Pattern VALID_DIGEST
A content digest specified by open container spec.- See Also:
- Content Digests OCI Digests
-
VALID_DIGEST_SHA256
public static final Pattern VALID_DIGEST_SHA256
A SHA-256 content digest specified by open container spec.- See Also:
- Content Digests OCI Digests
-
VALID_DIGEST_SHA512
public static final Pattern VALID_DIGEST_SHA512
A SHA-512 content digest specified by open container spec.- See Also:
- Content Digests OCI Digests
-
VALID_TAG
public static final Pattern VALID_TAG
A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.- See Also:
- docker tag
-
VALID_NAME_COMPONENT
public static final Pattern VALID_NAME_COMPONENT
Name components may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.- See Also:
- docker tag
-
-
Method Detail
-
skipped
public static boolean skipped()
If the validation is set to be skipped. I.e. the system propertyorg.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.SKIP
is set totrue
. When this is se to truevalidateName(String)
,validateTag(String)
andvalidateUserAndRepo(String)
returnsFormValidation.ok()
immediately without performing the validation.- Returns:
- true if validation is skipped.
-
splitUserAndRepo
@NonNull public static String[] splitUserAndRepo(@NonNull String userAndRepo)
Splits a repository id namespace/name into it's four components (repo/namespace[/*],name,tag, digest)- Parameters:
userAndRepo
- the repository ID namespace/name (ie. "jenkinsci/workflow-demo:latest"). The namespace can have more than one path element.- Returns:
- an array where position 0 is the namespace, 1 is the name and 2 is the tag and 3 is the digest.
Any position could be
null
-
validateUserAndRepo
@NonNull public static FormValidation validateUserAndRepo(@NonNull String userAndRepo)
Validates the string as[registry/repo/]name[:tag]
- Parameters:
userAndRepo
- the image id- Returns:
- if it is valid or not, or OK if set to
SKIP
. - See Also:
VALID_NAME_COMPONENT
,VALID_TAG
-
checkUserAndRepo
public static void checkUserAndRepo(@NonNull String userAndRepo) throws FormValidation
CallsvalidateUserAndRepo(String)
and if the result is not OK throws it as an exception.- Parameters:
userAndRepo
- the image id- Throws:
FormValidation
- if not OK
-
validateDigest
@NonNull public static FormValidation validateDigest(@CheckForNull String digest)
Validates a digest is following the rules. If the tag is null or the empty string it is considered valid.- Parameters:
digest
- the digest to validate.- Returns:
- the validation result
- See Also:
VALID_DIGEST
-
validateTag
@NonNull public static FormValidation validateTag(@CheckForNull String tag)
Validates a tag is following the rules. If the tag is null or the empty string it is considered valid.- Parameters:
tag
- the tag to validate.- Returns:
- the validation result
- See Also:
VALID_TAG
-
checkTag
public static void checkTag(@CheckForNull String tag) throws FormValidation
CallsvalidateTag(String)
and if not OK throws the exception.- Parameters:
tag
- the tag- Throws:
FormValidation
- if not OK
-
validateName
@NonNull public static FormValidation validateName(@CheckForNull String name)
Validates a docker image name that it is following the rules as a single name component. If the name is null or the empty string it is not considered valid.- Parameters:
name
- the name- Returns:
- the validation result
- See Also:
VALID_NAME_COMPONENT
-
checkName
public static void checkName(String name) throws FormValidation
CallsvalidateName(String)
and if not OK throws the exception.- Parameters:
name
- the name- Throws:
FormValidation
- if not OK
-
-