Add "(Shared)Tags" validation
This commit is contained in:
parent
c37ef753c4
commit
3ff8c5ce0d
|
|
@ -18,6 +18,9 @@ import (
|
||||||
var (
|
var (
|
||||||
GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,64}$`)
|
GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,64}$`)
|
||||||
GitFetchRegex = regexp.MustCompile(`^refs/(heads|tags)/[^*?:]+$`)
|
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 {
|
type Manifest2822 struct {
|
||||||
|
|
@ -395,6 +398,9 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
|
||||||
entry.DeduplicateSharedTags()
|
entry.DeduplicateSharedTags()
|
||||||
entry.CleanDirectoryValues()
|
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 {
|
if invalidArchitectures := entry.InvalidArchitectures(); len(invalidArchitectures) > 0 {
|
||||||
return fmt.Errorf("Tags %q has invalid Architectures: %q", entry.TagsString(), strings.Join(invalidArchitectures, ", "))
|
return fmt.Errorf("Tags %q has invalid Architectures: %q", entry.TagsString(), strings.Join(invalidArchitectures, ", "))
|
||||||
}
|
}
|
||||||
|
|
@ -458,6 +464,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
|
||||||
return invalid
|
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 {
|
func (entry Manifest2822Entry) InvalidArchitectures() []string {
|
||||||
invalid := []string{}
|
invalid := []string{}
|
||||||
for _, arch := range entry.Architectures {
|
for _, arch := range entry.Architectures {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue