From faa0f758d8503260def8b05dc8aba094f9502cef Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Tue, 22 Dec 2020 16:43:33 +0100 Subject: [PATCH] run/image: Copy in consts and parser error definitions. This copies definitions and errors verbatim from [0]. [0]: https://github.com/novln/docker-parser/blob/d237083ad01bcd08414b0b0d31a29fa4edc2c4fe/distribution/reference/reference.go#L31-L51 Signed-off-by: Alexander Jung --- run/image.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/run/image.go b/run/image.go index e89243e..b0e33c3 100644 --- a/run/image.go +++ b/run/image.go @@ -20,6 +20,33 @@ package run // If an error was encountered it is returned, along with a nil Reference. // NOTE: Parse will not handle short digests. +import ( + "fmt" + "errors" +) + +const ( + // NameTotalLengthMax is the maximum total number of characters in a repository name. + NameTotalLengthMax = 255 +) + +var ( + // ErrReferenceInvalidFormat represents an error while trying to parse a string as a reference. + ErrReferenceInvalidFormat = errors.New("invalid reference format") + + // ErrTagInvalidFormat represents an error while trying to parse a string as a tag. + ErrTagInvalidFormat = errors.New("invalid tag format") + + // ErrDigestInvalidFormat represents an error while trying to parse a string as a tag. + ErrDigestInvalidFormat = errors.New("invalid digest format") + + // ErrNameEmpty is returned for empty, invalid repository names. + ErrNameEmpty = errors.New("repository name must have at least one component") + + // ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax. + ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", NameTotalLengthMax) +) + func Parse(s string) (Reference, error) { matches := ReferenceRegexp.FindStringSubmatch(s) if matches == nil {