diff --git a/artifactory/services/utils/tests/xray/consts.go b/artifactory/services/utils/tests/xray/consts.go index 56ec4d227..2d8319278 100644 --- a/artifactory/services/utils/tests/xray/consts.go +++ b/artifactory/services/utils/tests/xray/consts.go @@ -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 = ` { @@ -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", } diff --git a/xray/services/enrich.go b/xray/services/enrich.go index 7c0924c84..346bb7cd4 100644 --- a/xray/services/enrich.go +++ b/xray/services/enrich.go @@ -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 } diff --git a/xray/services/scan.go b/xray/services/scan.go index 2ebfcfade..e2be0601e 100644 --- a/xray/services/scan.go +++ b/xray/services/scan.go @@ -78,15 +78,11 @@ 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) } } @@ -94,9 +90,9 @@ func createScanGraphQueryParams(scanParams XrayGraphScanParams) string { 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 { @@ -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 @@ -205,9 +204,9 @@ type XrayGraphScanParams struct { BinaryGraph *xrayUtils.BinaryGraphNode IncludeVulnerabilities bool IncludeLicenses bool - XscGitInfoContext *XscGitInfoContext XscVersion string XrayVersion string + Technology string MultiScanId string } @@ -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 } diff --git a/xray/services/scan_test.go b/xray/services/scan_test.go index 2366448bc..472bea801 100644 --- a/xray/services/scan_test.go +++ b/xray/services/scan_test.go @@ -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 { diff --git a/xsc/services/analytics.go b/xsc/services/analytics.go index 8603f7e9f..36ea510ca 100644 --- a/xsc/services/analytics.go +++ b/xsc/services/analytics.go @@ -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" ) @@ -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 {