...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package static
17
18 import (
19 "encoding/json"
20
21 "github.com/google/go-containerregistry/pkg/v1/types"
22 "github.com/sigstore/cosign/v2/pkg/cosign/bundle"
23 ctypes "github.com/sigstore/cosign/v2/pkg/types"
24 )
25
26
27 type Option func(*options)
28
29 type options struct {
30 LayerMediaType types.MediaType
31 ConfigMediaType types.MediaType
32 Bundle *bundle.RekorBundle
33 RFC3161Timestamp *bundle.RFC3161Timestamp
34 Cert []byte
35 Chain []byte
36 Annotations map[string]string
37 RecordCreationTimestamp bool
38 }
39
40 func makeOptions(opts ...Option) (*options, error) {
41 o := &options{
42 LayerMediaType: ctypes.SimpleSigningMediaType,
43 ConfigMediaType: types.OCIConfigJSON,
44 Annotations: make(map[string]string),
45 }
46
47 for _, opt := range opts {
48 opt(o)
49 }
50
51 if o.Cert != nil {
52 o.Annotations[CertificateAnnotationKey] = string(o.Cert)
53 o.Annotations[ChainAnnotationKey] = string(o.Chain)
54 }
55
56 if o.Bundle != nil {
57 b, err := json.Marshal(o.Bundle)
58 if err != nil {
59 return nil, err
60 }
61 o.Annotations[BundleAnnotationKey] = string(b)
62 }
63
64 if o.RFC3161Timestamp != nil {
65 b, err := json.Marshal(o.RFC3161Timestamp)
66 if err != nil {
67 return nil, err
68 }
69 o.Annotations[RFC3161TimestampAnnotationKey] = string(b)
70 }
71 return o, nil
72 }
73
74
75 func WithLayerMediaType(mt types.MediaType) Option {
76 return func(o *options) {
77 o.LayerMediaType = mt
78 }
79 }
80
81
82 func WithConfigMediaType(mt types.MediaType) Option {
83 return func(o *options) {
84 o.ConfigMediaType = mt
85 }
86 }
87
88
89 func WithAnnotations(ann map[string]string) Option {
90 return func(o *options) {
91 o.Annotations = ann
92 }
93 }
94
95
96 func WithBundle(b *bundle.RekorBundle) Option {
97 return func(o *options) {
98 o.Bundle = b
99 }
100 }
101
102
103 func WithRFC3161Timestamp(b *bundle.RFC3161Timestamp) Option {
104 return func(o *options) {
105 o.RFC3161Timestamp = b
106 }
107 }
108
109
110 func WithCertChain(cert, chain []byte) Option {
111 return func(o *options) {
112 o.Cert = cert
113 o.Chain = chain
114 }
115 }
116
117
118 func WithRecordCreationTimestamp(rct bool) Option {
119 return func(o *options) {
120 o.RecordCreationTimestamp = rct
121 }
122 }
123
View as plain text