@@ -33,7 +33,9 @@ type Validator string
3333type validateDescendantsFunc func (r io.Reader ) error
3434
3535var mapValidateDescendants = map [Validator ]validateDescendantsFunc {
36- MediaTypeManifest : validateManifestDescendants ,
36+ MediaTypeImageConfig : validateConfigDescendants ,
37+ MediaTypeManifest : validateManifestDescendants ,
38+ MediaTypeManifestList : validateManifestListDescendants ,
3739}
3840
3941// ValidationError contains all the errors that happened during validation.
@@ -117,3 +119,68 @@ func validateManifestDescendants(r io.Reader) error {
117119 }
118120 return nil
119121}
122+
123+ func validateManifestListDescendants (r io.Reader ) error {
124+ header := v1.ManifestList {}
125+
126+ buf , err := ioutil .ReadAll (r )
127+ if err != nil {
128+ return errors .Wrapf (err , "error reading the io stream" )
129+ }
130+
131+ err = json .Unmarshal (buf , & header )
132+ if err != nil {
133+ return errors .Wrap (err , "manifestlist format mismatch" )
134+ }
135+
136+ for _ , manifest := range header .Manifests {
137+ if err = checkPlatform (manifest .Platform .OS , manifest .Platform .Architecture ); err != nil {
138+ return errors .Wrap (err , "check Platform error" )
139+ }
140+ }
141+ return nil
142+ }
143+
144+ func validateConfigDescendants (r io.Reader ) error {
145+ header := v1.Image {}
146+
147+ buf , err := ioutil .ReadAll (r )
148+ if err != nil {
149+ return errors .Wrapf (err , "error reading the io stream" )
150+ }
151+
152+ err = json .Unmarshal (buf , & header )
153+ if err != nil {
154+ return errors .Wrap (err , "config format mismatch" )
155+ }
156+
157+ if err = checkPlatform (header .OS , header .Architecture ); err != nil {
158+ return errors .Wrap (err , "check Platform error" )
159+ }
160+ return nil
161+ }
162+
163+ func checkPlatform (OS string , Architecture string ) error {
164+ validCombins := map [string ][]string {
165+ "android" : {"arm" }
166+ "darwin" : {"386" , "amd64" , "arm" , "arm64" },
167+ "dragonfly" : {"amd64" },
168+ "freebsd" : {"386" , "amd64" , "arm" },
169+ "linux" : {"386" , "amd64" , "arm" , "arm64" , "ppc64" , "ppc64le" , "mips64" , "mips64le" },
170+ "netbsd" : {"386" , "amd64" , "arm" },
171+ "openbsd" : {"386" , "amd64" , "arm" },
172+ "plan9" : {"386" , "amd64" },
173+ "solaris" : {"amd64" },
174+ "windows" : {"386" , "amd64" }}
175+ for os , archs := range validCombins {
176+ if os == OS {
177+ for _ , arch := range archs {
178+ if arch == Architecture {
179+ return nil
180+ }
181+ }
182+ return fmt .Errorf ("Combination of %q and %q is invalid." , OS , Architecture )
183+ }
184+ }
185+ return fmt .Errorf ("Operation system %q of the bundle is not supported yet." , OS )
186+ }
0 commit comments