...

Source file src/github.com/google/go-containerregistry/pkg/crane/get.go

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

     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 crane
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/google/go-containerregistry/pkg/name"
    21  	v1 "github.com/google/go-containerregistry/pkg/v1"
    22  	"github.com/google/go-containerregistry/pkg/v1/remote"
    23  )
    24  
    25  func getImage(r string, opt ...Option) (v1.Image, name.Reference, error) {
    26  	o := makeOptions(opt...)
    27  	ref, err := name.ParseReference(r, o.Name...)
    28  	if err != nil {
    29  		return nil, nil, fmt.Errorf("parsing reference %q: %w", r, err)
    30  	}
    31  	img, err := remote.Image(ref, o.Remote...)
    32  	if err != nil {
    33  		return nil, nil, fmt.Errorf("reading image %q: %w", ref, err)
    34  	}
    35  	return img, ref, nil
    36  }
    37  
    38  func getManifest(r string, opt ...Option) (*remote.Descriptor, error) {
    39  	o := makeOptions(opt...)
    40  	ref, err := name.ParseReference(r, o.Name...)
    41  	if err != nil {
    42  		return nil, fmt.Errorf("parsing reference %q: %w", r, err)
    43  	}
    44  	return remote.Get(ref, o.Remote...)
    45  }
    46  
    47  // Get calls remote.Get and returns an uninterpreted response.
    48  func Get(r string, opt ...Option) (*remote.Descriptor, error) {
    49  	return getManifest(r, opt...)
    50  }
    51  
    52  // Head performs a HEAD request for a manifest and returns a content descriptor
    53  // based on the registry's response.
    54  func Head(r string, opt ...Option) (*v1.Descriptor, error) {
    55  	o := makeOptions(opt...)
    56  	ref, err := name.ParseReference(r, o.Name...)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	return remote.Head(ref, o.Remote...)
    61  }
    62  

View as plain text