diff --git a/cli/scancommands.go b/cli/scancommands.go index 65569d63..992d4d7a 100644 --- a/cli/scancommands.go +++ b/cli/scancommands.go @@ -206,7 +206,7 @@ func ScanCmd(c *components.Context) error { if err != nil { return err } - xrayVersion, xscVersion, err := GetJfrogServicesVersion(serverDetails) + xrayVersion, xscVersion, err := xsc.GetJfrogServicesVersion(serverDetails) if err != nil { return err } @@ -453,7 +453,7 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe if err != nil { return "", "", nil, nil, err } - xrayVersion, xscVersion, err := GetJfrogServicesVersion(serverDetails) + xrayVersion, xscVersion, err := xsc.GetJfrogServicesVersion(serverDetails) if err != nil { return "", "", nil, nil, err } @@ -713,7 +713,7 @@ func DockerScan(c *components.Context, image string) error { if err != nil { return err } - xrayVersion, xscVersion, err := GetJfrogServicesVersion(serverDetails) + xrayVersion, xscVersion, err := xsc.GetJfrogServicesVersion(serverDetails) if err != nil { return err } @@ -747,26 +747,3 @@ func DockerScan(c *components.Context, image string) error { } return progressbar.ExecWithProgress(containerScanCommand) } - -func GetJfrogServicesVersion(serverDetails *coreConfig.ServerDetails) (xrayVersion, xscVersion string, err error) { - xrayManager, err := xray.CreateXrayServiceManager(serverDetails) - if err != nil { - return - } - xrayVersion, err = xrayManager.GetVersion() - if err != nil { - return - } - log.Debug("Xray version: " + xrayVersion) - xscService, err := xsc.CreateXscService(xrayVersion, serverDetails) - if err != nil { - return - } - xscVersion, e := xscService.GetVersion() - if e != nil { - log.Debug("Using Xray: " + e.Error()) - return - } - log.Debug("XSC version: " + xscVersion) - return -} diff --git a/commands/scan/scan.go b/commands/scan/scan.go index 23b24f97..5b32c4a0 100644 --- a/commands/scan/scan.go +++ b/commands/scan/scan.go @@ -25,6 +25,7 @@ import ( "github.com/jfrog/jfrog-cli-security/utils/techutils" "github.com/jfrog/jfrog-cli-security/utils/xray" "github.com/jfrog/jfrog-cli-security/utils/xray/scangraph" + "github.com/jfrog/jfrog-cli-security/utils/xsc" xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils" "golang.org/x/sync/errgroup" @@ -625,5 +626,9 @@ func directDepsListFromVulnerabilities(scanResult ...services.ScanResponse) *[]s } func ConditionalUploadDefaultScanFunc(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat format.OutputFormat) error { - return NewScanCommand().SetServerDetails(serverDetails).SetSpec(fileSpec).SetThreads(threads).SetOutputFormat(scanOutputFormat).SetFail(true).SetPrintExtendedTable(false).Run() + xrayVersion, xscVersion, err := xsc.GetJfrogServicesVersion(serverDetails) + if err != nil { + return err + } + return NewScanCommand().SetServerDetails(serverDetails).SetXrayVersion(xrayVersion).SetXscVersion(xscVersion).SetSpec(fileSpec).SetThreads(threads).SetOutputFormat(scanOutputFormat).SetFail(true).SetPrintExtendedTable(false).Run() } diff --git a/utils/xsc/xscmanager.go b/utils/xsc/xscmanager.go index a9d5a762..8650da88 100644 --- a/utils/xsc/xscmanager.go +++ b/utils/xsc/xscmanager.go @@ -4,6 +4,7 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" clientconfig "github.com/jfrog/jfrog-client-go/config" + "github.com/jfrog/jfrog-client-go/utils/log" xscservices "github.com/jfrog/jfrog-client-go/xray/services/xsc" "github.com/jfrog/jfrog-client-go/xsc" xscservicesutils "github.com/jfrog/jfrog-client-go/xsc/services/utils" @@ -47,3 +48,26 @@ func createDeprecatedXscServiceManager(serviceDetails *config.ServerDetails) (*x } return xsc.New(serviceConfig) } + +func GetJfrogServicesVersion(serverDetails *config.ServerDetails) (xrayVersion, xscVersion string, err error) { + xrayManager, err := xray.CreateXrayServiceManager(serverDetails) + if err != nil { + return + } + xrayVersion, err = xrayManager.GetVersion() + if err != nil { + return + } + log.Debug("Xray version: " + xrayVersion) + xscService, err := CreateXscService(xrayVersion, serverDetails) + if err != nil { + return + } + xscVersion, e := xscService.GetVersion() + if e != nil { + log.Debug("Using Xray: " + e.Error()) + return + } + log.Debug("XSC version: " + xscVersion) + return +}