diff --git a/artifactory/utils/dependenciesutils.go b/artifactory/utils/dependenciesutils.go index 9591c532b..91fa38cd1 100644 --- a/artifactory/utils/dependenciesutils.go +++ b/artifactory/utils/dependenciesutils.go @@ -57,7 +57,7 @@ func DownloadAnalyzerManagerIfNeeded() error { downloadUrl := artDetails.ArtifactoryUrl + remotePath remoteFileDetails, _, err := client.GetRemoteFileDetails(downloadUrl, &httpClientDetails) if err != nil { - return errors.New("couldn't get remote file details for " + downloadUrl) + return fmt.Errorf("couldn't get remote file details for %s: %s", downloadUrl, err.Error()) } analyzerManagerDir, err := xrayutils.GetAnalyzerManagerDirAbsolutePath() if err != nil { diff --git a/utils/usage/usage.go b/utils/usage/usage.go index 96b6ae28d..30f40f18c 100644 --- a/utils/usage/usage.go +++ b/utils/usage/usage.go @@ -2,8 +2,6 @@ package usage import ( "fmt" - xrayutils "github.com/jfrog/jfrog-cli-core/v2/xray/utils" - "golang.org/x/sync/errgroup" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" @@ -93,14 +91,6 @@ func (ur *UsageReporter) Report(features ...ReportFeature) { return }) } - if ur.sendToXray { - ur.reportWaitGroup.Go(func() (err error) { - if err = ur.reportToXray(features...); err != nil { - err = fmt.Errorf("xray, %s", err.Error()) - } - return - }) - } if ur.sendToArtifactory { ur.reportWaitGroup.Go(func() (err error) { if err = ur.reportToArtifactory(features...); err != nil { @@ -131,23 +121,6 @@ func (ur *UsageReporter) reportToEcosystem(features ...ReportFeature) (err error return ecosysusage.SendEcosystemUsageReports(reports...) } -func (ur *UsageReporter) reportToXray(features ...ReportFeature) (err error) { - if ur.serverDetails.XrayUrl == "" { - err = errorutils.CheckErrorf("Xray Url is not set.") - return - } - serviceManager, err := xrayutils.CreateXrayServiceManager(ur.serverDetails) - if err != nil { - return - } - events := ur.convertAttributesToXrayEvents(features...) - if len(events) == 0 { - err = errorutils.CheckErrorf("Nothing to send.") - return - } - return xrayusage.SendXrayUsageEvents(*serviceManager, events...) -} - func (ur *UsageReporter) reportToArtifactory(features ...ReportFeature) (err error) { if ur.serverDetails.ArtifactoryUrl == "" { err = errorutils.CheckErrorf("Artifactory Url is not set..") diff --git a/utils/usage/usage_test.go b/utils/usage/usage_test.go index d67ceef25..657f19ba1 100644 --- a/utils/usage/usage_test.go +++ b/utils/usage/usage_test.go @@ -159,64 +159,6 @@ func createArtifactoryUsageHandler(t *testing.T, productName, commandName string } } -func TestReportXrayUsage(t *testing.T) { - const productName = "test-product" - const commandName = "test-command" - const clientName = "test-client" - - server := httptest.NewServer(createXrayUsageHandler(t, productName, commandName, clientName)) - defer server.Close() - serverDetails := &config.ServerDetails{XrayUrl: server.URL + "/"} - - reporter := NewUsageReporter(productName, serverDetails).SetSendToEcosystem(false).SetSendToArtifactory(false) - - reporter.Report(ReportFeature{ - FeatureId: commandName, - ClientId: clientName, - }) - assert.NoError(t, reporter.WaitForResponses()) -} - -func TestReportXrayError(t *testing.T) { - reporter := NewUsageReporter("", &config.ServerDetails{}).SetSendToEcosystem(false).SetSendToArtifactory(false) - reporter.Report(ReportFeature{ - FeatureId: "", - }) - assert.Error(t, reporter.WaitForResponses()) - - server := httptest.NewServer(create404UsageHandler(t)) - defer server.Close() - reporter = NewUsageReporter("", &config.ServerDetails{ArtifactoryUrl: server.URL + "/"}).SetSendToEcosystem(false).SetSendToArtifactory(false) - reporter.Report(ReportFeature{ - FeatureId: "", - }) - assert.Error(t, reporter.WaitForResponses()) -} - -func createXrayUsageHandler(t *testing.T, productId, commandName, clientId string) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/api/v1/system/version" { - w.WriteHeader(http.StatusOK) - _, err := w.Write([]byte(`{"xray_version":"6.9.0"}`)) - assert.NoError(t, err) - return - } - if r.RequestURI == "/api/v1/usage/events/send" { - // Check request - buf := new(bytes.Buffer) - _, err := buf.ReadFrom(r.Body) - assert.NoError(t, err) - featureId := xrayusage.GetExpectedXrayEventName(productId, commandName) - assert.Equal(t, fmt.Sprintf(`[{"data":{"clientId":"%s"},"product_name":"%s","event_name":"%s","origin":"API_CLI"}]`, clientId, productId, featureId), buf.String()) - - // Send response OK - w.WriteHeader(http.StatusOK) - _, err = w.Write([]byte("{}")) - assert.NoError(t, err) - } - } -} - func TestReportEcosystemUsageError(t *testing.T) { // No features reporter := NewUsageReporter("", &config.ServerDetails{}).SetSendToArtifactory(false).SetSendToXray(false) diff --git a/xray/utils/analyzermanager.go b/xray/utils/analyzermanager.go index 51087cae5..940e46b82 100644 --- a/xray/utils/analyzermanager.go +++ b/xray/utils/analyzermanager.go @@ -99,7 +99,7 @@ func (am *AnalyzerManager) Exec(configFile, scanCommand, workingDir string, serv } cmd := exec.Command(am.AnalyzerManagerFullPath, scanCommand, configFile, am.MultiScanId) defer func() { - if !cmd.ProcessState.Exited() { + if cmd.ProcessState != nil && !cmd.ProcessState.Exited() { if killProcessError := cmd.Process.Kill(); errorutils.CheckError(killProcessError) != nil { err = errors.Join(err, killProcessError) }