...

Source file src/github.com/google/go-containerregistry/pkg/v1/types/types.go

Documentation: github.com/google/go-containerregistry/pkg/v1/types

     1  // Copyright 2018 Google LLC All Rights Reserved.
     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 types holds common OCI media types.
    16  package types
    17  
    18  // MediaType is an enumeration of the supported mime types that an element of an image might have.
    19  type MediaType string
    20  
    21  // The collection of known MediaType values.
    22  const (
    23  	OCIContentDescriptor           MediaType = "application/vnd.oci.descriptor.v1+json"
    24  	OCIImageIndex                  MediaType = "application/vnd.oci.image.index.v1+json"
    25  	OCIManifestSchema1             MediaType = "application/vnd.oci.image.manifest.v1+json"
    26  	OCIConfigJSON                  MediaType = "application/vnd.oci.image.config.v1+json"
    27  	OCILayer                       MediaType = "application/vnd.oci.image.layer.v1.tar+gzip"
    28  	OCILayerZStd                   MediaType = "application/vnd.oci.image.layer.v1.tar+zstd"
    29  	OCIRestrictedLayer             MediaType = "application/vnd.oci.image.layer.nondistributable.v1.tar+gzip"
    30  	OCIUncompressedLayer           MediaType = "application/vnd.oci.image.layer.v1.tar"
    31  	OCIUncompressedRestrictedLayer MediaType = "application/vnd.oci.image.layer.nondistributable.v1.tar"
    32  
    33  	DockerManifestSchema1       MediaType = "application/vnd.docker.distribution.manifest.v1+json"
    34  	DockerManifestSchema1Signed MediaType = "application/vnd.docker.distribution.manifest.v1+prettyjws"
    35  	DockerManifestSchema2       MediaType = "application/vnd.docker.distribution.manifest.v2+json"
    36  	DockerManifestList          MediaType = "application/vnd.docker.distribution.manifest.list.v2+json"
    37  	DockerLayer                 MediaType = "application/vnd.docker.image.rootfs.diff.tar.gzip"
    38  	DockerConfigJSON            MediaType = "application/vnd.docker.container.image.v1+json"
    39  	DockerPluginConfig          MediaType = "application/vnd.docker.plugin.v1+json"
    40  	DockerForeignLayer          MediaType = "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"
    41  	DockerUncompressedLayer     MediaType = "application/vnd.docker.image.rootfs.diff.tar"
    42  
    43  	OCIVendorPrefix    = "vnd.oci"
    44  	DockerVendorPrefix = "vnd.docker"
    45  )
    46  
    47  // IsDistributable returns true if a layer is distributable, see:
    48  // https://github.com/opencontainers/image-spec/blob/master/layer.md#non-distributable-layers
    49  func (m MediaType) IsDistributable() bool {
    50  	switch m {
    51  	case DockerForeignLayer, OCIRestrictedLayer, OCIUncompressedRestrictedLayer:
    52  		return false
    53  	}
    54  	return true
    55  }
    56  
    57  // IsImage returns true if the mediaType represents an image manifest, as opposed to something else, like an index.
    58  func (m MediaType) IsImage() bool {
    59  	switch m {
    60  	case OCIManifestSchema1, DockerManifestSchema2:
    61  		return true
    62  	}
    63  	return false
    64  }
    65  
    66  // IsIndex returns true if the mediaType represents an index, as opposed to something else, like an image.
    67  func (m MediaType) IsIndex() bool {
    68  	switch m {
    69  	case OCIImageIndex, DockerManifestList:
    70  		return true
    71  	}
    72  	return false
    73  }
    74  
    75  // IsConfig returns true if the mediaType represents a config, as opposed to something else, like an image.
    76  func (m MediaType) IsConfig() bool {
    77  	switch m {
    78  	case OCIConfigJSON, DockerConfigJSON:
    79  		return true
    80  	}
    81  	return false
    82  }
    83  
    84  func (m MediaType) IsSchema1() bool {
    85  	switch m {
    86  	case DockerManifestSchema1, DockerManifestSchema1Signed:
    87  		return true
    88  	}
    89  	return false
    90  }
    91  
    92  func (m MediaType) IsLayer() bool {
    93  	switch m {
    94  	case DockerLayer, DockerUncompressedLayer, OCILayer, OCILayerZStd, OCIUncompressedLayer, DockerForeignLayer, OCIRestrictedLayer, OCIUncompressedRestrictedLayer:
    95  		return true
    96  	}
    97  	return false
    98  }
    99  

View as plain text