Skip to content

fix: populate results_url #7

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

Merged
merged 1 commit into from
Feb 1, 2024
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
6 changes: 6 additions & 0 deletions jfrog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type Client interface {
ScanResults(img Image) (ScanResult, error)
ResultsURL(img Image, packageID string) string
}

type client struct {
Expand Down Expand Up @@ -55,6 +56,7 @@ type securityResultsPayload struct {
type ScanResult struct {
Version string `json:"version"`
SecurityIssues SecurityIssues `json:"sec_issues"`
PackageID string `json:"package_id"`
}

type SecurityIssues struct {
Expand Down Expand Up @@ -98,6 +100,10 @@ type Image struct {
Version string
}

func (c *client) ResultsURL(img Image, packageID string) string {
return fmt.Sprintf("%s/ui/scans-list/packages-scans/%s/%s/scan-descendants/%s?package_id=%s&version=%s", c.baseURL, img.Repo, img.Package, img.Version, packageID, img.Version)
}

func ParseImage(image string) (Image, error) {
tag, err := name.NewTag(image)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion jfrog/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// artifactory instance.
package jfrog

//go:generate mockgen -destination ./mock.go -package jfrog github.com/coder/xray/jfrog Client
//go:generate mockgen -destination ./mock.go -package jfrog github.com/coder/coder-xray/jfrog Client
18 changes: 16 additions & 2 deletions jfrog/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions reporter/codermock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reporter/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// and uploading results to a Coder deployment.
package reporter

//go:generate mockgen -destination ./codermock.go -package reporter github.com/coder/xray/reporter CoderClient
//go:generate mockgen -destination ./codermock.go -package reporter github.com/coder/coder-xray/reporter CoderClient
1 change: 1 addition & 0 deletions reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (k *K8sReporter) Init(ctx context.Context) error {
Critical: scan.SecurityIssues.Critical,
High: scan.SecurityIssues.High,
Medium: scan.SecurityIssues.Medium,
ResultsURL: k.JFrogClient.ResultsURL(image, scan.PackageID),
}
err = k.CoderClient.PostJFrogXrayScan(ctx, req)
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,26 @@ func TestK8SReporter(t *testing.T) {
resultsCh = make(chan codersdk.JFrogXrayScan)
)

jfrogClient.EXPECT().ScanResults(jfrog.Image{
img := jfrog.Image{
Repo: "my-repo",
Package: "ubuntu",
Version: "22.04",
}).Return(jfrog.ScanResult{
}

xrayResult := jfrog.ScanResult{
Version: "22.04",
SecurityIssues: jfrog.SecurityIssues{
Critical: expectedCrit,
High: expectedHigh,
Medium: expectedMedium,
Total: expectedCrit + expectedHigh + expectedMedium,
},
}, nil)
PackageID: "docker://my-repo/ubuntu",
}

jfrogClient.EXPECT().ScanResults(img).Return(xrayResult, nil)

jfrogClient.EXPECT().ResultsURL(img, xrayResult.PackageID)

coderClient.EXPECT().AgentManifest(ctx, expectedAgentToken).Return(agentsdk.Manifest{
WorkspaceID: expectedWorkspaceID,
Expand Down