Skip to content

Commit c20dd9f

Browse files
G-Rathanother-rex
andauthored
refactor: rename internal struct to avoid stuttering (google#1370)
Since this is an internal package it's not a breaking change to rename this Co-authored-by: Rex P <[email protected]>
1 parent 11600e7 commit c20dd9f

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

internal/config/config.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ import (
1616

1717
const osvScannerConfigName = "osv-scanner.toml"
1818

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

141137
// Sets the override config by reading the config file at configPath.
142138
// Will return an error if loading the config file fails
143-
func (c *ConfigManager) UseOverride(configPath string) error {
139+
func (c *Manager) UseOverride(configPath string) error {
144140
config, configErr := tryLoadConfig(configPath)
145141
if configErr != nil {
146142
return configErr
@@ -151,7 +147,7 @@ func (c *ConfigManager) UseOverride(configPath string) error {
151147
}
152148

153149
// Attempts to get the config
154-
func (c *ConfigManager) Get(r reporter.Reporter, targetPath string) Config {
150+
func (c *Manager) Get(r reporter.Reporter, targetPath string) Config {
155151
if c.OverrideConfig != nil {
156152
return *c.OverrideConfig
157153
}

pkg/osvscanner/osvscanner.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ func scanDebianDocker(r reporter.Reporter, dockerImageName string) ([]scannedPac
715715
}
716716

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

872-
configManager := config.ConfigManager{
872+
configManager := config.Manager{
873873
DefaultConfig: config.Config{},
874874
ConfigMap: make(map[string]config.Config),
875875
}
@@ -1033,7 +1033,7 @@ func filterUnscannablePackages(packages []scannedPackage) []scannedPackage {
10331033
}
10341034

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

11641164
// Overrides Go version using osv-scanner.toml
1165-
func overrideGoVersion(r reporter.Reporter, packages []scannedPackage, configManager *config.ConfigManager) {
1165+
func overrideGoVersion(r reporter.Reporter, packages []scannedPackage, configManager *config.Manager) {
11661166
for i, pkg := range packages {
11671167
if pkg.Name == "stdlib" && pkg.Ecosystem == "Go" {
11681168
configToUse := configManager.Get(r, pkg.Source.Path)

pkg/osvscanner/osvscanner_internal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func Test_filterResults(t *testing.T) {
4040
t.Run(tt.name, func(t *testing.T) {
4141
t.Parallel()
4242
r := &reporter.VoidReporter{}
43-
// ConfigManager looks for osv-scanner.toml in the source path.
43+
// configManager looks for osv-scanner.toml in the source path.
4444
// Sources in the test input should point to files/folders in the text fixture folder for this to work correctly.
45-
configManager := config.ConfigManager{
45+
configManager := config.Manager{
4646
DefaultConfig: config.Config{},
4747
ConfigMap: make(map[string]config.Config),
4848
}

pkg/osvscanner/vulnerability_result.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func buildVulnerabilityResults(
2424
vulnsResp *osv.HydratedBatchedResponse,
2525
licensesResp [][]models.License,
2626
actions ScannerActions,
27-
configManager *config.ConfigManager,
27+
configManager *config.Manager,
2828
) models.VulnerabilityResults {
2929
results := models.VulnerabilityResults{
3030
Results: []models.PackageSource{},

pkg/osvscanner/vulnerability_result_internal_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Test_assembleResult(t *testing.T) {
1919
vulnsResp *osv.HydratedBatchedResponse
2020
licensesResp [][]models.License
2121
actions ScannerActions
22-
config *config.ConfigManager
22+
config *config.Manager
2323
}
2424
packages := []scannedPackage{
2525
{
@@ -99,7 +99,7 @@ func Test_assembleResult(t *testing.T) {
9999
},
100100
CallAnalysisStates: callAnalysisStates,
101101
},
102-
config: &config.ConfigManager{},
102+
config: &config.Manager{},
103103
},
104104
}, {
105105
name: "group_vulnerabilities_with_all_packages_included",
@@ -115,7 +115,7 @@ func Test_assembleResult(t *testing.T) {
115115
},
116116
CallAnalysisStates: callAnalysisStates,
117117
},
118-
config: &config.ConfigManager{},
118+
config: &config.Manager{},
119119
},
120120
}, {
121121
name: "group_vulnerabilities_with_licenses",
@@ -132,7 +132,7 @@ func Test_assembleResult(t *testing.T) {
132132
},
133133
CallAnalysisStates: callAnalysisStates,
134134
},
135-
config: &config.ConfigManager{},
135+
config: &config.Manager{},
136136
},
137137
}, {
138138
name: "group_vulnerabilities_with_license_allowlist",
@@ -149,7 +149,7 @@ func Test_assembleResult(t *testing.T) {
149149
CallAnalysisStates: callAnalysisStates,
150150
},
151151

152-
config: &config.ConfigManager{},
152+
config: &config.Manager{},
153153
},
154154
}, {
155155
name: "group_vulnerabilities_with_license_allowlist_and_license_override",
@@ -165,7 +165,7 @@ func Test_assembleResult(t *testing.T) {
165165
},
166166
CallAnalysisStates: callAnalysisStates,
167167
},
168-
config: &config.ConfigManager{
168+
config: &config.Manager{
169169
OverrideConfig: &config.Config{
170170
PackageOverrides: []config.PackageOverrideEntry{
171171
{
@@ -193,7 +193,7 @@ func Test_assembleResult(t *testing.T) {
193193
},
194194
CallAnalysisStates: callAnalysisStates,
195195
},
196-
config: &config.ConfigManager{},
196+
config: &config.Manager{},
197197
},
198198
}}
199199
for _, tt := range tests {

0 commit comments

Comments
 (0)