@@ -5,46 +5,47 @@ import (
5
5
"context"
6
6
"errors"
7
7
"fmt"
8
- "net/http"
9
8
"net/url"
10
9
"strings"
11
10
"sync"
12
11
13
- configv1 "github.com/openshift/api/config/v1"
14
12
configv1listers "github.com/openshift/client-go/config/listers/config/v1"
15
13
"github.com/openshift/library-go/pkg/verify/store"
16
14
"github.com/openshift/library-go/pkg/verify/store/parallel"
17
15
"github.com/openshift/library-go/pkg/verify/store/sigstore"
18
- utilerrors "k8s.io/apimachinery/pkg/util/errors"
19
- "k8s.io/klog/v2"
20
16
)
21
17
22
18
type Store struct {
23
19
// Name is the name of the ClusterVersion object that configures this store.
24
20
Name string
25
21
26
- // ClusterVersionLister allows the store to fetch the current ClusterVersion configuration.
27
- ClusterVersionLister configv1listers.ClusterVersionLister
22
+ // Lister allows the store to fetch the current ClusterVersion configuration.
23
+ Lister configv1listers.ClusterVersionLister
28
24
29
- // HTTPClient construct which respects the customstore CA certs and cluster proxy configuration
30
- HTTPClient func (string ) (* http.Client , error )
25
+ // HTTPClient is called once for each Signatures call to ensure
26
+ // requests are made with the currently-recommended parameters.
27
+ HTTPClient sigstore.HTTPClient
31
28
32
29
// lock allows the store to be locked while mutating or accessing internal state.
33
30
lock sync.Mutex
34
31
35
- // customStores tracks the most-recently retrieved ClusterVersion configuration.
36
- customStores []configv1. SignatureStore
32
+ // customURIs tracks the most-recently retrieved ClusterVersion configuration.
33
+ customURIs []* url. URL
37
34
}
38
35
39
36
// Signatures fetches signatures for the provided digest.
40
37
func (s * Store ) Signatures (ctx context.Context , name string , digest string , fn store.Callback ) error {
41
- customStores , err := s .refreshConfiguration ()
38
+ uris , err := s .refreshConfiguration (ctx )
42
39
if err != nil {
43
40
return err
44
- } else if customStores == nil {
41
+ }
42
+
43
+ if uris == nil {
45
44
return nil
46
- } else if len (customStores ) == 0 {
47
- return errors .New ("ClusterVersion spec.signatureStores is an empty array. Unset signatureStores entirely if you want to enable the default signature stores" )
45
+ }
46
+
47
+ if len (uris ) == 0 {
48
+ return errors .New ("ClusterVersion spec.signatureStores is an empty array. Unset signatureStores entirely if you want to to enable the default signature stores." )
48
49
}
49
50
50
51
allDone := false
@@ -57,66 +58,44 @@ func (s *Store) Signatures(ctx context.Context, name string, digest string, fn s
57
58
return done , err
58
59
}
59
60
60
- var errs []error
61
- stores := make ([]store.Store , 0 , len (customStores ))
62
- for _ , customStore := range customStores {
63
- uri , err := url .Parse (customStore .URL )
64
- if err != nil {
65
- errs = append (errs , fmt .Errorf ("failed to parse the ClusterVersion spec.signatureStores %w" , err ))
66
- continue
67
- }
68
- newHttpClient , err := s .HTTPClient (customStore .CA .Name )
69
- if err != nil {
70
- errs = append (errs , fmt .Errorf ("failed to process the ClusterVersion spec.signatureStores %w" , err ))
71
- continue
72
- }
73
-
61
+ stores := make ([]store.Store , 0 , len (uris ))
62
+ for i := range uris {
63
+ uri := * uris [i ]
74
64
stores = append (stores , & sigstore.Store {
75
- URI : uri ,
76
- HTTPClient : func () (* http.Client , error ) { return newHttpClient , nil }})
77
- }
78
-
79
- if len (stores ) == 0 {
80
- return utilerrors .NewAggregate (errs )
65
+ URI : & uri ,
66
+ HTTPClient : s .HTTPClient ,
67
+ })
81
68
}
82
69
store := & parallel.Store {Stores : stores }
83
- if err := store .Signatures (ctx , name , digest , wrapper ); allDone {
84
- if len (errs ) > 0 {
85
- klog .V (2 ).Infof ("%s" , utilerrors .NewAggregate (errs ))
86
- }
87
- return nil
88
- } else if err != nil {
89
- errs = append (errs , err )
90
- return utilerrors .NewAggregate (errs )
70
+ if err := store .Signatures (ctx , name , digest , wrapper ); err != nil || allDone {
71
+ return err
91
72
}
92
-
93
- errs = append (errs , errors .New ("ClusterVersion spec.signatureStores exhausted without finding a valid signature" ))
94
- return utilerrors .NewAggregate (errs )
73
+ return errors .New ("ClusterVersion spec.signatureStores exhausted without finding a valid signature." )
95
74
}
96
75
97
- // refreshConfiguration retrieves the latest configuration from the ClusterVersionLister
98
- // and updates the customStores with the URL and CA information from the retrieved configuration.
99
- // It returns the updated customStores slice and any error encountered during the retrieval process.
100
- func (s * Store ) refreshConfiguration () ([]configv1.SignatureStore , error ) {
101
-
102
- config , err := s .ClusterVersionLister .Get (s .Name )
76
+ func (s * Store ) refreshConfiguration (ctx context.Context ) ([]* url.URL , error ) {
77
+ config , err := s .Lister .Get (s .Name )
103
78
if err != nil {
104
79
return nil , err
105
80
}
106
81
107
- var customStores = make ([]configv1. SignatureStore , 0 , len ( config . Spec . SignatureStores ))
82
+ var uris [] * url. URL
108
83
if config .Spec .SignatureStores != nil {
84
+ uris = make ([]* url.URL , 0 , len (config .Spec .SignatureStores ))
109
85
for _ , store := range config .Spec .SignatureStores {
110
- url := store .URL
111
- caCert := store .CA
112
- customStores = append (customStores , configv1.SignatureStore {URL : url , CA : caCert })
86
+ uri , err := url .Parse (store .URL )
87
+ if err != nil {
88
+ return uris , err
89
+ }
90
+
91
+ uris = append (uris , uri )
113
92
}
114
93
}
115
94
116
95
s .lock .Lock ()
117
96
defer s .lock .Unlock ()
118
- s .customStores = customStores
119
- return customStores , nil
97
+ s .customURIs = uris
98
+ return uris , nil
120
99
}
121
100
122
101
// String returns a description of where this store finds
@@ -125,14 +104,14 @@ func (s *Store) String() string {
125
104
s .lock .Lock ()
126
105
defer s .lock .Unlock ()
127
106
128
- if s .customStores == nil {
129
- return "ClusterVersion signatureStores not set , falling back to default stores"
130
- } else if len (s .customStores ) == 0 {
107
+ if s .customURIs == nil {
108
+ return "ClusterVersion signatureStores unset , falling back to default stores"
109
+ } else if len (s .customURIs ) == 0 {
131
110
return "0 ClusterVersion signatureStores"
132
111
}
133
- customStores := make ([]string , 0 , len (s .customStores ))
134
- for _ , customStore := range s .customStores {
135
- customStores = append (customStores , customStore . URL )
112
+ uris := make ([]string , 0 , len (s .customURIs ))
113
+ for _ , uri := range s .customURIs {
114
+ uris = append (uris , uri . String () )
136
115
}
137
- return fmt .Sprintf ("ClusterVersion signatureStores: %s" , strings .Join (customStores , ", " ))
116
+ return fmt .Sprintf ("ClusterVersion signatureStores: %s" , strings .Join (uris , ", " ))
138
117
}
0 commit comments