Skip to content

Commit

Permalink
Add Xray Source Control Service (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea authored Sep 11, 2023
1 parent 6994626 commit c4b988b
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 71 deletions.
29 changes: 14 additions & 15 deletions artifactory/services/utils/tests/xray/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,21 +1415,20 @@ const BuildScanResultsResponse = `
}
`


var MapReportIdEndpoint = map[int]string {
777: VulnerabilitiesEndpoint,
888: LicensesEndpoint,
var MapReportIdEndpoint = map[int]string{
777: VulnerabilitiesEndpoint,
888: LicensesEndpoint,
}

var MapResponse = map[string]map[string]string {
VulnerabilitiesEndpoint: {
"XrayReportRequest": VulnerabilityXrayReportRequestResponse,
"ReportStatus": VulnerabilityReportStatusResponse,
"ReportDetails": VulnerabilityReportDetailsResponse,
},
LicensesEndpoint: {
"XrayReportRequest": LicensesXrayReportRequestResponse,
"ReportStatus": LicensesReportStatusResponse,
"ReportDetails": LicensesReportDetailsResponse,
},
var MapResponse = map[string]map[string]string{
VulnerabilitiesEndpoint: {
"XrayReportRequest": VulnerabilityXrayReportRequestResponse,
"ReportStatus": VulnerabilityReportStatusResponse,
"ReportDetails": VulnerabilityReportDetailsResponse,
},
LicensesEndpoint: {
"XrayReportRequest": LicensesXrayReportRequestResponse,
"ReportStatus": LicensesReportStatusResponse,
"ReportDetails": LicensesReportDetailsResponse,
},
}
4 changes: 2 additions & 2 deletions artifactory/services/utils/tests/xray/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}

return
}
case http.MethodPost:
Expand Down Expand Up @@ -114,7 +114,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
}
case http.MethodDelete:
if numSegments == 0 {
_, err := fmt.Fprint(w, XrayReportDeleteResponse)
_, err := fmt.Fprint(w, XrayReportDeleteResponse)
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
60 changes: 30 additions & 30 deletions tests/xrayreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ func TestXrayReport(t *testing.T) {
t.Run("reportAll", reportAll)
}

var vulnerabilitiesReportRequestParams = services.VulnerabilitiesReportRequestParams {
Name: "test-report",
Filters: services.VulnerabilitiesFilter{
HasRemediation: &trueValue,
Severity: []string{"high"},
},
Resources: services.Resource{
Repositories: []services.Repository{
{
Name: "dummy-repo",
},
var vulnerabilitiesReportRequestParams = services.VulnerabilitiesReportRequestParams{
Name: "test-report",
Filters: services.VulnerabilitiesFilter{
HasRemediation: &trueValue,
Severity: []string{"high"},
},
Resources: services.Resource{
Repositories: []services.Repository{
{
Name: "dummy-repo",
},
},
}
var licensesReportRequestParams = services.LicensesReportRequestParams {
Name: "test-report",
Filters: services.LicensesFilter{
LicensePatterns: []string{"*"},
},
Resources: services.Resource{
Repositories: []services.Repository{
{
Name: "dummy-repo",
},
},
}
var licensesReportRequestParams = services.LicensesReportRequestParams{
Name: "test-report",
Filters: services.LicensesFilter{
LicensePatterns: []string{"*"},
},
Resources: services.Resource{
Repositories: []services.Repository{
{
Name: "dummy-repo",
},
},
}
var reportTypes = []string {
},
}
var reportTypes = []string{
xray.VulnerabilitiesEndpoint,
xray.LicensesEndpoint,
}
Expand All @@ -83,15 +83,15 @@ func reportAll(t *testing.T) {

reportReqCont := services.ReportContentRequestParams{
ReportType: ep,
ReportId: reportId,
Direction: "asc",
PageNum: 0,
NumRows: 7,
ReportId: reportId,
Direction: "asc",
PageNum: 0,
NumRows: 7,
}
if ep == xray.VulnerabilitiesEndpoint {
reportReqCont.OrderBy = "severity"
reportReqCont.OrderBy = "severity"
} else if ep == xray.LicensesEndpoint {
reportReqCont.OrderBy = "license"
reportReqCont.OrderBy = "license"
}
content, err := testXrayReportService.Content(reportReqCont)
assert.NoError(t, err)
Expand Down
10 changes: 8 additions & 2 deletions xray/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func (sm *XrayServicesManager) ScanGraph(params services.XrayGraphScanParams) (s

// GetScanGraphResults returns an Xray scan output of the requested graph scan.
// The scanId input should be received from ScanGraph request.
func (sm *XrayServicesManager) GetScanGraphResults(scanID string, includeVulnerabilities, includeLicenses bool) (*services.ScanResponse, error) {
func (sm *XrayServicesManager) GetScanGraphResults(scanID string, includeVulnerabilities, includeLicenses, xscEnabled bool) (*services.ScanResponse, error) {
scanService := services.NewScanService(sm.client)
scanService.XrayDetails = sm.config.GetServiceDetails()
return scanService.GetScanGraphResults(scanID, includeVulnerabilities, includeLicenses)
return scanService.GetScanGraphResults(scanID, includeVulnerabilities, includeLicenses, xscEnabled)
}

// BuildScan scans a published build-info with Xray.
Expand Down Expand Up @@ -197,3 +197,9 @@ func (sm *XrayServicesManager) IsEntitled(featureId string) (bool, error) {
entitlementsService.XrayDetails = sm.config.GetServiceDetails()
return entitlementsService.IsEntitled(featureId)
}

func (sm *XrayServicesManager) XscEnabled() (string, error) {
scanService := services.NewScanService(sm.client)
scanService.XrayDetails = sm.config.GetServiceDetails()
return scanService.IsXscEnabled()
}
39 changes: 19 additions & 20 deletions xray/services/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (

const (
// ReportsAPI refer to: https://www.jfrog.com/confluence/display/JFROG/Xray+REST+API#XrayRESTAPI-REPORTS
ReportsAPI = "api/v1/reports"
Vulnerabilities = "vulnerabilities"
Licenses = "licenses"
Violations = "violations"

ReportsAPI = "api/v1/reports"
Vulnerabilities = "vulnerabilities"
Licenses = "licenses"
Violations = "violations"
)

// ReportService defines the Http client and Xray details
Expand All @@ -43,11 +42,11 @@ type ReportDetails struct {
// ReportContentRequestParams defines a report content request
type ReportContentRequestParams struct {
ReportType string
ReportId string
Direction string
PageNum int
NumRows int
OrderBy string
ReportId string
Direction string
PageNum int
NumRows int
OrderBy string
}

// ReportContent defines a report content response
Expand Down Expand Up @@ -77,17 +76,17 @@ type Row struct {
ExternalAdvisorySource string `json:"external_advisory_source,omitempty"`
ExternalAdvisorySeverity string `json:"external_advisory_severity,omitempty"`
// Licenses Report field
License string `json:"license,omitempty"`
LicenseName string `json:"license_name,omitempty"`
Component string `json:"component,omitempty"`
Artifact string `json:"artifact,omitempty"`
ArtifactScanTime string `json:"artifact_scan_time,omitempty"`
Unknown *bool `json:"unknown,omitempty"`
Unrecognized *bool `json:"unrecognized,omitempty"`
Custom *bool `json:"custom,omitempty"`
License string `json:"license,omitempty"`
LicenseName string `json:"license_name,omitempty"`
Component string `json:"component,omitempty"`
Artifact string `json:"artifact,omitempty"`
ArtifactScanTime string `json:"artifact_scan_time,omitempty"`
Unknown *bool `json:"unknown,omitempty"`
Unrecognized *bool `json:"unrecognized,omitempty"`
Custom *bool `json:"custom,omitempty"`
// Common field
Path string `json:"path,omitempty"`
References []string `json:"references,omitempty"`
Path string `json:"path,omitempty"`
References []string `json:"references,omitempty"`
}

// For backwork compatibility keeping old struct name
Expand Down
Loading

0 comments on commit c4b988b

Please sign in to comment.