@@ -52,7 +52,7 @@ type GitClient interface {
5252 GetRepoHeadBranchName (ctx context.Context , repoPath string ) (string , error )
5353}
5454
55- func NewAnalyzer (scmClient ScmClient , gitClient GitClient , formatter Formatter , config * models.Config ) * Analyzer {
55+ func NewAnalyzer (scmClient ScmClient , gitClient GitClient , formatter Formatter , config * models.Config , opaClient * opa. Opa ) * Analyzer {
5656 if config == nil {
5757 config = & models.Config {}
5858 }
@@ -61,6 +61,7 @@ func NewAnalyzer(scmClient ScmClient, gitClient GitClient, formatter Formatter,
6161 GitClient : gitClient ,
6262 Formatter : formatter ,
6363 Config : config ,
64+ Opa : opaClient ,
6465 }
6566}
6667
@@ -69,6 +70,7 @@ type Analyzer struct {
6970 GitClient GitClient
7071 Formatter Formatter
7172 Config * models.Config
73+ Opa * opa.Opa
7274}
7375
7476func (a * Analyzer ) AnalyzeOrg (ctx context.Context , org string , numberOfGoroutines * int ) error {
@@ -84,12 +86,8 @@ func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutine
8486 log .Debug ().Msgf ("Fetching list of repositories for organization: %s on %s" , org , provider )
8587 orgReposBatches := a .ScmClient .GetOrgRepos (ctx , org )
8688
87- opaClient , err := a .newOpa (ctx )
88- if err != nil {
89- return err
90- }
9189 pkgsupplyClient := pkgsupply .NewStaticClient ()
92- inventory := scanner .NewInventory (opaClient , pkgsupplyClient , provider , providerVersion )
90+ inventory := scanner .NewInventory (a . Opa , pkgsupplyClient , provider , providerVersion )
9391
9492 log .Debug ().Msgf ("Starting repository analysis for organization: %s on %s" , org , provider )
9593 bar := progressbar .NewOptions (
@@ -185,13 +183,8 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
185183
186184 log .Debug ().Msgf ("Provider: %s, Version: %s" , provider , providerVersion )
187185
188- opaClient , err := a .newOpa (ctx )
189- if err != nil {
190- return err
191- }
192186 pkgsupplyClient := pkgsupply .NewStaticClient ()
193-
194- inventory := scanner .NewInventory (opaClient , pkgsupplyClient , provider , providerVersion )
187+ inventory := scanner .NewInventory (a .Opa , pkgsupplyClient , provider , providerVersion )
195188
196189 log .Debug ().Msgf ("Starting repository analysis for: %s/%s on %s" , org , repoName , provider )
197190 bar := progressbar .NewOptions (
@@ -240,13 +233,8 @@ func (a *Analyzer) AnalyzeLocalRepo(ctx context.Context, repoPath string) error
240233
241234 log .Debug ().Msgf ("Provider: %s, Version: %s" , provider , providerVersion )
242235
243- opaClient , err := a .newOpa (ctx )
244- if err != nil {
245- return err
246- }
247236 pkgsupplyClient := pkgsupply .NewStaticClient ()
248-
249- inventory := scanner .NewInventory (opaClient , pkgsupplyClient , provider , providerVersion )
237+ inventory := scanner .NewInventory (a .Opa , pkgsupplyClient , provider , providerVersion )
250238
251239 log .Debug ().Msgf ("Starting repository analysis for: %s/%s on %s" , org , repoName , provider )
252240 bar := progressbar .NewOptions (
@@ -337,14 +325,3 @@ func (a *Analyzer) cloneRepoToTemp(ctx context.Context, gitURL string, token str
337325 }
338326 return tempDir , nil
339327}
340-
341- func (a * Analyzer ) newOpa (ctx context.Context ) (* opa.Opa , error ) {
342- opaClient , err := opa .NewOpa ()
343- if err != nil {
344- log .Error ().Err (err ).Msg ("Failed to create OPA client" )
345- return nil , err
346- }
347- _ = opaClient .WithConfig (ctx , a .Config )
348-
349- return opaClient , nil
350- }
0 commit comments