...

Source file src/github.com/opencontainers/image-spec/schema/schema.go

Documentation: github.com/opencontainers/image-spec/schema

     1  // Copyright 2016 The Linux Foundation
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package schema
    16  
    17  import (
    18  	"embed"
    19  	"net/http"
    20  
    21  	v1 "github.com/opencontainers/image-spec/specs-go/v1"
    22  )
    23  
    24  // Media types for the OCI image formats
    25  const (
    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
    32  )
    33  
    34  var (
    35  	// fs stores the embedded http.FileSystem
    36  	// having the OCI JSON schema files in root "/".
    37  	//go:embed *.json
    38  	fs embed.FS
    39  
    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/",
    60  	}
    61  
    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",
    71  	}
    72  )
    73  
    74  // FileSystem returns an in-memory filesystem including the schema files.
    75  // The schema files are located at the root directory.
    76  func FileSystem() http.FileSystem {
    77  	return http.FS(fs)
    78  }
    79  

View as plain text