@@ -162,7 +162,7 @@ func (r *rules) newProgram(ast *cel.Ast) cel.Program {
162162 return prg
163163}
164164
165- func processVendorRuleset (filename string , verbose bool ) error {
165+ func processVendorRuleset (filename string , r * rules , verbose bool ) error {
166166 verboseLog (verbose , "Reading vendor ruleset file: %s" , filename )
167167 content , err := os .ReadFile (filename )
168168
@@ -175,10 +175,21 @@ func processVendorRuleset(filename string, verbose bool) error {
175175 // Unmarshal the text-formatted content into the struct.
176176 parseErr := prototext .Unmarshal (content , & rulesetCollection )
177177
178- if parseErr != nil {
178+ if parseErr != nil {
179179 fmt .Fprintf (os .Stderr , "failed to parse vendor ruleset file as VendorRulesetCollection: %v\n " , parseErr )
180180 return parseErr
181181 }
182+
183+ for _ , ruleset := range rulesetCollection .GetRuleSets () {
184+ for _ , rule := range ruleset .GetRules () {
185+ if rule .GetCelExpression () != "" {
186+ _ , ok := r .newAST (rule .GetCelExpression ())
187+ if ! ok {
188+ return fmt .Errorf ("failed to compile cel_expression for rule %s in ruleset %s" , rule .GetId (), ruleset .GetName ())
189+ }
190+ }
191+ }
192+ }
182193
183194 fmt .Printf ("Successfully validated vendor ruleset. \n " )
184195 return nil
@@ -203,7 +214,7 @@ func main() {
203214 r := newRules (opts .version )
204215
205216 if opts .textproto != "" {
206- if err := processVendorRuleset (opts .textproto , opts .verbose ); err != nil {
217+ if err := processVendorRuleset (opts .textproto , r , opts .verbose ); err != nil {
207218 fmt .Fprintf (os .Stderr , "failed to process vendor ruleset: %v\n " , err )
208219 os .Exit (1 )
209220 }
0 commit comments