Use pointers more consistently, allow "fetch" tag validation to check SharedTags too
This commit is contained in:
parent
78186ac78f
commit
7e50189a05
|
|
@ -9,6 +9,13 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func validateTagName(man *Manifest2822, repoName, tagName string) error {
|
||||
if tagName != "" && (man.GetTag(tagName) == nil && len(man.GetSharedTag(tagName)) == 0) {
|
||||
return fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// "library" is the default "library directory"
|
||||
// returns the parsed version of (in order):
|
||||
// if "repo" is a URL, the remote contents of that URL
|
||||
|
|
@ -33,10 +40,10 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
man, err := Parse(resp.Body)
|
||||
if tagName != "" && man.GetTag(tagName) == nil {
|
||||
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
|
||||
if err != nil {
|
||||
return repoName, tagName, man, err
|
||||
}
|
||||
return repoName, tagName, man, err
|
||||
return repoName, tagName, man, validateTagName(man, repoName, tagName)
|
||||
}
|
||||
|
||||
// try file paths
|
||||
|
|
@ -55,10 +62,10 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
|
|||
if err == nil {
|
||||
defer f.Close()
|
||||
man, err := Parse(f)
|
||||
if tagName != "" && man.GetTag(tagName) == nil {
|
||||
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
|
||||
if err != nil {
|
||||
return repoName, tagName, man, err
|
||||
}
|
||||
return repoName, tagName, man, err
|
||||
return repoName, tagName, man, validateTagName(man, repoName, tagName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -308,20 +308,20 @@ func (entry Manifest2822Entry) HasArchitecture(arch string) bool {
|
|||
}
|
||||
|
||||
func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry {
|
||||
for _, entry := range manifest.Entries {
|
||||
for i, entry := range manifest.Entries {
|
||||
if entry.HasTag(tag) {
|
||||
return &entry
|
||||
return &manifest.Entries[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSharedTag returns a list of entries with the given tag in entry.SharedTags (or the empty list if there are no entries with the given tag).
|
||||
func (manifest Manifest2822) GetSharedTag(tag string) []Manifest2822Entry {
|
||||
ret := []Manifest2822Entry{}
|
||||
for _, entry := range manifest.Entries {
|
||||
func (manifest Manifest2822) GetSharedTag(tag string) []*Manifest2822Entry {
|
||||
ret := []*Manifest2822Entry{}
|
||||
for i, entry := range manifest.Entries {
|
||||
if entry.HasSharedTag(tag) {
|
||||
ret = append(ret, entry)
|
||||
ret = append(ret, &manifest.Entries[i])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
|
|
|||
Loading…
Reference in New Issue