Skip to content

Commit

Permalink
run/image: Copy in consts and parser error definitions.
Browse files Browse the repository at this point in the history
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 <a.jung@lancs.ac.uk>
  • Loading branch information
nderjung committed Dec 22, 2020
1 parent 4fbb108 commit faa0f75
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions run/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit faa0f75

Please sign in to comment.