Skip to content

Commit

Permalink
Merge branch 'main' into sofa-url-column
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert authored May 30, 2024
2 parents 7e69d3d + 1c2c38c commit 5861548
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 8 additions & 3 deletions tables/sofa/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ func TestUnmarshalJSON(t *testing.T) {
}

func TestWithUserAgent(t *testing.T) {
cwd, err := os.Getwd()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "Foo/2.0", r.Header.Get("User-Agent"))
}))
path := t.TempDir()
client, err := NewSofaClient(WithUserAgent("Foo/2.0"), WithCacheDir(path))
assert.NoError(t, err)
client, err := NewSofaClient(WithUserAgent("test"), WithCacheDir(cwd))
assert.Equal(t, "Foo/2.0", client.userAgent)

err = client.downloadFile(server.URL, path+"/test.txt")
assert.NoError(t, err)
assert.Equal(t, "test", client.userAgent)
}

func TestLoacCachedEtag(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions tables/sofa/sofa_cves.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SofaUnpatchedCVEsColumns() []table.ColumnDefinition {
}
}

func SofaUnpatchedCVEsGenerate(ctx context.Context, queryContext table.QueryContext, socketPath string) ([]map[string]string, error) {
func SofaUnpatchedCVEsGenerate(ctx context.Context, queryContext table.QueryContext, socketPath string, opts ...Option) ([]map[string]string, error) {
url := SofaV1URL
if constraintList, present := queryContext.Constraints["url"]; present {
// 'url' is in the where clause
Expand Down Expand Up @@ -62,7 +62,12 @@ func SofaUnpatchedCVEsGenerate(ctx context.Context, queryContext table.QueryCont
}
}

client, err := NewSofaClient(WithURL(url))
defaultOpts := []Option{
WithURL(url),
}
opts = append(opts, defaultOpts...)

client, err := NewSofaClient(opts...)
if err != nil {
return nil, err
}
Expand Down
9 changes: 7 additions & 2 deletions tables/sofa/sofa_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func SofaSecurityReleaseInfoColumns() []table.ColumnDefinition {
}
}

func SofaSecurityReleaseInfoGenerate(ctx context.Context, queryContext table.QueryContext, socketPath string) ([]map[string]string, error) {
func SofaSecurityReleaseInfoGenerate(ctx context.Context, queryContext table.QueryContext, socketPath string, clientOpts ...Option) ([]map[string]string, error) {
url, osVersion := processContextConstraints(queryContext)

if osVersion == "" {
Expand All @@ -148,7 +148,12 @@ func SofaSecurityReleaseInfoGenerate(ctx context.Context, queryContext table.Que
}
}

client, err := NewSofaClient(WithURL(url))
defaultOpts := []Option{
WithURL(url),
}
clientOpts = append(clientOpts, defaultOpts...)

client, err := NewSofaClient(clientOpts...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5861548

Please sign in to comment.