...

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

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

     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 v1
    16  
    17  import (
    18  	"encoding/json"
    19  	"io"
    20  
    21  	"github.com/google/go-containerregistry/pkg/v1/types"
    22  )
    23  
    24  // Manifest represents the OCI image manifest in a structured way.
    25  type Manifest struct {
    26  	SchemaVersion int64             `json:"schemaVersion"`
    27  	MediaType     types.MediaType   `json:"mediaType,omitempty"`
    28  	Config        Descriptor        `json:"config"`
    29  	Layers        []Descriptor      `json:"layers"`
    30  	Annotations   map[string]string `json:"annotations,omitempty"`
    31  	Subject       *Descriptor       `json:"subject,omitempty"`
    32  }
    33  
    34  // IndexManifest represents an OCI image index in a structured way.
    35  type IndexManifest struct {
    36  	SchemaVersion int64             `json:"schemaVersion"`
    37  	MediaType     types.MediaType   `json:"mediaType,omitempty"`
    38  	Manifests     []Descriptor      `json:"manifests"`
    39  	Annotations   map[string]string `json:"annotations,omitempty"`
    40  	Subject       *Descriptor       `json:"subject,omitempty"`
    41  }
    42  
    43  // Descriptor holds a reference from the manifest to one of its constituent elements.
    44  type Descriptor struct {
    45  	MediaType    types.MediaType   `json:"mediaType"`
    46  	Size         int64             `json:"size"`
    47  	Digest       Hash              `json:"digest"`
    48  	Data         []byte            `json:"data,omitempty"`
    49  	URLs         []string          `json:"urls,omitempty"`
    50  	Annotations  map[string]string `json:"annotations,omitempty"`
    51  	Platform     *Platform         `json:"platform,omitempty"`
    52  	ArtifactType string            `json:"artifactType,omitempty"`
    53  }
    54  
    55  // ParseManifest parses the io.Reader's contents into a Manifest.
    56  func ParseManifest(r io.Reader) (*Manifest, error) {
    57  	m := Manifest{}
    58  	if err := json.NewDecoder(r).Decode(&m); err != nil {
    59  		return nil, err
    60  	}
    61  	return &m, nil
    62  }
    63  
    64  // ParseIndexManifest parses the io.Reader's contents into an IndexManifest.
    65  func ParseIndexManifest(r io.Reader) (*IndexManifest, error) {
    66  	im := IndexManifest{}
    67  	if err := json.NewDecoder(r).Decode(&im); err != nil {
    68  		return nil, err
    69  	}
    70  	return &im, nil
    71  }
    72  

View as plain text