@@ -23,56 +23,62 @@ import (
2323
2424// Media types for the OCI image formats
2525const (
26- ValidatorMediaTypeDescriptor Validator = v1 .MediaTypeDescriptor
27- ValidatorMediaTypeLayoutHeader Validator = v1 .MediaTypeLayoutHeader
28- ValidatorMediaTypeManifest Validator = v1 .MediaTypeImageManifest
29- ValidatorMediaTypeImageIndex Validator = v1 .MediaTypeImageIndex
30- ValidatorMediaTypeImageConfig Validator = v1 .MediaTypeImageConfig
31- ValidatorMediaTypeImageLayer unimplemented = v1 .MediaTypeImageLayer
26+ ValidatorMediaTypeDescriptor Validator = v1 .MediaTypeDescriptor
27+ ValidatorMediaTypeLayoutHeader Validator = v1 .MediaTypeLayoutHeader
28+ ValidatorMediaTypeManifest Validator = v1 .MediaTypeImageManifest
29+ ValidatorMediaTypeImageIndex Validator = v1 .MediaTypeImageIndex
30+ ValidatorMediaTypeImageConfig Validator = v1 .MediaTypeImageConfig
31+ ValidatorMediaTypeImageLayer Validator = v1 .MediaTypeImageLayer
3232)
3333
3434var (
35- // fs stores the embedded http.FileSystem
36- // having the OCI JSON schema files in root "/".
35+ // specFS stores the embedded http.FileSystem having the OCI JSON schema files in root "/".
3736 //go:embed *.json
38- fs embed.FS
37+ specFS embed.FS
3938
40- // schemaNamespaces is a set of URI prefixes which are treated as containing the schema files of fs.
41- // This is necessary because *.json schema files in this directory use "id" and "$ref" attributes which evaluate to such URIs, e.g.
42- // ./image-manifest-schema.json URI contains
43- // "id": "https://opencontainers.org/schema/image/manifest",
44- // and
45- // "$ref": "content-descriptor.json"
46- // which evaluates as a link to https://opencontainers.org/schema/image/content-descriptor.json .
47- //
48- // To support such links without accessing the network (and trying to load content which is not hosted at these URIs),
49- // fsLoaderFactory accepts any URI starting with one of the schemaNamespaces below,
50- // and uses _escFS to load them from the root of its in-memory filesystem tree.
51- //
52- // (Note that this must contain subdirectories before its parent directories for fsLoaderFactory.refContents to work.)
53- schemaNamespaces = []string {
54- "https://opencontainers.org/schema/image/descriptor/" ,
55- "https://opencontainers.org/schema/image/index/" ,
56- "https://opencontainers.org/schema/image/manifest/" ,
57- "https://opencontainers.org/schema/image/" ,
58- "https://opencontainers.org/schema/descriptor/" ,
59- "https://opencontainers.org/schema/" ,
39+ // specsOrig maps OCI schema media types to schema files.
40+ specs = map [Validator ]string {
41+ ValidatorMediaTypeDescriptor : "content-descriptor.json" ,
42+ ValidatorMediaTypeLayoutHeader : "image-layout-schema.json" ,
43+ ValidatorMediaTypeManifest : "image-manifest-schema.json" ,
44+ ValidatorMediaTypeImageIndex : "image-index-schema.json" ,
45+ ValidatorMediaTypeImageConfig : "config-schema.json" ,
6046 }
6147
62- // specs maps OCI schema media types to schema URIs.
63- // These URIs are expected to be used only by fsLoaderFactory (which trims schemaNamespaces defined above)
64- // and should never cause a network access.
65- specs = map [Validator ]string {
66- ValidatorMediaTypeDescriptor : "https://opencontainers.org/schema/content-descriptor.json" ,
67- ValidatorMediaTypeLayoutHeader : "https://opencontainers.org/schema/image/image-layout-schema.json" ,
68- ValidatorMediaTypeManifest : "https://opencontainers.org/schema/image/image-manifest-schema.json" ,
69- ValidatorMediaTypeImageIndex : "https://opencontainers.org/schema/image/image-index-schema.json" ,
70- ValidatorMediaTypeImageConfig : "https://opencontainers.org/schema/image/config-schema.json" ,
48+ // specURLs lists the various URLs a given spec may be known by.
49+ // This is generated from the "id" value in each spec and relative ref values they contain.
50+ specURLs = map [string ][]string {
51+ "config-schema.json" : {
52+ "https://opencontainers.org/schema/image/config" ,
53+ },
54+ "content-descriptor.json" : {
55+ "https://opencontainers.org/schema/descriptor" ,
56+ "https://opencontainers.org/schema/image/content-descriptor.json" ,
57+ },
58+ "defs-descriptor.json" : {
59+ "https://opencontainers.org/schema/image/descriptor/mediaType" ,
60+ "https://opencontainers.org/schema/defs-descriptor.json" ,
61+ "https://opencontainers.org/schema/image/defs-descriptor.json" ,
62+ },
63+ "defs.json" : {
64+ "https://opencontainers.org/schema/defs.json" ,
65+ "https://opencontainers.org/schema/image/defs.json" ,
66+ "https://opencontainers.org/schema/image/descriptor/defs.json" ,
67+ },
68+ "image-index-schema.json" : {
69+ "https://opencontainers.org/schema/image/index" ,
70+ },
71+ "image-layout-schema.json" : {
72+ "https://opencontainers.org/schema/image/layout" ,
73+ },
74+ "image-manifest-schema.json" : {
75+ "https://opencontainers.org/schema/image/manifest" ,
76+ },
7177 }
7278)
7379
7480// FileSystem returns an in-memory filesystem including the schema files.
7581// The schema files are located at the root directory.
7682func FileSystem () http.FileSystem {
77- return http .FS (fs )
83+ return http .FS (specFS )
7884}
0 commit comments