Skip to content

Commit

Permalink
Enhance v6 search command (#2303)
Browse files Browse the repository at this point in the history
* add v6 search command

Signed-off-by: Alex Goodman <[email protected]>

* add json schema generation

Signed-off-by: Alex Goodman <[email protected]>

* add schema drift checks

Signed-off-by: Alex Goodman <[email protected]>

* add initial db search schemas

Signed-off-by: Alex Goodman <[email protected]>

* add readmes for schemas

Signed-off-by: Alex Goodman <[email protected]>

* add field comments to json schema

Signed-off-by: Alex Goodman <[email protected]>

* fix cpe and ecosystem filtering

Signed-off-by: Alex Goodman <[email protected]>

* mimic v5 help

Signed-off-by: Alex Goodman <[email protected]>

* fix cli test

Signed-off-by: Alex Goodman <[email protected]>

* keep config shape clean

Signed-off-by: Alex Goodman <[email protected]>

* add tests

Signed-off-by: Alex Goodman <[email protected]>

* address review comments

Signed-off-by: Alex Goodman <[email protected]>

* fix v5 namespace rhel and version cases

Signed-off-by: Alex Goodman <[email protected]>

* address pkg spec comments

Signed-off-by: Alex Goodman <[email protected]>

* fix limit handling

Signed-off-by: Alex Goodman <[email protected]>

* add any pkg helper

Signed-off-by: Alex Goodman <[email protected]>

* use loop var

Signed-off-by: Alex Goodman <[email protected]>

* add tests and fix deprecated linter configuration

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Jan 15, 2025
1 parent ac48e0d commit a22349b
Show file tree
Hide file tree
Showing 46 changed files with 4,846 additions and 93 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/json-schema-drift-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -u

if [ "$(git status --porcelain | wc -l)" -ne "0" ]; then
echo " 🔴 there are uncommitted changes, please commit them before running this check"
exit 1
fi

if ! make generate-json-schema; then
echo "Generating json schema failed"
exit 1
fi

if [ "$(git status --porcelain | wc -l)" -ne "0" ]; then
echo " 🔴 there are uncommitted changes, please commit them before running this check"
exit 1
fi
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
issues:
max-same-issues: 25
uniq-by-line: false

# TODO: enable this when we have coverage on docstring comments
# # The list of ids of default excludes to include or disable.
Expand Down Expand Up @@ -49,8 +50,6 @@ linters-settings:
# If lower than 0, disable the check.
# Default: 40
statements: 50
output:
uniq-by-line: false
run:
timeout: 10m

Expand Down
16 changes: 15 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tasks:
- task: check-go-mod-tidy
- task: check-licenses
- task: lint
- task: check-json-schema-drift
- task: validate-cyclonedx-schema
# TODO: while developing v6, we need to disable this check (since v5 and v6 are imported in the same codebase)
# - task: validate-grype-db-schema
Expand Down Expand Up @@ -171,6 +172,11 @@ tasks:
- cmd: .github/scripts/go-mod-tidy-check.sh && echo "go.mod and go.sum are tidy!"
silent: true

check-json-schema-drift:
desc: Ensure there is no drift between the JSON schema and the code
cmds:
- .github/scripts/json-schema-drift-check.sh

validate-cyclonedx-schema:
desc: Run integration tests
cmds:
Expand Down Expand Up @@ -313,9 +319,17 @@ tasks:
## Code and data generation targets #################################

generate:
desc: Run data generation tasks
desc: Run code and data generation tasks
cmds:
- task: generate-json-schema

generate-json-schema:
desc: Generate a new JSON schema
cmds:
# re-generate package metadata
- "cd grype/internal && go generate"
# generate the JSON schema for the CLI output
- "cd cmd/grype/cli/commands/internal/jsonschema && go run ."


## Build-related targets #################################
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func DBCheck(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "check",
Short: "check to see if there is a database update available",
Short: "Check to see if there is a database update available",
PreRunE: func(cmd *cobra.Command, args []string) error {
// DB commands should not opt into the low-pass check filter
opts.DB.MaxUpdateCheckFrequency = 0
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func DBDelete(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "delete",
Short: "delete the vulnerability database",
Short: "Delete the vulnerability database",
Args: cobra.ExactArgs(0),
PreRunE: disableUI(app),
RunE: func(_ *cobra.Command, _ []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func DBDiff(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "diff [flags] base_db_url target_db_url",
Short: "diff two DBs and display the result",
Short: "Diff two DBs and display the result",
Args: cobra.MaximumNArgs(2),
RunE: func(_ *cobra.Command, args []string) (err error) {
var base, target string
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func DBImport(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "import FILE",
Short: "import a vulnerability database archive",
Short: "Import a vulnerability database archive",
Long: fmt.Sprintf("import a vulnerability database archive from a local FILE.\nDB archives can be obtained from %q.", internal.DBUpdateURL),
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func DBList(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "list",
Short: "list all DBs available according to the listing URL",
Short: "List all DBs available according to the listing URL",
PreRunE: disableUI(app),
Args: cobra.ExactArgs(0),
RunE: func(_ *cobra.Command, _ []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func DBProviders(app clio.Application) *cobra.Command {

cmd := &cobra.Command{
Use: "providers",
Short: "list vulnerability database providers",
Short: "List vulnerability providers that are in the database",
Args: cobra.ExactArgs(0),
RunE: func(_ *cobra.Command, _ []string) error {
return runDBProviders(opts, app)
Expand Down
Loading

0 comments on commit a22349b

Please sign in to comment.