Skip to content
This repository was archived by the owner on Aug 22, 2020. It is now read-only.

Add "(Shared)Tags" validation #21

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions manifest/rfc2822.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
var (
GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,64}$`)
GitFetchRegex = regexp.MustCompile(`^refs/(heads|tags)/[^*?:]+$`)

// https://github.com/docker/distribution/blob/v2.7.1/reference/regexp.go#L37
ValidTagRegex = regexp.MustCompile(`^\w[\w.-]{0,127}$`)
)

type Manifest2822 struct {
Expand Down Expand Up @@ -395,6 +398,9 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
entry.DeduplicateSharedTags()
entry.CleanDirectoryValues()

if invalidTags := entry.InvalidTags(); len(invalidTags) > 0 {
return fmt.Errorf("Tags %q has invalid (Shared)Tags: %q", entry.TagsString(), strings.Join(invalidTags, ", "))
}
if invalidArchitectures := entry.InvalidArchitectures(); len(invalidArchitectures) > 0 {
return fmt.Errorf("Tags %q has invalid Architectures: %q", entry.TagsString(), strings.Join(invalidArchitectures, ", "))
}
Expand Down Expand Up @@ -458,6 +464,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
return invalid
}

func (entry Manifest2822Entry) InvalidTags() []string {
invalid := []string{}
for _, tag := range append(append([]string{}, entry.Tags...), entry.SharedTags...) {
if !ValidTagRegex.MatchString(tag) {
invalid = append(invalid, tag)
}
}
return invalid
}

func (entry Manifest2822Entry) InvalidArchitectures() []string {
invalid := []string{}
for _, arch := range entry.Architectures {
Expand Down