...

Source file src/github.com/sigstore/cosign/v2/pkg/oci/remote/image.go

Documentation: github.com/sigstore/cosign/v2/pkg/oci/remote

     1  //
     2  // Copyright 2021 The Sigstore Authors.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package remote
    17  
    18  import (
    19  	"errors"
    20  	"net/http"
    21  
    22  	"github.com/google/go-containerregistry/pkg/name"
    23  	v1 "github.com/google/go-containerregistry/pkg/v1"
    24  	"github.com/google/go-containerregistry/pkg/v1/remote/transport"
    25  	"github.com/sigstore/cosign/v2/pkg/oci"
    26  )
    27  
    28  var ErrImageNotFound = errors.New("image not found in registry")
    29  
    30  // SignedImage provides access to a remote image reference, and its signatures.
    31  func SignedImage(ref name.Reference, options ...Option) (oci.SignedImage, error) {
    32  	o := makeOptions(ref.Context(), options...)
    33  	ri, err := remoteImage(ref, o.ROpt...)
    34  	var te *transport.Error
    35  	if errors.As(err, &te) && te.StatusCode == http.StatusNotFound {
    36  		return nil, ErrImageNotFound
    37  	} else if err != nil {
    38  		return nil, err
    39  	}
    40  	return &image{
    41  		Image: ri,
    42  		opt:   o,
    43  	}, nil
    44  }
    45  
    46  type image struct {
    47  	v1.Image
    48  	opt *options
    49  }
    50  
    51  var _ oci.SignedImage = (*image)(nil)
    52  
    53  // Signatures implements oci.SignedImage
    54  func (i *image) Signatures() (oci.Signatures, error) {
    55  	return signatures(i, i.opt)
    56  }
    57  
    58  // Attestations implements oci.SignedImage
    59  func (i *image) Attestations() (oci.Signatures, error) {
    60  	return attestations(i, i.opt)
    61  }
    62  
    63  // Attestations implements oci.SignedImage
    64  func (i *image) Attachment(name string) (oci.File, error) {
    65  	return attachment(i, name, i.opt)
    66  }
    67  

View as plain text