...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
54 func (i *image) Signatures() (oci.Signatures, error) {
55 return signatures(i, i.opt)
56 }
57
58
59 func (i *image) Attestations() (oci.Signatures, error) {
60 return attestations(i, i.opt)
61 }
62
63
64 func (i *image) Attachment(name string) (oci.File, error) {
65 return attachment(i, name, i.opt)
66 }
67
View as plain text