Skip to content

Commit

Permalink
remove old input to the right place, simplify git url input
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 13, 2024
1 parent ba0c6c7 commit 2a7081e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 50 deletions.
8 changes: 5 additions & 3 deletions artifactory/services/utils/tests/xray/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package xray

import xrayServices "github.com/jfrog/jfrog-client-go/xray/services"
import (
xscServices "github.com/jfrog/jfrog-client-go/xsc/services"
)

const ScanResponse = `
{
Expand Down Expand Up @@ -1437,13 +1439,13 @@ const XscGitInfoResponse = `{"multi_scan_id": "3472b4e2-bddc-11ee-a9c9-acde48001

const XscGitInfoBadResponse = `"failed create git info request: git_repo_url field must contain value"`

var GitInfoContextWithMinimalRequiredFields = xrayServices.XscGitInfoContext{
var GitInfoContextWithMinimalRequiredFields = xscServices.XscGitInfoContext{
GitRepoHttpsCloneUrl: "https://git.jfrog.info/projects/XSC/repos/xsc-service",
BranchName: "feature/XRAY-123-cool-feature",
LastCommitHash: "acc5e24e69a-d3c1-4022-62eb-69e4a1e5",
}

var GitInfoContextWithMissingFields = xrayServices.XscGitInfoContext{
var GitInfoContextWithMissingFields = xscServices.XscGitInfoContext{
GitRepoHttpsCloneUrl: "https://git.jfrog.info/projects/XSC/repos/xsc-service",
BranchName: "feature/XRAY-123-cool-feature",
}
Expand Down
7 changes: 3 additions & 4 deletions xray/services/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func (es *EnrichService) GetImportGraphResults(scanId string) (*ScanResponse, er
type XrayGraphImportParams struct {
// A path in Artifactory that this Artifact is intended to be deployed to.
// This will provide a way to extract the watches that should be applied on this graph
ScanType ScanType
SBOMInput []byte
XscGitInfoContext *XscGitInfoContext
XscVersion string
ScanType ScanType
SBOMInput []byte
XscVersion string
}
42 changes: 10 additions & 32 deletions xray/services/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,21 @@ func createScanGraphQueryParams(scanParams XrayGraphScanParams) string {
}
}
}

// Xsc params are used only when XSC is enabled and MultiScanId is provided
if scanParams.XscVersion != "" && scanParams.MultiScanId != "" {
params = append(params, multiScanIdParam+scanParams.MultiScanId)
gitInfoContext := scanParams.XscGitInfoContext
if gitInfoContext != nil {
if len(gitInfoContext.Technologies) > 0 {
// Append the tech type, each graph can contain only one tech type
params = append(params, scanTechQueryParam+gitInfoContext.Technologies[0])
}
if scanParams.Technology != "" {
params = append(params, scanTechQueryParam+scanParams.Technology)
}
}

if scanParams.ScanType != "" {
params = append(params, scanTypeQueryParam+string(scanParams.ScanType))
}

if isGitRepoUrlSupported(scanParams.XrayVersion) && scanParams.XscGitInfoContext != nil && scanParams.XscGitInfoContext.GitRepoHttpsCloneUrl != "" {
if isGitRepoUrlSupported(scanParams.XrayVersion) && scanParams.GitRepoHttpsCloneUrl != "" {
// Add git repo key to the query params to produce violations defined in the git repo policy
params = append(params, gitRepoKeyQueryParam+xscUtils.GetGitRepoUrlKey(scanParams.XscGitInfoContext.GitRepoHttpsCloneUrl))
params = append(params, gitRepoKeyQueryParam+xscUtils.GetGitRepoUrlKey(scanParams.GitRepoHttpsCloneUrl))
}

if len(params) == 0 {
Expand Down Expand Up @@ -195,7 +191,10 @@ func (ss *ScanService) GetScanGraphResults(scanId, xrayVersion string, includeVu
type XrayGraphScanParams struct {
// A path in Artifactory that this Artifact is intended to be deployed to.
// This will provide a way to extract the watches that should be applied on this graph
RepoPath string
RepoPath string
// This will provide a way to extract the watches that should be applied on this graph
GitRepoHttpsCloneUrl string
// This will provide a way to extract the watches that should be applied on this graph
ProjectKey string
Watches []string
ScanType ScanType
Expand All @@ -205,9 +204,9 @@ type XrayGraphScanParams struct {
BinaryGraph *xrayUtils.BinaryGraphNode
IncludeVulnerabilities bool
IncludeLicenses bool
XscGitInfoContext *XscGitInfoContext
XscVersion string
XrayVersion string
Technology string
MultiScanId string
}

Expand Down Expand Up @@ -326,27 +325,6 @@ type Policy struct {
Rule string `json:"rule,omitempty"`
}

type XscPostContextResponse struct {
MultiScanId string `json:"multi_scan_id,omitempty"`
}

type XscVersionResponse struct {
Version string `json:"xsc_version"`
}

type XscGitInfoContext struct {
GitRepoHttpsCloneUrl string `json:"git_repo_url"`
GitRepoName string `json:"git_repo_name,omitempty"`
GitProject string `json:"git_project,omitempty"`
GitProvider string `json:"git_provider,omitempty"`
Technologies []string `json:"technologies,omitempty"`
BranchName string `json:"branch_name"`
LastCommitUrl string `json:"last_commit,omitempty"`
LastCommitHash string `json:"commit_hash"`
LastCommitMessage string `json:"commit_message,omitempty"`
LastCommitAuthor string `json:"commit_author,omitempty"`
}

func (gp *XrayGraphScanParams) GetProjectKey() string {
return gp.ProjectKey
}
14 changes: 6 additions & 8 deletions xray/services/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ func TestCreateScanGraphQueryParams(t *testing.T) {
for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
params := XrayGraphScanParams{
RepoPath: test.repoPath,
Watches: test.watches,
ProjectKey: test.projectKey,
ScanType: test.scanType,
XrayVersion: test.xrayVersion,
XscGitInfoContext: &XscGitInfoContext{
GitRepoHttpsCloneUrl: test.gitRepoUrl,
},
RepoPath: test.repoPath,
Watches: test.watches,
ProjectKey: test.projectKey,
ScanType: test.scanType,
XrayVersion: test.xrayVersion,
GitRepoHttpsCloneUrl: test.gitRepoUrl,
}
actualQuery := createScanGraphQueryParams(params)
if actualQuery != test.expectedQuery {
Expand Down
18 changes: 15 additions & 3 deletions xsc/services/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/xray/services"
xscutils "github.com/jfrog/jfrog-client-go/xsc/services/utils"
)

Expand Down Expand Up @@ -117,8 +116,21 @@ func (vs *AnalyticsEventService) GetGeneralEvent(msi string) (*XscAnalyticsGener
// XscAnalyticsGeneralEvent extend the basic struct with Frogbot related info.
type XscAnalyticsGeneralEvent struct {
XscAnalyticsBasicGeneralEvent
GitInfo *services.XscGitInfoContext `json:"gitinfo,omitempty"`
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
GitInfo *XscGitInfoContext `json:"gitinfo,omitempty"`
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
}

type XscGitInfoContext struct {
GitRepoHttpsCloneUrl string `json:"git_repo_url"`
GitRepoName string `json:"git_repo_name,omitempty"`
GitProject string `json:"git_project,omitempty"`
GitProvider string `json:"git_provider,omitempty"`
Technologies []string `json:"technologies,omitempty"`
BranchName string `json:"branch_name"`
LastCommitUrl string `json:"last_commit,omitempty"`
LastCommitHash string `json:"commit_hash"`
LastCommitMessage string `json:"commit_message,omitempty"`
LastCommitAuthor string `json:"commit_author,omitempty"`
}

type XscAnalyticsGeneralEventFinalize struct {
Expand Down

0 comments on commit 2a7081e

Please sign in to comment.