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"
|
"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"
|
// "library" is the default "library directory"
|
||||||
// returns the parsed version of (in order):
|
// returns the parsed version of (in order):
|
||||||
// if "repo" is a URL, the remote contents of that URL
|
// if "repo" is a URL, the remote contents of that URL
|
||||||
|
|
@ -33,11 +40,11 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
man, err := Parse(resp.Body)
|
man, err := Parse(resp.Body)
|
||||||
if tagName != "" && man.GetTag(tagName) == nil {
|
if err != nil {
|
||||||
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
|
|
||||||
}
|
|
||||||
return repoName, tagName, man, err
|
return repoName, tagName, man, err
|
||||||
}
|
}
|
||||||
|
return repoName, tagName, man, validateTagName(man, repoName, tagName)
|
||||||
|
}
|
||||||
|
|
||||||
// try file paths
|
// try file paths
|
||||||
filePaths := []string{}
|
filePaths := []string{}
|
||||||
|
|
@ -55,11 +62,11 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
man, err := Parse(f)
|
man, err := Parse(f)
|
||||||
if tagName != "" && man.GetTag(tagName) == nil {
|
if err != nil {
|
||||||
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
|
|
||||||
}
|
|
||||||
return repoName, tagName, man, err
|
return repoName, tagName, man, err
|
||||||
}
|
}
|
||||||
|
return repoName, tagName, man, validateTagName(man, repoName, tagName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return repoName, tagName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, library)
|
return repoName, tagName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, library)
|
||||||
|
|
|
||||||
|
|
@ -308,20 +308,20 @@ func (entry Manifest2822Entry) HasArchitecture(arch string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry {
|
func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry {
|
||||||
for _, entry := range manifest.Entries {
|
for i, entry := range manifest.Entries {
|
||||||
if entry.HasTag(tag) {
|
if entry.HasTag(tag) {
|
||||||
return &entry
|
return &manifest.Entries[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
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).
|
// 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 {
|
func (manifest Manifest2822) GetSharedTag(tag string) []*Manifest2822Entry {
|
||||||
ret := []Manifest2822Entry{}
|
ret := []*Manifest2822Entry{}
|
||||||
for _, entry := range manifest.Entries {
|
for i, entry := range manifest.Entries {
|
||||||
if entry.HasSharedTag(tag) {
|
if entry.HasSharedTag(tag) {
|
||||||
ret = append(ret, entry)
|
ret = append(ret, &manifest.Entries[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue