From ba470705ca3d2a85103c450124694a9f42784e1e Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:50:04 +0300 Subject: [PATCH] Use project env val in commands (#148) --- cli/scancommands.go | 14 +++++++++----- commands/audit/audit.go | 7 +------ go.mod | 6 +++--- go.sum | 8 ++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cli/scancommands.go b/cli/scancommands.go index ce9ecd99..c969eadb 100644 --- a/cli/scancommands.go +++ b/cli/scancommands.go @@ -236,7 +236,7 @@ func ScanCmd(c *components.Context) error { SetThreads(threads). SetSpec(specFile). SetOutputFormat(format). - SetProject(c.GetStringFlagValue(flags.Project)). + SetProject(getProject(c)). SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)). SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)). SetFail(c.GetBoolFlagValue(flags.Fail)). @@ -287,10 +287,14 @@ func getMinimumSeverity(c *components.Context) (severity severityutils.Severity, } func isProjectProvided(c *components.Context) bool { + return getProject(c) != "" +} + +func getProject(c *components.Context) string { if c.IsFlagSet(flags.Project) { - return c.GetStringFlagValue(flags.Project) != "" + return c.GetStringFlagValue(flags.Project) } - return os.Getenv(coreutils.Project) != "" + return os.Getenv(coreutils.Project) } func addTrailingSlashToRepoPathIfNeeded(c *components.Context) string { @@ -454,7 +458,7 @@ func CreateAuditCmd(c *components.Context) (*audit.AuditCommand, error) { auditCmd.SetAnalyticsMetricsService(xsc.NewAnalyticsMetricsService(serverDetails)) auditCmd.SetTargetRepoPath(addTrailingSlashToRepoPathIfNeeded(c)). - SetProject(c.GetStringFlagValue(flags.Project)). + SetProject(getProject(c)). SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)). SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)). SetFail(c.GetBoolFlagValue(flags.Fail)). @@ -689,7 +693,7 @@ func DockerScan(c *components.Context, image string) error { SetTargetRepoPath(addTrailingSlashToRepoPathIfNeeded(c)). SetServerDetails(serverDetails). SetOutputFormat(format). - SetProject(c.GetStringFlagValue(flags.Project)). + SetProject(getProject(c)). SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)). SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)). SetFail(c.GetBoolFlagValue(flags.Fail)). diff --git a/commands/audit/audit.go b/commands/audit/audit.go index 091ae012..531f18e4 100644 --- a/commands/audit/audit.go +++ b/commands/audit/audit.go @@ -3,7 +3,6 @@ package audit import ( "errors" "fmt" - "os" jfrogappsconfig "github.com/jfrog/jfrog-apps-config/go" "github.com/jfrog/jfrog-cli-core/v2/utils/config" @@ -92,11 +91,7 @@ func (auditCmd *AuditCommand) CreateCommonGraphScanParams() *scangraph.CommonGra Watches: auditCmd.watches, ScanType: services.Dependency, } - if auditCmd.projectKey == "" { - commonParams.ProjectKey = os.Getenv(coreutils.Project) - } else { - commonParams.ProjectKey = auditCmd.projectKey - } + commonParams.ProjectKey = auditCmd.projectKey commonParams.IncludeVulnerabilities = auditCmd.IncludeVulnerabilities commonParams.IncludeLicenses = auditCmd.IncludeLicenses commonParams.MultiScanId, commonParams.XscVersion = xsc.GetXscMsiAndVersion(auditCmd.analyticsMetricsService) diff --git a/go.mod b/go.mod index 18778448..ddd0a3e7 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/jfrog/froggit-go v1.16.1 github.com/jfrog/gofrog v1.7.5 github.com/jfrog/jfrog-apps-config v1.0.1 - github.com/jfrog/jfrog-cli-core/v2 v2.54.1 + github.com/jfrog/jfrog-cli-core/v2 v2.55.2 github.com/jfrog/jfrog-client-go v1.44.2 github.com/magiconair/properties v1.8.7 github.com/owenrumney/go-sarif/v2 v2.3.0 @@ -114,10 +114,10 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240820213306-d507532c4863 +// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go dev -replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240820163739-bb148903e3de +// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go dev // replace github.com/jfrog/froggit-go => github.com/jfrog/froggit-go dev diff --git a/go.sum b/go.sum index 98a8a48f..77d8088e 100644 --- a/go.sum +++ b/go.sum @@ -890,16 +890,16 @@ github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+ github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI= github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw= -github.com/jfrog/build-info-go v1.8.9-0.20240820163739-bb148903e3de h1:1nnH4GCKTXH2jhjTCONI4DMNnS8u9c0bhDFZzl6fE5g= -github.com/jfrog/build-info-go v1.8.9-0.20240820163739-bb148903e3de/go.mod h1:6mdtqjREK76bHNODXakqKR/+ksJ9dvfLS7H57BZtnLY= +github.com/jfrog/build-info-go v1.9.34 h1:bPnW58VpclbpBe/x8XEu/2BIviEOoJrJ5PkRRcmU3Co= +github.com/jfrog/build-info-go v1.9.34/go.mod h1:6mdtqjREK76bHNODXakqKR/+ksJ9dvfLS7H57BZtnLY= github.com/jfrog/froggit-go v1.16.1 h1:FBIM1qevX/ag9unfmpGzfmZ36D8ulOJ+DPTSFUk3l5U= github.com/jfrog/froggit-go v1.16.1/go.mod h1:TEJSzgiV+3D/GVGE8Y6j46ut1jrBLD1FL6WdMdKwwCE= github.com/jfrog/gofrog v1.7.5 h1:dFgtEDefJdlq9cqTRoe09RLxS5Bxbe1Ev5+E6SmZHcg= github.com/jfrog/gofrog v1.7.5/go.mod h1:jyGiCgiqSSR7k86hcUSu67XVvmvkkgWTmPsH25wI298= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240820213306-d507532c4863 h1:gD9gzsdmdrJZaqIJ/f16tuyyl64DPMDw2YQRGmHfooY= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240820213306-d507532c4863/go.mod h1:2/Ccqq0ayMqIuH5AAoneX0CowwdrNWQcs5aKz8iDYkE= +github.com/jfrog/jfrog-cli-core/v2 v2.55.2 h1:Pm4mY1UThSyFGklDl6O8qoJgTgH9jL3i2tor/ux+X8c= +github.com/jfrog/jfrog-cli-core/v2 v2.55.2/go.mod h1:2/Ccqq0ayMqIuH5AAoneX0CowwdrNWQcs5aKz8iDYkE= github.com/jfrog/jfrog-client-go v1.44.2 h1:5t8tx6NOth6Xq24SdF3MYSd6vo0bTibW93nads2DEuY= github.com/jfrog/jfrog-client-go v1.44.2/go.mod h1:f5Jfv+RGKVr4smOp4a4pxyBKdlpLG7R894kx2XW+w8c= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=