Skip to content

Commit

Permalink
Add new XscAddGeneralEventRequest struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
gailazar300 committed Mar 26, 2024
1 parent 1579176 commit a972545
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 93 deletions.
2 changes: 1 addition & 1 deletion tests/xscevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestXscPostEvent(t *testing.T) {
AnalyzerManagerVersion: "1.1.1", //add

Check failure on line 29 in tests/xscevent_test.go

View workflow job for this annotation

GitHub Actions / Static-Check

commentFormatting: put a space between `//` and comment text (gocritic)
JpdVersion: "1.5", //?,

Check failure on line 30 in tests/xscevent_test.go

View workflow job for this annotation

GitHub Actions / Static-Check

commentFormatting: put a space between `//` and comment text (gocritic)
}
msi, err := testsEventService.PostEvent(event)
msi, err := testsEventService.PostEvent(services.XscAddGeneralEventRequest{XscGeneralEvent: event})
assert.NoError(t, err)
assert.True(t, isValidUUID(msi))
}
Expand Down
File renamed without changes.
70 changes: 1 addition & 69 deletions xsc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,76 +49,8 @@ func (sm *XscServicesManager) GetVersion() (string, error) {
}

// PostEvent will send an analytics metrics general event to Xsc and return MSI (multi scan id) generated by Xsc.
func (sm *XscServicesManager) PostEvent(event services.XscGeneralEvent) (string, error) {
// TODO should we validate?
//if !event.IsValidateEvent(event) {
// return "", nil
//}
func (sm *XscServicesManager) PostEvent(event services.XscAddGeneralEventRequest) (string, error) {
eventService := services.NewEventService(sm.client)
eventService.XscDetails = sm.config.GetServiceDetails()
return eventService.PostEvent(event)
}

// TODO: NEED TO IMPLEMENT
//// ScanGraph will send Xsc the given graph for scan
//// Returns a string represents the scan ID.
//func (sm *XscServicesManager) ScanGraph(params services.XscGraphScanParams) (scanId string, err error) {
// scanService := services.NewScanService(sm.client)
// scanService.XscDetails = sm.config.GetServiceDetails()
// return scanService.ScanGraph(params)
//}
//
//// GetScanGraphResults returns an Xsc scan output of the requested graph scan.
//// The scanId input should be received from ScanGraph request.
//func (sm *XscServicesManager) GetScanGraphResults(scanID string, includeVulnerabilities, includeLicenses bool) (*services.ScanResponse, error) {
// scanService := services.NewScanService(sm.client)
// scanService.XscDetails = sm.config.GetServiceDetails()
// return scanService.GetScanGraphResults(scanID, includeVulnerabilities, includeLicenses)
//}
//
//// BuildScan scans a published build-info with Xsc.
//// Returns a string represents the scan ID.
//func (sm *XscServicesManager) BuildScan(params services.XscBuildParams) (*services.BuildScanResponse, error) {
// buildScanService := services.NewBuildScanService(sm.client)
// buildScanService.XscDetails = sm.config.GetServiceDetails()
// err := buildScanService.Scan(params)
// if err != nil {
// return nil, err
// }
// return buildScanService.GetBuildScanResults(params)
//}
//
//// BuildSummary returns the summary of build scan which had been previously performed.
//func (sm *XscServicesManager) BuildSummary(params services.XscBuildParams) (*services.SummaryResponse, error) {
// buildSummary := services.NewSummaryService(sm.client)
// buildSummary.XscDetails = sm.config.GetServiceDetails()
// return buildSummary.GetBuildSummary(params)
//}
//
//// GenerateVulnerabilitiesReport returns a Xsc report response of the requested report
//func (sm *XscServicesManager) GenerateVulnerabilitiesReport(params services.ReportRequestParams) (resp *services.ReportResponse, err error) {
// reportService := services.NewReportService(sm.client)
// reportService.XscDetails = sm.config.GetServiceDetails()
// return reportService.Vulnerabilities(params)
//}
//
//// ReportDetails returns a Xsc details response for the requested report
//func (sm *XscServicesManager) ReportDetails(reportId string) (details *services.ReportDetails, err error) {
// reportService := services.NewReportService(sm.client)
// reportService.XscDetails = sm.config.GetServiceDetails()
// return reportService.Details(reportId)
//}
//
//// ReportContent returns a Xsc report content response for the requested report
//func (sm *XscServicesManager) ReportContent(params services.ReportContentRequestParams) (content *services.ReportContent, err error) {
// reportService := services.NewReportService(sm.client)
// reportService.XscDetails = sm.config.GetServiceDetails()
// return reportService.Content(params)
//}
//
//// DeleteReport deletes a Xsc report
//func (sm *XscServicesManager) DeleteReport(reportId string) error {
// reportService := services.NewReportService(sm.client)
// reportService.XscDetails = sm.config.GetServiceDetails()
// return reportService.Delete(reportId)
//}
31 changes: 8 additions & 23 deletions xsc/services/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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/utils/log"
"github.com/jfrog/jfrog-client-go/xray/services"
"net/http"
)

Expand All @@ -25,7 +25,7 @@ func (vs *EventService) GetXscDetails() auth.ServiceDetails {
}

// PostEvent sends general event to Xsc and returns msi generated by Xsc.
func (vs *EventService) PostEvent(event XscGeneralEvent) (string, error) {
func (vs *EventService) PostEvent(event XscAddGeneralEventRequest) (string, error) {
httpDetails := vs.XscDetails.CreateHttpClientDetails()
requestContent, err := json.Marshal(event)
if err != nil {
Expand All @@ -43,6 +43,12 @@ func (vs *EventService) PostEvent(event XscGeneralEvent) (string, error) {
return response.MultiScanId, errorutils.CheckError(err)
}

type XscAddGeneralEventRequest struct {
XscGeneralEvent
GitInfo *services.XscGitInfoContext
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
}

type XscGeneralEvent struct {
EventType int `json:"event_type,omitempty"`
EventStatus string `json:"event_status,omitempty"`
Expand All @@ -66,24 +72,3 @@ type XscGeneralEvent struct {
type XscGeneralEventResponse struct {
MultiScanId string `json:"multi_scan_id,omitempty"`
}

// TODO should we validate? or if xsc changes its values we need to updated here everytime? what are the mandatory fields?
func (e XscGeneralEvent) IsValidateEvent(event XscGeneralEvent) bool {
valid := true
if _, ok := eventTypes[e.EventType]; !ok {
valid = false
log.Error("invalid event type in xsc general event request.")
}
return valid
}

var eventTypes = map[int]string{
1: "ShiftLeftScanEvent",
2: "ScaScanEvent",
3: "ContextualExpEvent",
4: "SecretsExpEvent",
5: "IacExpEvent",
6: "SastExpEvent",
7: "ApplicationsExpEvent",
8: "SourceCodeScanEvent",
}

0 comments on commit a972545

Please sign in to comment.