Skip to content

Commit

Permalink
Use project env val in commands (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored Aug 21, 2024
1 parent 6050884 commit ba47070
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
14 changes: 9 additions & 5 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)).
Expand Down Expand Up @@ -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)).
Expand Down
7 changes: 1 addition & 6 deletions commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit ba47070

Please sign in to comment.