Skip to content

Commit

Permalink
keep config shape clean
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Dec 23, 2024
1 parent b28e3bb commit 0802095
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
7 changes: 6 additions & 1 deletion cmd/grype/cli/commands/db_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ Global Flags:
DBSearchVulnerabilities(app),
)

return app.SetupCommand(cmd, opts)
// prevent from being shown in the grype config
type configWrapper struct {
Opts *dbSearchMatchOptions `json:"-" yaml:"-" mapstructure:"-"`
}

return app.SetupCommand(cmd, &configWrapper{opts})
}

func runDBSearchMatches(opts dbSearchMatchOptions) error {
Expand Down
11 changes: 9 additions & 2 deletions cmd/grype/cli/commands/db_search_vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func DBSearchVulnerabilities(app clio.Application) *cobra.Command {
DBOptions: *dbOptionsDefault(app.ID()),
}

return app.SetupCommand(&cobra.Command{
cmd := &cobra.Command{
Use: "vuln ID...",
Aliases: []string{"vulnerability", "vulnerabilities", "vulns"},
Short: "Search for vulnerabilities within the DB (supports DB schema v6+ only)",
Expand All @@ -56,7 +56,14 @@ func DBSearchVulnerabilities(app clio.Application) *cobra.Command {
}
return runDBSearchVulnerabilities(*opts)
},
}, opts)
}

// prevent from being shown in the grype config
type configWrapper struct {
Opts *dbSearchVulnerabilityOptions `json:"-" yaml:"-" mapstructure:"-"`
}

return app.SetupCommand(cmd, &configWrapper{opts})
}

func runDBSearchVulnerabilities(opts dbSearchVulnerabilityOptions) error {
Expand Down
3 changes: 1 addition & 2 deletions cmd/grype/cli/options/database_search_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func parseOSString(osValue string) (*v6.OSSpecifier, error) {
}

// is codename / label
// TODO: pick one! not both
return &v6.OSSpecifier{Name: name, Codename: version, LabelVersion: version}, nil
return &v6.OSSpecifier{Name: name, LabelVersion: version}, nil

default:
return nil, fmt.Errorf("invalid distro name@version: %q", osValue)
Expand Down
4 changes: 2 additions & 2 deletions grype/db/v6/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ type OperatingSystem struct {
ID ID `gorm:"column:id;primaryKey"`

// Name is the operating system family name (e.g. "debian")
Name string `gorm:"column:name;index:os_idx,unique;index"`
ReleaseID string `gorm:"column:release_id;index:os_idx,unique;index"`
Name string `gorm:"column:name;index:os_idx,unique;index"`
ReleaseID string `gorm:"column:release_id;index:os_idx,unique;index"`

// MajorVersion is the major version of a specific release (e.g. "10" for debian 10)
MajorVersion string `gorm:"column:major_version;index:os_idx,unique;index"`
Expand Down
2 changes: 1 addition & 1 deletion test/cli/db_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestDBProviders(t *testing.T) {
name: "db providers command help",
args: []string{"db", "providers", "-h"},
assertions: []traitAssertion{
assertInOutput("List vulnerability database providers"),
assertInOutput("List vulnerability providers that are in the database"),
assertNoStderr,
},
},
Expand Down

0 comments on commit 0802095

Please sign in to comment.