Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sensible defaults to the OSV evaluator to allow running without any configuration #3053

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions internal/engine/eval/vulncheck/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package vulncheck

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -53,9 +52,44 @@ type config struct {
EcosystemConfig []ecosystemConfig `json:"ecosystem_config" mapstructure:"ecosystem_config" validate:"required"`
}

func defaultConfig() *config {
return &config{
Action: pr_actions.ActionReviewPr,
EcosystemConfig: []ecosystemConfig{
{
Name: "npm",
DbType: vulnDbTypeOsv,
DbEndpoint: "https://api.osv.dev/v1/query",
PackageRepository: packageRepository{
Url: "https://registry.npmjs.org",
},
},
{
Name: "pypi",
DbType: vulnDbTypeOsv,
DbEndpoint: "https://api.osv.dev/v1/query",
PackageRepository: packageRepository{
Url: "https://pypi.org/pypi",
},
},
{
Name: "go",
DbType: vulnDbTypeOsv,
DbEndpoint: "https://api.osv.dev/v1/query",
PackageRepository: packageRepository{
Url: "https://proxy.golang.org",
},
SumRepository: packageRepository{
Url: "https://sum.golang.org",
},
},
},
}
}

func parseConfig(ruleCfg map[string]any) (*config, error) {
if ruleCfg == nil {
return nil, errors.New("config was missing")
if len(ruleCfg) == 0 {
return defaultConfig(), nil
}

var conf config
Expand Down