Skip to content

Commit

Permalink
🐛 fix default builtin configs
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Jul 23, 2024
1 parent 1e192fb commit 2c6f6fb
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions cmd/analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -127,10 +128,41 @@ func AnalysisCmd() *cobra.Command {
os.Exit(1)
}

// we add builtin configs by default for all locations
defaultBuiltinConfigs := []provider.InitConfig{}
seenBuiltinConfigs := map[string]bool{}
finalConfigs := []provider.Config{}
for _, config := range configs {
if config.Name != "builtin" {
finalConfigs = append(finalConfigs, config)
}
for _, initConf := range config.InitConfig {
if _, ok := seenBuiltinConfigs[initConf.Location]; !ok {
if initConf.Location != "" {
if stat, err := os.Stat(initConf.Location); err == nil && stat.IsDir() {
builtinLocation, err := filepath.Abs(initConf.Location)
if err != nil {
builtinLocation = initConf.Location
}
seenBuiltinConfigs[builtinLocation] = true
builtinConf := provider.InitConfig{Location: builtinLocation}
if config.Name == "builtin" {
builtinConf.ProviderSpecificConfig = initConf.ProviderSpecificConfig
}
defaultBuiltinConfigs = append(defaultBuiltinConfigs, builtinConf)
}
}
}
}
}
finalConfigs = append(finalConfigs, provider.Config{
Name: "builtin",
InitConfig: defaultBuiltinConfigs,
})

providers := map[string]provider.InternalProviderClient{}
builtinConfigs := []provider.InitConfig{}
providerLocations := []string{}
for _, config := range configs {
for _, config := range finalConfigs {
config.ContextLines = contextLines
for _, ind := range config.InitConfig {
providerLocations = append(providerLocations, ind.Location)
Expand All @@ -141,9 +173,6 @@ func AnalysisCmd() *cobra.Command {
for _, i := range config.InitConfig {
i.AnalysisMode = provider.AnalysisMode(analysisMode)
inits = append(inits, i)
builtinConfigs = append(builtinConfigs, provider.InitConfig{
Location: i.Location,
})
}
config.InitConfig = inits
}
Expand Down Expand Up @@ -208,6 +237,7 @@ func AnalysisCmd() *cobra.Command {
}
}
// Now that we have all the providers, we need to start them.
additionalBuiltinConfigs := []provider.InitConfig{}
for name, provider := range needProviders {
switch name {
// other providers can return additional configs for the builtin provider
Expand All @@ -223,14 +253,14 @@ func AnalysisCmd() *cobra.Command {
os.Exit(1)
}
if additionalBuiltinConfs != nil {
builtinConfigs = append(builtinConfigs, additionalBuiltinConfs...)
additionalBuiltinConfigs = append(additionalBuiltinConfigs, additionalBuiltinConfs...)
}
initSpan.End()
}
}

if builtinClient, ok := needProviders["builtin"]; ok {
if _, err = builtinClient.ProviderInit(ctx, builtinConfigs); err != nil {
if _, err = builtinClient.ProviderInit(ctx, additionalBuiltinConfigs); err != nil {
errLog.Error(err, "unable to init builtin provider")
os.Exit(1)
}
Expand Down

0 comments on commit 2c6f6fb

Please sign in to comment.