Skip to content

Commit

Permalink
Pass versions to conditional scans (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored Dec 15, 2024
1 parent 857bca8 commit 63e89a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
29 changes: 3 additions & 26 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion commands/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
}
24 changes: 24 additions & 0 deletions utils/xsc/xscmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 63e89a6

Please sign in to comment.