Browse Source

Validate (and deduplicate) Architectures values

Tianon Gravi 8 years ago
parent
commit
d60142b532

+ 3 - 4
bashbrew/go/src/bashbrew/cmd-put-shared.go

@@ -22,14 +22,13 @@ func entriesToManifestToolYaml(r Repo, entries ...*manifest.Manifest2822Entry) (
 
 			var ociArch architecture.OCIPlatform
 			if ociArch, ok = architecture.SupportedArches[arch]; !ok {
-				// skip unsupported arches
-				// TODO turn this into explicit validation checks at "parse" time instead (so that unsupported arches result in concrete user-facing errors long before this block of code)
-				continue
+				// this should never happen -- the parser validates Architectures
+				panic("somehow, an unsupported architecture slipped past the parser validation: " + arch)
 			}
 
 			var archNamespace string
 			if archNamespace, ok = archNamespaces[arch]; !ok || archNamespace == "" {
-				fmt.Fprintf(os.Stderr, "warning: no arch-namespace specified for %q; skipping %q\n", arch, r.EntryIdentifier(*entry))
+				fmt.Fprintf(os.Stderr, "warning: no arch-namespace specified for %q; skipping (%q)\n", arch, r.EntryIdentifier(*entry))
 				continue
 			}
 

+ 1 - 1
bashbrew/go/vendor/manifest

@@ -10,7 +10,7 @@
 		{
 			"importpath": "github.com/docker-library/go-dockerlibrary",
 			"repository": "https://github.com/docker-library/go-dockerlibrary",
-			"revision": "4fd80f3c84b66d3a62d907359f540c9417745f79",
+			"revision": "29d359eaa1fda9e522de1ee6994edf8c85eb5665",
 			"branch": "master"
 		},
 		{

+ 3 - 3
bashbrew/go/vendor/src/github.com/docker-library/go-dockerlibrary/manifest/example_test.go

@@ -19,7 +19,7 @@ GitFetch: refs/heads/master
 GitRepo: https://github.com/docker-library/golang.git
 SharedTags: latest
 arm64v8-GitRepo: https://github.com/docker-library/golang.git
-Architectures: amd64
+Architectures: amd64, amd64
 
 
  # hi
@@ -57,7 +57,7 @@ ppc64le-Directory: 1.5/ppc64le
 SharedTags: raspbian
 GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
 Tags: raspbian-s390x
-Architectures: s390x
+Architectures: s390x, i386
 
 
 `)))
@@ -115,7 +115,7 @@ i: g@h j
 	//
 	// Tags: raspbian-s390x
 	// SharedTags: raspbian
-	// Architectures: s390x
+	// Architectures: i386, s390x
 	// GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
 	//
 	// Shared Tag Groups:

+ 35 - 1
bashbrew/go/vendor/src/github.com/docker-library/go-dockerlibrary/manifest/rfc2822.go

@@ -8,6 +8,7 @@ import (
 	"sort"
 	"strings"
 
+	"github.com/docker-library/go-dockerlibrary/architecture"
 	"github.com/docker-library/go-dockerlibrary/pkg/stripper"
 
 	"pault.ag/go/debian/control"
@@ -364,11 +365,15 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
 		return fmt.Errorf("Tags %q missing one of GitRepo, GitFetch, or GitCommit", entry.TagsString())
 	}
 	if invalidMaintainers := entry.InvalidMaintainers(); len(invalidMaintainers) > 0 {
-		return fmt.Errorf("Tags %q has invalid Maintainers: %q (expected format %q)", strings.Join(invalidMaintainers, ", "), MaintainersFormat)
+		return fmt.Errorf("Tags %q has invalid Maintainers: %q (expected format %q)", entry.TagsString(), strings.Join(invalidMaintainers, ", "), MaintainersFormat)
 	}
 
 	entry.DeduplicateSharedTags()
 
+	if invalidArchitectures := entry.InvalidArchitectures(); len(invalidArchitectures) > 0 {
+		return fmt.Errorf("Tags %q has invalid Architectures: %q", entry.TagsString(), strings.Join(invalidArchitectures, ", "))
+	}
+
 	seenTag := map[string]bool{}
 	for _, tag := range entry.Tags {
 		if otherEntry := manifest.GetTag(tag); otherEntry != nil {
@@ -428,6 +433,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
 	return invalid
 }
 
+func (entry Manifest2822Entry) InvalidArchitectures() []string {
+	invalid := []string{}
+	for _, arch := range entry.Architectures {
+		if _, ok := architecture.SupportedArches[arch]; !ok {
+			invalid = append(invalid, arch)
+		}
+	}
+	return invalid
+}
+
 // DeduplicateSharedTags will remove duplicate values from entry.SharedTags, preserving order.
 func (entry *Manifest2822Entry) DeduplicateSharedTags() {
 	aggregate := []string{}
@@ -442,6 +457,21 @@ func (entry *Manifest2822Entry) DeduplicateSharedTags() {
 	entry.SharedTags = aggregate
 }
 
+// DeduplicateArchitectures will remove duplicate values from entry.Architectures and sort the result.
+func (entry *Manifest2822Entry) DeduplicateArchitectures() {
+	aggregate := []string{}
+	seen := map[string]bool{}
+	for _, arch := range entry.Architectures {
+		if seen[arch] {
+			continue
+		}
+		seen[arch] = true
+		aggregate = append(aggregate, arch)
+	}
+	sort.Strings(aggregate)
+	entry.Architectures = aggregate
+}
+
 type decoderWrapper struct {
 	*control.Decoder
 }
@@ -471,6 +501,7 @@ func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error {
 		if len(entry.Architectures) == 0 {
 			entry.Architectures = arches
 		}
+		entry.DeduplicateArchitectures()
 
 		// pull out any new architecture-specific values from Paragraph.Values
 		entry.SeedArchValues()
@@ -504,6 +535,9 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
 	if len(manifest.Global.Tags) > 0 {
 		return nil, fmt.Errorf("global Tags not permitted")
 	}
+	if invalidArchitectures := manifest.Global.InvalidArchitectures(); len(invalidArchitectures) > 0 {
+		return nil, fmt.Errorf("invalid global Architectures: %q", strings.Join(invalidArchitectures, ", "))
+	}
 
 	for {
 		entry := manifest.Global.Clone()