@@ -39,8 +39,8 @@ func NewStore(client corev1client.ConfigMapsGetter, limiter *rate.Limiter) *Stor
39
39
limiter = rate .NewLimiter (rate .Every (30 * time .Second ), 1 )
40
40
}
41
41
return & Store {
42
- client : client ,
43
- ns : "openshift-config-managed" ,
42
+ client : client ,
43
+ ns : "openshift-config-managed" ,
44
44
limiter : limiter ,
45
45
}
46
46
}
@@ -66,6 +66,18 @@ func (s *Store) mostRecentConfigMaps() []corev1.ConfigMap {
66
66
return s .last
67
67
}
68
68
69
+ // digestToKeyPrefix changes digest to use '-' in place of ':',
70
+ // {algo}-{hash} instead of {algo}:{hash}, because colons are not
71
+ // allowed in ConfigMap keys.
72
+ func digestToKeyPrefix (digest string ) (string , error ) {
73
+ parts := strings .SplitN (digest , ":" , 3 )
74
+ if len (parts ) != 2 || len (parts [0 ]) == 0 || len (parts [1 ]) == 0 {
75
+ return "" , fmt .Errorf ("the provided digest must be of the form ALGO:HASH" )
76
+ }
77
+ algo , hash := parts [0 ], parts [1 ]
78
+ return fmt .Sprintf ("%s-%s" , algo , hash ), nil
79
+ }
80
+
69
81
// DigestSignatures returns a list of signatures that match the request
70
82
// digest out of config maps labelled with ReleaseLabelConfigMap in the
71
83
// openshift-config-managed namespace.
@@ -85,12 +97,10 @@ func (s *Store) DigestSignatures(ctx context.Context, digest string) ([][]byte,
85
97
s .rememberMostRecentConfigMaps (configMaps .Items )
86
98
}
87
99
88
- parts := strings . SplitN (digest , ":" , 3 )
89
- if len ( parts ) != 2 || len ( parts [ 0 ]) == 0 || len ( parts [ 1 ]) == 0 {
90
- return nil , fmt . Errorf ( "the provided digest must be of the form ALGO:HASH" )
100
+ prefix , err := digestToKeyPrefix (digest )
101
+ if err != nil {
102
+ return nil , err
91
103
}
92
- algo , hash := parts [0 ], parts [1 ]
93
- prefix := fmt .Sprintf ("%s-%s" , algo , hash )
94
104
95
105
var signatures [][]byte
96
106
for _ , cm := range items {
@@ -117,8 +127,12 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
117
127
BinaryData : make (map [string ][]byte ),
118
128
}
119
129
for digest , signatures := range signaturesByDigest {
130
+ prefix , err := digestToKeyPrefix (digest )
131
+ if err != nil {
132
+ return err
133
+ }
120
134
for i := 0 ; i < len (signatures ); i ++ {
121
- cm .BinaryData [fmt .Sprintf ("%s-%d" , digest , i )] = signatures [i ]
135
+ cm .BinaryData [fmt .Sprintf ("%s-%d" , prefix , i )] = signatures [i ]
122
136
}
123
137
}
124
138
return retry .OnError (
0 commit comments