Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New progress bar for the audit command #417

Merged
merged 7 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/buger/jsonparser v1.1.1
github.com/c-bata/go-prompt v0.2.5 // Should not be updated to 0.2.6 duy to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
github.com/c-bata/go-prompt v0.2.5 // Should not be updated to 0.2.6 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/forPelevin/gomoji v1.1.4
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -91,6 +91,6 @@ exclude (

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.14.1-0.20220621123826-1e21b88b991f

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.3.1-0.20220620130614-83dda95caddf
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.3.1-0.20220623084021-a61432b84f63

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.0.7-0.20211213134245-6f374e4b7e3b
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i
github.com/jedib0t/go-pretty/v6 v6.3.2 h1:+46BKrPFAyhAn3MTT3vzvZc+qvWAX23yviAlBG9zAxA=
github.com/jedib0t/go-pretty/v6 v6.3.2/go.mod h1:B1WBBWnJhW9jnk7GHxY+p9NlmNwf/KUb4hKsRk6BdBQ=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jfrog/build-info-go v1.3.1-0.20220620130614-83dda95caddf h1:LprYKtz11FL8WmNBwaGPHfSPcFTrR3UkWVUEcDmh2GQ=
github.com/jfrog/build-info-go v1.3.1-0.20220620130614-83dda95caddf/go.mod h1:S2x0YOFBqBYp22goGRXGfy3ut7XaespgroVJpD6fPwk=
github.com/jfrog/build-info-go v1.3.1-0.20220623084021-a61432b84f63 h1:q4vngc6HMcDpOggrCTuYnRzp/zG76d6M7OiKdn1v1A8=
github.com/jfrog/build-info-go v1.3.1-0.20220623084021-a61432b84f63/go.mod h1:S2x0YOFBqBYp22goGRXGfy3ut7XaespgroVJpD6fPwk=
github.com/jfrog/gofrog v1.1.2 h1:txts7zSFEGan3a8G+AJCrcq4a/z8PrCmZ7m6c7qaALg=
github.com/jfrog/gofrog v1.1.2/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4=
github.com/jfrog/jfrog-client-go v1.14.1-0.20220621123826-1e21b88b991f h1:l+vtDv9wmgCyUnECIO2gtRuwirZ2ulrbDJm7VsYrDPQ=
Expand Down
1 change: 1 addition & 0 deletions utils/ioutils/ioutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ReadCredentialsFromConsole(details, savedDetails coreutils.Credentials, dis
details.SetPassword(savedDetails.GetPassword())
}
}

return nil
}

Expand Down
7 changes: 6 additions & 1 deletion xray/audit/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package audit

