Skip to content

Commit

Permalink
refactor: rename internal struct to avoid stuttering (#1370)
Browse files Browse the repository at this point in the history
Since this is an internal package it's not a breaking change to rename
this

Co-authored-by: Rex P <[email protected]>
  • Loading branch information
G-Rath and another-rex authored Nov 1, 2024
1 parent 11600e7 commit c20dd9f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
10 changes: 3 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import (

const osvScannerConfigName = "osv-scanner.toml"

// Ignore stuttering as that would be a breaking change
// TODO: V2 rename?
//
//nolint:revive
type ConfigManager struct {
type Manager struct {
// Override to replace all other configs
OverrideConfig *Config
// Config to use if no config file is found alongside manifests
Expand Down Expand Up @@ -140,7 +136,7 @@ func shouldIgnoreTimestamp(ignoreUntil time.Time) bool {

// Sets the override config by reading the config file at configPath.
// Will return an error if loading the config file fails
func (c *ConfigManager) UseOverride(configPath string) error {
func (c *Manager) UseOverride(configPath string) error {
config, configErr := tryLoadConfig(configPath)
if configErr != nil {
return configErr
Expand All @@ -151,7 +147,7 @@ func (c *ConfigManager) UseOverride(configPath string) error {
}

// Attempts to get the config
func (c *ConfigManager) Get(r reporter.Reporter, targetPath string) Config {
func (c *Manager) Get(r reporter.Reporter, targetPath string) Config {
if c.OverrideConfig != nil {
return *c.OverrideConfig
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func scanDebianDocker(r reporter.Reporter, dockerImageName string) ([]scannedPac
}

// Filters results according to config, preserving order. Returns total number of vulnerabilities removed.
func filterResults(r reporter.Reporter, results *models.VulnerabilityResults, configManager *config.ConfigManager, allPackages bool) int {
func filterResults(r reporter.Reporter, results *models.VulnerabilityResults, configManager *config.Manager, allPackages bool) int {
removedCount := 0
unimportantCount := 0
newResults := []models.PackageSource{} // Want 0 vulnerabilities to show in JSON as an empty list, not null.
Expand Down Expand Up @@ -869,7 +869,7 @@ func DoScan(actions ScannerActions, r reporter.Reporter) (models.VulnerabilityRe
return models.VulnerabilityResults{}, errors.New("databases can only be downloaded when running in offline mode")
}

configManager := config.ConfigManager{
configManager := config.Manager{
DefaultConfig: config.Config{},
ConfigMap: make(map[string]config.Config),
}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ func filterUnscannablePackages(packages []scannedPackage) []scannedPackage {
}

// filterIgnoredPackages removes ignore scanned packages according to config. Returns filtered scanned packages.
func filterIgnoredPackages(r reporter.Reporter, packages []scannedPackage, configManager *config.ConfigManager) []scannedPackage {
func filterIgnoredPackages(r reporter.Reporter, packages []scannedPackage, configManager *config.Manager) []scannedPackage {
out := make([]scannedPackage, 0, len(packages))
for _, p := range packages {
configToUse := configManager.Get(r, p.Source.Path)
Expand Down Expand Up @@ -1162,7 +1162,7 @@ func makeLicensesRequests(packages []scannedPackage) ([][]models.License, error)
}

// Overrides Go version using osv-scanner.toml
func overrideGoVersion(r reporter.Reporter, packages []scannedPackage, configManager *config.ConfigManager) {
func overrideGoVersion(r reporter.Reporter, packages []scannedPackage, configManager *config.Manager) {
for i, pkg := range packages {
if pkg.Name == "stdlib" && pkg.Ecosystem == "Go" {
configToUse := configManager.Get(r, pkg.Source.Path)
Expand Down
4 changes: 2 additions & 2 deletions pkg/osvscanner/osvscanner_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func Test_filterResults(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
r := &reporter.VoidReporter{}
// ConfigManager looks for osv-scanner.toml in the source path.
// configManager looks for osv-scanner.toml in the source path.
// Sources in the test input should point to files/folders in the text fixture folder for this to work correctly.
configManager := config.ConfigManager{
configManager := config.Manager{
DefaultConfig: config.Config{},
ConfigMap: make(map[string]config.Config),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osvscanner/vulnerability_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func buildVulnerabilityResults(
vulnsResp *osv.HydratedBatchedResponse,
licensesResp [][]models.License,
actions ScannerActions,
configManager *config.ConfigManager,
configManager *config.Manager,
) models.VulnerabilityResults {
results := models.VulnerabilityResults{
Results: []models.PackageSource{},
Expand Down
14 changes: 7 additions & 7 deletions pkg/osvscanner/vulnerability_result_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_assembleResult(t *testing.T) {
vulnsResp *osv.HydratedBatchedResponse
licensesResp [][]models.License
actions ScannerActions
config *config.ConfigManager
config *config.Manager
}
packages := []scannedPackage{
{
Expand Down Expand Up @@ -99,7 +99,7 @@ func Test_assembleResult(t *testing.T) {
},
CallAnalysisStates: callAnalysisStates,
},
config: &config.ConfigManager{},
config: &config.Manager{},
},
}, {
name: "group_vulnerabilities_with_all_packages_included",
Expand All @@ -115,7 +115,7 @@ func Test_assembleResult(t *testing.T) {
},
CallAnalysisStates: callAnalysisStates,
},
config: &config.ConfigManager{},
config: &config.Manager{},
},
}, {
name: "group_vulnerabilities_with_licenses",
Expand All @@ -132,7 +132,7 @@ func Test_assembleResult(t *testing.T) {
},
CallAnalysisStates: callAnalysisStates,
},
config: &config.ConfigManager{},
config: &config.Manager{},
},
}, {
name: "group_vulnerabilities_with_license_allowlist",
Expand All @@ -149,7 +149,7 @@ func Test_assembleResult(t *testing.T) {
CallAnalysisStates: callAnalysisStates,
},

config: &config.ConfigManager{},
config: &config.Manager{},
},
}, {
name: "group_vulnerabilities_with_license_allowlist_and_license_override",
Expand All @@ -165,7 +165,7 @@ func Test_assembleResult(t *testing.T) {
},
CallAnalysisStates: callAnalysisStates,
},
config: &config.ConfigManager{
config: &config.Manager{
OverrideConfig: &config.Config{
PackageOverrides: []config.PackageOverrideEntry{
{
Expand Down Expand Up @@ -193,7 +193,7 @@ func Test_assembleResult(t *testing.T) {
},
CallAnalysisStates: callAnalysisStates,
},
config: &config.ConfigManager{},
config: &config.Manager{},
},
}}
for _, tt := range tests {
Expand Down

0 comments on commit c20dd9f

Please sign in to comment.