@@ -59,11 +59,11 @@ func NewPipeAnalyzer(ctx context.Context, limitIncidents, limitCodeSnips, contex
5959 locations := []string {}
6060 for _ , config := range configs {
6161 if config .Address == "" || config .BinaryPath != "" {
62- return nil , fmt .Errorf ("You can only use an existing provider serving at a particular location" )
62+ return nil , fmt .Errorf ("you can only use an existing provider serving at a particular location" )
6363 }
6464 for _ , initConfig := range config .InitConfig {
6565 if initConfig .PipeName == "" {
66- return nil , fmt .Errorf ("The providers should only be using a pipe to communicate to the LSP" )
66+ return nil , fmt .Errorf ("the providers should only be using a pipe to communicate to the LSP" )
6767 }
6868 locations = append (locations , initConfig .Location )
6969 defaultBuiltinConfigs = append (defaultBuiltinConfigs , provider.InitConfig {
@@ -93,7 +93,7 @@ func NewPipeAnalyzer(ctx context.Context, limitIncidents, limitCodeSnips, contex
9393 Log : l .WithName ("parser" ),
9494 }
9595
96- discoveryRulesets , violationRulesets , neededProviders , err := parseRules (parser , rules , l , cancelFunc )
96+ discoveryRulesets , violationRulesets , neededProviders , providerConditions , err := parseRules (parser , rules , l , cancelFunc )
9797 if err != nil {
9898 return nil , err
9999 }
@@ -152,6 +152,15 @@ func NewPipeAnalyzer(ctx context.Context, limitIncidents, limitCodeSnips, contex
152152 }
153153 }
154154
155+ // Call Prepare() on all providers with the provider conditions
156+ for k , v := range providerConditions {
157+ if _ , ok := neededProviders [k ]; ok {
158+ if err := neededProviders [k ].Prepare (ctx , v ); err != nil {
159+ return nil , err
160+ }
161+ }
162+ }
163+
155164 ctx , cancelFunc = context .WithCancel (context .Background ())
156165 eng := engine .CreateRuleEngine (ctx ,
157166 10 ,
@@ -185,21 +194,27 @@ func NewPipeAnalyzer(ctx context.Context, limitIncidents, limitCodeSnips, contex
185194
186195}
187196
188- func parseRules (parser parser.RuleParser , rules string , l logr.Logger , cancelFunc func ()) ([]engine.RuleSet , []engine.RuleSet , map [string ]provider.InternalProviderClient , error ) {
197+ func parseRules (parser parser.RuleParser , rules string , l logr.Logger , cancelFunc func ()) ([]engine.RuleSet , []engine.RuleSet , map [string ]provider.InternalProviderClient , map [ string ][]provider. ConditionsByCap , error ) {
189198 discoveryRulesets := []engine.RuleSet {}
190199 violationRulesets := []engine.RuleSet {}
191200 neededProviders := map [string ]provider.InternalProviderClient {}
201+ providerConditions := map [string ][]provider.ConditionsByCap {}
192202 for _ , f := range strings .Split (rules , "," ) {
193- internRuleSets , newNeededProviders , err := parser .LoadRules (strings .TrimSpace (f ))
203+ internRuleSets , newNeededProviders , provConditions , err := parser .LoadRules (strings .TrimSpace (f ))
194204 if err != nil {
195205 l .Error (err , "unable to parse all the rules for ruleset" , "file" , f )
196206 cancelFunc ()
197- return nil , nil , nil , err
207+ return nil , nil , nil , nil , err
198208 }
199209 for k , v := range newNeededProviders {
200210 neededProviders [k ] = v
201211 }
202-
212+ for k , v := range provConditions {
213+ if _ , ok := providerConditions [k ]; ! ok {
214+ providerConditions [k ] = []provider.ConditionsByCap {}
215+ }
216+ providerConditions [k ] = append (providerConditions [k ], v ... )
217+ }
203218 for _ , interimRuleSet := range internRuleSets {
204219 runCacheResetRuleset := engine.RuleSet {
205220 Name : interimRuleSet .Name ,
@@ -237,5 +252,5 @@ func parseRules(parser parser.RuleParser, rules string, l logr.Logger, cancelFun
237252 }
238253 }
239254 }
240- return discoveryRulesets , violationRulesets , neededProviders , nil
255+ return discoveryRulesets , violationRulesets , neededProviders , providerConditions , nil
241256}
0 commit comments