import (
"fmt"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -78,11 +79,15 @@ func buildXrayDependencyTree(treeHelper map[string][]string, impactPath []string
return xrDependencyTree
}

func Scan(modulesDependencyTrees []*services.GraphNode, xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails) (results []services.ScanResponse, err error) {
func Scan(modulesDependencyTrees []*services.GraphNode, xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, progress ioUtils.ProgressMgr) (results []services.ScanResponse, err error) {
if len(modulesDependencyTrees) == 0 {
return results, errorutils.CheckErrorf("No dependencies were found. Please try to build your project and re-run the audit command.")
}

if progress != nil {
progress.SetHeadlineMsg("Scanning for vulnerabilities")
}

// Get Xray version
_, xrayVersion, err := xraycommands.CreateXrayServiceManagerAndGetVersion(serverDetails)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions xray/audit/go/golang.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package _go

import (
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand All @@ -14,13 +15,13 @@ const (
goPackageTypeIdentifier = "go://"
)

func AuditGo(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditGo(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildGoDependencyTree()
if err != nil {
return
}
isMultipleRootProject = false
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/java/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package java

import (
"fmt"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"

"github.com/jfrog/jfrog-cli-core/v2/xray/audit"

Expand All @@ -12,13 +13,13 @@ import (
"github.com/jfrog/jfrog-client-go/xray/services"
)

func AuditGradle(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, excludeTestDeps, useWrapper bool) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditGradle(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, excludeTestDeps, useWrapper bool, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildGradleDependencyTree(excludeTestDeps, useWrapper)
if err != nil {
return
}
isMultipleRootProject = len(graph) > 1
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/java/mvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package java

import (
"fmt"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"

"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand All @@ -11,13 +12,13 @@ import (
"github.com/jfrog/jfrog-client-go/xray/services"
)

func AuditMvn(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, insecureTls bool) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditMvn(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, insecureTls bool, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildMvnDependencyTree(insecureTls)
if err != nil {
return
}
isMultipleRootProject = len(graph) > 1
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/audit"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/jfrog/jfrog-client-go/xray/services"
)
Expand All @@ -14,13 +15,13 @@ const (
npmPackageTypeIdentifier = "npm://"
)

func AuditNpm(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, args []string) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditNpm(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, args []string, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildNpmDependencyTree(args)
if err != nil {
return
}
isMultipleRootProject = false
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/nuget/nuget.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nuget

import (
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"github.com/jfrog/jfrog-client-go/utils/log"
"os"

Expand All @@ -15,13 +16,13 @@ const (
nugetPackageTypeIdentifier = "nuget://"
)

func AuditNuget(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditNuget(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildNugetDependencyTree()
if err != nil {
return
}
isMultipleRootProject = len(graph) > 1
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/xray/audit"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/jfrog/jfrog-client-go/xray/services"
Expand All @@ -22,13 +23,13 @@ const (
pythonPackageTypeIdentifier = "pypi://"
)

func AuditPython(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, pythonTool pythonutils.PythonTool) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditPython(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, pythonTool pythonutils.PythonTool, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := BuildDependencyTree(pythonTool)
if err != nil {
return
}
isMultipleRootProject = len(graph) > 1
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan(graph, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
5 changes: 3 additions & 2 deletions xray/audit/yarn/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/audit"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/jfrog/jfrog-client-go/xray/services"
)
Expand All @@ -14,13 +15,13 @@ const (
npmPackageTypeIdentifier = "npm://"
)

func AuditYarn(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func AuditYarn(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, progress ioUtils.ProgressMgr) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
graph, err := buildYarnDependencyTree()
if err != nil {
return
}
isMultipleRootProject = false
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails)
results, err = audit.Scan([]*services.GraphNode{graph}, xrayGraphScanPrams, serverDetails, progress)
return
}

Expand Down
23 changes: 14 additions & 9 deletions xray/commands/audit/generic/auditmanager.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package audit

import (
"fmt"
"github.com/jfrog/build-info-go/utils/pythonutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/audit/yarn"
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"os"

"github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand All @@ -18,7 +20,7 @@ import (
)

// GenericAudit audits the project found in the current directory using Xray.
func GenericAudit(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, excludeTestDeps, useWrapper, insecureTls bool, args []string, technologies ...string) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
func GenericAudit(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails *config.ServerDetails, excludeTestDeps, useWrapper, insecureTls bool, args []string, progress ioUtils.ProgressMgr, technologies ...string) (results []services.ScanResponse, isMultipleRootProject bool, err error) {
// If no technologies were given, try to detect all types of technologies used.
// Otherwise, run audit for requested technologies only.
if len(technologies) == 0 {
Expand All @@ -31,25 +33,28 @@ func GenericAudit(xrayGraphScanPrams services.XrayGraphScanParams, serverDetails
for _, tech := range coreutils.ToTechnologies(technologies) {
var techResults []services.ScanResponse
var e error
if progress != nil {
progress.SetHeadlineMsg(fmt.Sprintf("Calculating %v dependencies", tech))
}
switch tech {
case coreutils.Maven:
techResults, isMultipleRootProject, e = java.AuditMvn(xrayGraphScanPrams, serverDetails, insecureTls)
techResults, isMultipleRootProject, e = java.AuditMvn(xrayGraphScanPrams, serverDetails, insecureTls, progress)
case coreutils.Gradle:
techResults, isMultipleRootProject, e = java.AuditGradle(xrayGraphScanPrams, serverDetails, excludeTestDeps, useWrapper)
techResults, isMultipleRootProject, e = java.AuditGradle(xrayGraphScanPrams, serverDetails, excludeTestDeps, useWrapper, progress)
case coreutils.Npm:
techResults, isMultipleRootProject, e = npm.AuditNpm(xrayGraphScanPrams, serverDetails, args)
techResults, isMultipleRootProject, e = npm.AuditNpm(xrayGraphScanPrams, serverDetails, args, progress)
case coreutils.Yarn:
techResults, isMultipleRootProject, e = yarn.AuditYarn(xrayGraphScanPrams, serverDetails)
techResults, isMultipleRootProject, e = yarn.AuditYarn(xrayGraphScanPrams, serverDetails, progress)
case coreutils.Go:
techResults, isMultipleRootProject, e = _go.AuditGo(xrayGraphScanPrams, serverDetails)
techResults, isMultipleRootProject, e = _go.AuditGo(xrayGraphScanPrams, serverDetails, progress)
case coreutils.Pip:
techResults, isMultipleRootProject, e = python.AuditPython(xrayGraphScanPrams, serverDetails, pythonutils.Pip)
techResults, isMultipleRootProject, e = python.AuditPython(xrayGraphScanPrams, serverDetails, pythonutils.Pip, progress)
case coreutils.Pipenv:
techResults, isMultipleRootProject, e = python.AuditPython(xrayGraphScanPrams, serverDetails, pythonutils.Pipenv)
techResults, isMultipleRootProject, e = python.AuditPython(xrayGraphScanPrams, serverDetails, pythonutils.Pipenv, progress)
case coreutils.Dotnet:
continue
case coreutils.Nuget:
techResults, isMultipleRootProject, e = nuget.AuditNuget(xrayGraphScanPrams, serverDetails)
techResults, isMultipleRootProject, e = nuget.AuditNuget(xrayGraphScanPrams, serverDetails, progress)
default:
log.Info(string(tech), " is currently not supported")
}
Expand Down
16 changes: 15 additions & 1 deletion xray/commands/audit/generic/generic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package audit

import (
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"os"

"github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand All @@ -24,6 +25,7 @@ type GenericAuditCommand struct {
insecureTls bool
args []string
technologies []string
progress ioUtils.ProgressMgr
}

func NewGenericAuditCommand() *GenericAuditCommand {
Expand Down Expand Up @@ -100,7 +102,15 @@ func (auditCmd *GenericAuditCommand) Run() (err error) {
if err != nil {
return err
}
results, isMultipleRootProject, err := GenericAudit(auditCmd.CreateXrayGraphScanParams(), server, auditCmd.excludeTestDependencies, auditCmd.useWrapper, auditCmd.insecureTls, auditCmd.args, auditCmd.technologies...)
results, isMultipleRootProject, err := GenericAudit(auditCmd.CreateXrayGraphScanParams(), server, auditCmd.excludeTestDependencies, auditCmd.useWrapper, auditCmd.insecureTls, auditCmd.args, auditCmd.progress, auditCmd.technologies...)
if err != nil {
return err
}

if auditCmd.progress != nil {
err = auditCmd.progress.Quit()
}

if err != nil {
return err
}
Expand Down Expand Up @@ -149,3 +159,7 @@ func (auditCmd *GenericAuditCommand) SetTechnologies(technologies []string) *Gen
auditCmd.technologies = technologies
return auditCmd
}

func (auditCmd *GenericAuditCommand) SetProgress(progress ioUtils.ProgressMgr) {
auditCmd.progress = progress
}