@@ -230,63 +230,63 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
230
230
RekorURL : data .rekorURL ,
231
231
}
232
232
233
- // We're not currently using the policyCache returned from PreProcessPolicy, but we could
234
- // use it to cache the policy for future use.
235
- if p , _ , err := policy .PreProcessPolicy (ctx , policyOptions ); err != nil {
233
+ p , err := policy .NewPolicy (ctx , policyOptions )
234
+ if err != nil {
236
235
allErrors = errors .Join (allErrors , err )
237
- } else {
238
- // inject extra variables into rule data per source
239
- if len (data .extraRuleData ) > 0 {
240
- policySpec := p .Spec ()
241
- sources := policySpec .Sources
242
- for i := range sources {
243
- src := sources [i ]
244
- var rule_data_raw []byte
245
- unmarshaled := make (map [string ]interface {})
246
-
247
- if src .RuleData != nil {
248
- rule_data_raw , err = src .RuleData .MarshalJSON ()
249
- if err != nil {
250
- log .Errorf ("Unable to parse ruledata to raw data" )
251
- }
252
- err = json .Unmarshal (rule_data_raw , & unmarshaled )
253
- if err != nil {
254
- log .Errorf ("Unable to parse ruledata into standard JSON object" )
255
- }
256
- } else {
257
- sources [i ].RuleData = new (extv1.JSON )
258
- }
236
+ return
237
+ }
259
238
260
- for j := range data .extraRuleData {
261
- parts := strings .SplitN (data .extraRuleData [j ], "=" , 2 )
262
- if len (parts ) < 2 {
263
- log .Errorf ("Incorrect syntax for --extra-rule-data" )
264
- }
265
- extraRuleDataPolicyConfig , err := validate_utils .GetPolicyConfig (ctx , parts [1 ])
266
- if err != nil {
267
- log .Errorf ("Unable to load data from extraRuleData: %s" , err .Error ())
268
- }
269
- unmarshaled [parts [0 ]] = extraRuleDataPolicyConfig
239
+ // inject extra variables into rule data per source
240
+ if len (data .extraRuleData ) > 0 {
241
+ policySpec := p .Spec ()
242
+ sources := policySpec .Sources
243
+ for i := range sources {
244
+ src := sources [i ]
245
+ var rule_data_raw []byte
246
+ unmarshaled := make (map [string ]interface {})
247
+
248
+ if src .RuleData != nil {
249
+ rule_data_raw , err = src .RuleData .MarshalJSON ()
250
+ if err != nil {
251
+ log .Errorf ("Unable to parse ruledata to raw data" )
270
252
}
271
- rule_data_raw , err = json .Marshal ( unmarshaled )
253
+ err = json .Unmarshal ( rule_data_raw , & unmarshaled )
272
254
if err != nil {
273
- log .Errorf ("Unable to parse updated ruledata: %s" , err . Error () )
255
+ log .Errorf ("Unable to parse ruledata into standard JSON object" )
274
256
}
257
+ } else {
258
+ sources [i ].RuleData = new (extv1.JSON )
259
+ }
275
260
276
- if rule_data_raw == nil {
277
- log .Errorf ("Invalid rule data JSON" )
261
+ for j := range data .extraRuleData {
262
+ parts := strings .SplitN (data .extraRuleData [j ], "=" , 2 )
263
+ if len (parts ) < 2 {
264
+ log .Errorf ("Incorrect syntax for --extra-rule-data" )
278
265
}
279
-
280
- err = sources [i ].RuleData .UnmarshalJSON (rule_data_raw )
266
+ extraRuleDataPolicyConfig , err := validate_utils .GetPolicyConfig (ctx , parts [1 ])
281
267
if err != nil {
282
- log .Errorf ("Unable to marshal updated JSON : %s" , err .Error ())
268
+ log .Errorf ("Unable to load data from extraRuleData : %s" , err .Error ())
283
269
}
270
+ unmarshaled [parts [0 ]] = extraRuleDataPolicyConfig
271
+ }
272
+ rule_data_raw , err = json .Marshal (unmarshaled )
273
+ if err != nil {
274
+ log .Errorf ("Unable to parse updated ruledata: %s" , err .Error ())
275
+ }
276
+
277
+ if rule_data_raw == nil {
278
+ log .Errorf ("Invalid rule data JSON" )
279
+ }
280
+
281
+ err = sources [i ].RuleData .UnmarshalJSON (rule_data_raw )
282
+ if err != nil {
283
+ log .Errorf ("Unable to marshal updated JSON: %s" , err .Error ())
284
284
}
285
- policySpec .Sources = sources
286
- p = p .WithSpec (policySpec )
287
285
}
288
- data .policy = p
286
+ policySpec .Sources = sources
287
+ p = p .WithSpec (policySpec )
289
288
}
289
+ data .policy = p
290
290
291
291
return
292
292
},
0 commit comments