-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from atomist-skills/fixed-data-source
fixed data source should be in here for testing
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package data | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/atomist-skills/go-skill/policy/data/proxy" | ||
"github.com/atomist-skills/go-skill/policy/data/query" | ||
"github.com/atomist-skills/go-skill/policy/goals" | ||
"github.com/atomist-skills/go-skill/policy/types" | ||
) | ||
|
||
type vulnerabilityFetcher func(ctx context.Context, evalCtx goals.GoalEvaluationContext, imageSbom types.SBOM) (*query.QueryResponse, []types.Package, map[string][]types.Vulnerability, error) | ||
|
||
type fixedDataSource struct { | ||
jynxGQLClient query.QueryClient | ||
proxyClient *proxy.ProxyClient | ||
vulnerabilities vulnerabilityFetcher | ||
} | ||
|
||
func NewFixedDataSource(jynxGQLClient query.QueryClient, proxyClient *proxy.ProxyClient, vulnerabilities vulnerabilityFetcher) DataSource { | ||
return &fixedDataSource{ | ||
jynxGQLClient: jynxGQLClient, | ||
proxyClient: proxyClient, | ||
vulnerabilities: vulnerabilities, | ||
} | ||
} | ||
|
||
func (ds *fixedDataSource) GetQueryClient() query.QueryClient { | ||
return ds.jynxGQLClient | ||
} | ||
|
||
func (ds *fixedDataSource) GetProxyClient() (*proxy.ProxyClient, error) { | ||
return ds.proxyClient, nil | ||
} | ||
|
||
func (ds *fixedDataSource) GetImageVulnerabilities(ctx context.Context, evalCtx goals.GoalEvaluationContext, imageSbom types.SBOM) (*query.QueryResponse, []types.Package, map[string][]types.Vulnerability, error) { | ||
if ds.vulnerabilities != nil { | ||
return ds.vulnerabilities(ctx, evalCtx, imageSbom) | ||
} | ||
|
||
return &query.QueryResponse{}, []types.Package{}, map[string][]types.Vulnerability{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type FixedQueryClientUnmarshaler func(data []byte, output interface{}) error | ||
|
||
// FixedQueryClient returns static data from responses passed in at construction time | ||
type FixedQueryClient struct { | ||
unmarshaler FixedQueryClientUnmarshaler | ||
data map[string][]byte | ||
} | ||
|
||
func NewFixedQueryClient(unmarshaler FixedQueryClientUnmarshaler, data map[string][]byte) FixedQueryClient { | ||
return FixedQueryClient{ | ||
unmarshaler: unmarshaler, | ||
data: data, | ||
} | ||
} | ||
|
||
func (ds FixedQueryClient) Query(ctx context.Context, queryName string, queryBody string, variables map[string]interface{}, output interface{}) (*QueryResponse, error) { | ||
res, ok := ds.data[queryName] | ||
if !ok { | ||
return nil, nil | ||
} | ||
|
||
err := ds.unmarshaler(res, output) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &QueryResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters