Skip to content

Commit

Permalink
Make OSV api public (google#167)
Browse files Browse the repository at this point in the history
* Make OSV api public

* Add osv file

* Add commend on public function

* Removed v1, made maxQueriesPerRequest private

* Fix bug

---------

Co-authored-by: Oliver Chang <[email protected]>
  • Loading branch information
2 people authored and julieqiu committed May 2, 2023
1 parent ab526b3 commit 8f4e7cc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/output/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"strings"

"github.com/google/osv-scanner/internal/osv"
"github.com/google/osv-scanner/pkg/models"
"github.com/google/osv-scanner/pkg/osv"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
Expand Down
7 changes: 4 additions & 3 deletions internal/osv/osv.go → pkg/osv/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const (
GetEndpoint = "https://api.osv.dev/v1/vulns"
// BaseVulnerabilityURL is the base URL for detailed vulnerability views.
BaseVulnerabilityURL = "https://osv.dev/"
// MaxQueriesPerRequest splits up querybatch into multiple requests if
// maxQueriesPerRequest splits up querybatch into multiple requests if
// number of queries exceed this number
MaxQueriesPerRequest = 1000
maxQueriesPerRequest = 1000
)

// Package represents a package identifier for OSV.
Expand Down Expand Up @@ -121,9 +121,10 @@ func checkResponseError(resp *http.Response) error {
return fmt.Errorf("server response error: %s", string(respBuf))
}

// MakeRequest sends a batched query to osv.dev
func MakeRequest(request BatchedQuery) (*BatchedResponse, error) {
// API has a limit of 1000 bulk query per request
queryChunks := chunkBy(request.Queries, MaxQueriesPerRequest)
queryChunks := chunkBy(request.Queries, maxQueriesPerRequest)
var totalOsvResp BatchedResponse
for _, queries := range queryChunks {
requestBytes, err := json.Marshal(BatchedQuery{Queries: queries})
Expand Down
2 changes: 1 addition & 1 deletion pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"path/filepath"
"strings"

"github.com/google/osv-scanner/internal/osv"
"github.com/google/osv-scanner/internal/output"
"github.com/google/osv-scanner/internal/sbom"
"github.com/google/osv-scanner/pkg/config"
"github.com/google/osv-scanner/pkg/lockfile"
"github.com/google/osv-scanner/pkg/models"
"github.com/google/osv-scanner/pkg/osv"
)

type ScannerActions struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/osvscanner/vulnerability_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package osvscanner
import (
"fmt"

"github.com/google/osv-scanner/internal/osv"
"github.com/google/osv-scanner/internal/output"
"github.com/google/osv-scanner/pkg/grouper"
"github.com/google/osv-scanner/pkg/models"
"github.com/google/osv-scanner/pkg/osv"
)

// groupResponseBySource converts raw OSV API response into structured vulnerability information
Expand Down
2 changes: 1 addition & 1 deletion pkg/osvscanner/vulnerability_result_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"reflect"
"testing"

"github.com/google/osv-scanner/internal/osv"
"github.com/google/osv-scanner/internal/output"
"github.com/google/osv-scanner/pkg/models"
"github.com/google/osv-scanner/pkg/osv"
)

func Test_groupResponseBySource(t *testing.T) {
Expand Down

0 comments on commit 8f4e7cc

Please sign in to comment.