Skip to content

Commit

Permalink
Before review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gailazar300 committed Mar 26, 2024
1 parent a972545 commit 336b75c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func init() {
TestArtifactory = flag.Bool("test.artifactory", false, "Test Artifactory")
TestDistribution = flag.Bool("test.distribution", false, "Test distribution")
TestXray = flag.Bool("test.xray", false, "Test xray")
TestXsc = flag.Bool("test.xsc", true, "Test xsc")
TestXsc = flag.Bool("test.xsc", false, "Test xsc")
TestPipelines = flag.Bool("test.pipelines", false, "Test pipelines")
TestAccess = flag.Bool("test.access", false, "Test access")
TestRepositories = flag.Bool("test.repositories", false, "Test repositories in Artifactory")
Expand Down
25 changes: 12 additions & 13 deletions tests/xscevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ import (
"testing"
)

var testsEventService *services.EventService
var testsEventService *services.AnalyticsEventService

func TestXscPostEvent(t *testing.T) {
xscDetails, client := initXscEventTest(t)
testsEventService = services.NewEventService(client)
testsEventService = services.NewAnalyticsEventService(client)
testsEventService.XscDetails = xscDetails

event := services.XscGeneralEvent{
EventType: 1, // ?
event := services.XscAnalyticsBasicGeneralEvent{
EventType: 1,
EventStatus: "started",
Product: "cli",
ProductVersion: "2.53.1", // add cli version call
IsDefaultConfig: false, // what is this?
JfrogUser: "gail", // add cli user
OsPlatform: "mac", // add
OsArchitecture: "arm", // add
MachineId: "", //?
AnalyzerManagerVersion: "1.1.1", //add
JpdVersion: "1.5", //?,
ProductVersion: "2.53.1",
IsDefaultConfig: false,
JfrogUser: "gail",
OsPlatform: "mac",
OsArchitecture: "arm64",
MachineId: "id",
AnalyzerManagerVersion: "1.1.1",
}
msi, err := testsEventService.PostEvent(services.XscAddGeneralEventRequest{XscGeneralEvent: event})
msi, err := testsEventService.AddGeneralEvent(services.XscAnalyticsGeneralEvent{XscAnalyticsBasicGeneralEvent: event})
assert.NoError(t, err)
assert.True(t, isValidUUID(msi))
}
Expand Down
8 changes: 4 additions & 4 deletions xsc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func (sm *XscServicesManager) GetVersion() (string, error) {
return versionService.GetVersion()
}

// 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.XscAddGeneralEventRequest) (string, error) {
eventService := services.NewEventService(sm.client)
// AddAnalyticsGeneralEvent will send an analytics metrics general event to Xsc and return MSI (multi scan id) generated by Xsc.
func (sm *XscServicesManager) AddAnalyticsGeneralEvent(event services.XscAnalyticsGeneralEvent) (string, error) {
eventService := services.NewAnalyticsEventService(sm.client)
eventService.XscDetails = sm.config.GetServiceDetails()
return eventService.PostEvent(event)
return eventService.AddGeneralEvent(event)
}
23 changes: 12 additions & 11 deletions xsc/services/event.go → xsc/services/analyticsevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (
"net/http"
)

type EventService struct {
type AnalyticsEventService struct {
client *jfroghttpclient.JfrogHttpClient
XscDetails auth.ServiceDetails
}

func NewEventService(client *jfroghttpclient.JfrogHttpClient) *EventService {
return &EventService{client: client}
func NewAnalyticsEventService(client *jfroghttpclient.JfrogHttpClient) *AnalyticsEventService {
return &AnalyticsEventService{client: client}
}

// GetXscDetails returns the Xsc details
func (vs *EventService) GetXscDetails() auth.ServiceDetails {
func (vs *AnalyticsEventService) GetXscDetails() auth.ServiceDetails {
return vs.XscDetails
}

// PostEvent sends general event to Xsc and returns msi generated by Xsc.
func (vs *EventService) PostEvent(event XscAddGeneralEventRequest) (string, error) {
// AddGeneralEvent sends general event to Xsc and returns msi generated by Xsc.
func (vs *AnalyticsEventService) AddGeneralEvent(event XscAnalyticsGeneralEvent) (string, error) {
httpDetails := vs.XscDetails.CreateHttpClientDetails()
requestContent, err := json.Marshal(event)
if err != nil {
Expand All @@ -38,18 +38,19 @@ func (vs *EventService) PostEvent(event XscAddGeneralEventRequest) (string, erro
if err = errorutils.CheckResponseStatus(resp, http.StatusCreated); err != nil {
return "", errorutils.CheckError(errorutils.GenerateResponseError(resp.Status, utils.IndentJson(body)))
}
var response XscGeneralEventResponse
var response XscAnalyticsGeneralEventResponse
err = json.Unmarshal(body, &response)
return response.MultiScanId, errorutils.CheckError(err)
}

type XscAddGeneralEventRequest struct {
XscGeneralEvent
// XscAnalyticsGeneralEvent extend the basic struct with Frogbot related info.
type XscAnalyticsGeneralEvent struct {
XscAnalyticsBasicGeneralEvent
GitInfo *services.XscGitInfoContext
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
}

type XscGeneralEvent struct {
type XscAnalyticsBasicGeneralEvent struct {
EventType int `json:"event_type,omitempty"`
EventStatus string `json:"event_status,omitempty"`
Product string `json:"product,omitempty"`
Expand All @@ -69,6 +70,6 @@ type XscGeneralEvent struct {
FrogbotCiProvider string `json:"frogbot_ci_provider,omitempty"`
}

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

0 comments on commit 336b75c

Please sign in to comment.