Skip to content

Commit 861b1af

Browse files
authored
feat: support having the detector use the api by default based on an environment variable (#346)
1 parent 5c4bb1c commit 861b1af

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ however it currently can produce false negatives for some ecosystems.
134134
You cannot use the API in `--offline` mode, but you can use both the offline
135135
databases and the API together; the detector will remove any duplicate results.
136136

137+
> [!NOTE]
138+
>
139+
> If the `OSV_DETECTOR_PREFER_API` environment variable is `true`, then the
140+
> detector will default to using the API rather than the dbs, as if it has been
141+
> called with `--use-api --use-dbs=false`.
142+
137143
Once all the lockfiles have been pared, the detector will then determine all the
138144
databases to load - if `--use-dbs` is `true` (which it is by default) then this
139145
will include ecosystem specific databases based on the parsed packages.

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var (
2323
version = "dev"
2424
commit = "none"
2525
date = "unknown"
26+
27+
// controls if the api should be preferred by default, rather than the dbs
28+
preferAPI = os.Getenv("OSV_DETECTOR_PREFER_API") == "true"
2629
)
2730

2831
func makeAPIDBConfig() database.Config {
@@ -505,8 +508,8 @@ func run(args []string, stdout, stderr io.Writer) int {
505508
listEcosystems := cli.Bool("list-ecosystems", false, "List all of the known ecosystems that are supported by the detector")
506509
listPackages := cli.Bool("list-packages", false, "List the packages that are parsed from the input files")
507510
outputAsJSON := cli.Bool("json", false, "Output the results in JSON format")
508-
useDatabases := cli.Bool("use-dbs", true, "Use the databases from osv.dev to check for known vulnerabilities")
509-
useAPI := cli.Bool("use-api", false, "Use the osv.dev API to check for known vulnerabilities")
511+
useDatabases := cli.Bool("use-dbs", !preferAPI, "Use the databases from osv.dev to check for known vulnerabilities")
512+
useAPI := cli.Bool("use-api", preferAPI, "Use the osv.dev API to check for known vulnerabilities")
510513
batchSize := cli.Int("batch-size", 1000, "The number of packages to include in each batch when using the api database")
511514

512515
cli.Var(&globalIgnores, "ignore", `ID of an OSV to ignore when determining exit codes.

0 commit comments

Comments
 (0)