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

Make OSV api public #167

Merged
merged 7 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
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
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