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

Control the depth of the pnpm dependency tree #202

Merged
merged 12 commits into from
Dec 15, 2024
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x'
attiasas marked this conversation as resolved.
Show resolved Hide resolved
dotnet-version: 6.0.425
- name: Setup Python3
uses: actions/setup-python@v4
with:
Expand Down
27 changes: 15 additions & 12 deletions cli/docs/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package docs

import (
"fmt"
"github.com/jfrog/jfrog-cli-security/commands/git"
"strings"

"github.com/jfrog/jfrog-cli-security/commands/git"

"github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
Expand Down Expand Up @@ -114,6 +115,7 @@ const (
useWrapperAudit = auditPrefix + UseWrapper
ExcludeTestDeps = "exclude-test-deps"
DepType = "dep-type"
MaxTreeDepth = "max-tree-depth"
ThirdPartyContextualAnalysis = "third-party-contextual-analysis"
RequirementsFile = "requirements-file"
WorkingDirs = "working-dirs"
Expand Down Expand Up @@ -238,17 +240,18 @@ var flagsMap = map[string]components.Flag{
"List of exclusions separated by semicolons, utilized to skip sub-projects from undergoing an audit. These exclusions may incorporate the * and ? wildcards.",
components.WithStrDefaultValue(strings.Join(utils.DefaultScaExcludePatterns, ";")),
),
Mvn: components.NewBoolFlag(Mvn, "Set to true to request audit for a Maven project."),
Gradle: components.NewBoolFlag(Gradle, "Set to true to request audit for a Gradle project."),
Npm: components.NewBoolFlag(Npm, "Set to true to request audit for a npm project."),
Pnpm: components.NewBoolFlag(Pnpm, "Set to true to request audit for a Pnpm project."),
Yarn: components.NewBoolFlag(Yarn, "Set to true to request audit for a Yarn project."),
Nuget: components.NewBoolFlag(Nuget, "Set to true to request audit for a .NET project."),
Pip: components.NewBoolFlag(Pip, "Set to true to request audit for a Pip project."),
Pipenv: components.NewBoolFlag(Pipenv, "Set to true to request audit for a Pipenv project."),
Poetry: components.NewBoolFlag(Poetry, "Set to true to request audit for a Poetry project."),
Go: components.NewBoolFlag(Go, "Set to true to request audit for a Go project."),
DepType: components.NewStringFlag(DepType, "[npm] Defines npm dependencies type. Possible values are: all, devOnly and prodOnly."),
Mvn: components.NewBoolFlag(Mvn, "Set to true to request audit for a Maven project."),
Gradle: components.NewBoolFlag(Gradle, "Set to true to request audit for a Gradle project."),
Npm: components.NewBoolFlag(Npm, "Set to true to request audit for a npm project."),
Pnpm: components.NewBoolFlag(Pnpm, "Set to true to request audit for a Pnpm project."),
Yarn: components.NewBoolFlag(Yarn, "Set to true to request audit for a Yarn project."),
Nuget: components.NewBoolFlag(Nuget, "Set to true to request audit for a .NET project."),
Pip: components.NewBoolFlag(Pip, "Set to true to request audit for a Pip project."),
Pipenv: components.NewBoolFlag(Pipenv, "Set to true to request audit for a Pipenv project."),
Poetry: components.NewBoolFlag(Poetry, "Set to true to request audit for a Poetry project."),
Go: components.NewBoolFlag(Go, "Set to true to request audit for a Go project."),
DepType: components.NewStringFlag(DepType, "[npm] Defines npm dependencies type. Possible values are: all, devOnly and prodOnly."),
MaxTreeDepth: components.NewStringFlag(MaxTreeDepth, "[pnpm] Max depth of the generated dependencies tree for SCA scan.", components.WithStrDefaultValue("Infinity")),
attiasas marked this conversation as resolved.
Show resolved Hide resolved
ThirdPartyContextualAnalysis: components.NewBoolFlag(
ThirdPartyContextualAnalysis,
"[npm] when set, the Contextual Analysis scan also uses the code of the project dependencies to determine the applicability of the vulnerability.",
Expand Down
1 change: 1 addition & 0 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func CreateAuditCmd(c *components.Context) (*audit.AuditCommand, error) {
SetInsecureTls(c.GetBoolFlagValue(flags.InsecureTls)).
SetNpmScope(c.GetStringFlagValue(flags.DepType)).
SetPipRequirementsFile(c.GetStringFlagValue(flags.RequirementsFile)).
SetMaxTreeDepth(c.GetStringFlagValue(flags.MaxTreeDepth)).
SetExclusions(pluginsCommon.GetStringsArrFlagValue(c, flags.Exclusions))
return auditCmd, err
}
Expand Down
7 changes: 5 additions & 2 deletions commands/audit/sca/pnpm/pnpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ func installProjectIfNeeded(pnpmExecPath, workingDir string) (dirForDependencies
err = fmt.Errorf("failed copying project to temp dir: %w", err)
return
}
err = getPnpmCmd(pnpmExecPath, dirForDependenciesCalculation, "install", npm.IgnoreScriptsFlag).GetCmd().Run()
output, err := getPnpmCmd(pnpmExecPath, dirForDependenciesCalculation, "install", npm.IgnoreScriptsFlag).GetCmd().CombinedOutput()
if err != nil {
err = fmt.Errorf("failed to install project: %w\n%s", err, string(output))
}
return
}

// Run 'pnpm ls ...' command (project must be installed) and parse the returned result to create a dependencies trees for the projects.
func calculateDependencies(executablePath, workingDir string, params utils.AuditParams) (dependencyTrees []*xrayUtils.GraphNode, uniqueDeps []string, err error) {
attiasas marked this conversation as resolved.
Show resolved Hide resolved
lsArgs := append([]string{"--depth", "Infinity", "--json", "--long"}, params.Args()...)
lsArgs := append([]string{"--depth", params.MaxTreeDepth(), "--json", "--long"}, params.Args()...)
npmLsCmdContent, err := getPnpmCmd(executablePath, workingDir, "ls", lsArgs...).RunWithOutput()
if err != nil {
return
Expand Down
12 changes: 12 additions & 0 deletions utils/auditbasicparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type AuditParams interface {
InstallCommandName() string
InstallCommandArgs() []string
SetNpmScope(depType string) *AuditBasicParams
SetMaxTreeDepth(maxTreeDepth string) *AuditBasicParams
MaxTreeDepth() string
OutputFormat() format.OutputFormat
DepsRepo() string
SetDepsRepo(depsRepo string) *AuditBasicParams
Expand Down Expand Up @@ -54,6 +56,7 @@ type AuditBasicParams struct {
ignoreConfigFile bool
isMavenDepTreeInstalled bool
isCurationCmd bool
maxTreeDepth string
pipRequirementsFile string
depsRepo string
installCommandName string
Expand Down Expand Up @@ -109,6 +112,15 @@ func (abp *AuditBasicParams) UseJas() bool {
return abp.useJas
}

func (abp *AuditBasicParams) MaxTreeDepth() string {
return abp.maxTreeDepth
}

func (abp *AuditBasicParams) SetMaxTreeDepth(maxTreeDepth string) *AuditBasicParams {
abp.maxTreeDepth = maxTreeDepth
return abp
}

func (abp *AuditBasicParams) PipRequirementsFile() string {
return abp.pipRequirementsFile
}
Expand Down
Loading