Skip to content

Commit

Permalink
updated npmpackagehandler to resolve from Artifactory if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Jan 21, 2024
1 parent d44be67 commit d307aaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
26 changes: 9 additions & 17 deletions commands/audit/sca/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func BuildDependencyTree(params utils.AuditParams) (dependencyTrees []*xrayUtils

treeDepsParam := createTreeDepsParam(params)

restoreNpmrcFunc, err := configNpmResolutionServerIfNeeded(params)
clearResolutionServerFunc, err := configNpmResolutionServerIfNeeded(params)
if err != nil {
err = fmt.Errorf("failed while configuring a resolution server: %s", err.Error())
return
}
defer func() {
if restoreNpmrcFunc != nil {
err = errors.Join(err, restoreNpmrcFunc())
if clearResolutionServerFunc != nil {
err = errors.Join(err, clearResolutionServerFunc())
}
}()

Expand All @@ -62,29 +62,21 @@ func BuildDependencyTree(params utils.AuditParams) (dependencyTrees []*xrayUtils
}

// Generates a .npmrc file to configure an Artifactory server as the resolver server.
func configNpmResolutionServerIfNeeded(params utils.AuditParams) (restoreNpmrcFunc func() error, err error) {
func configNpmResolutionServerIfNeeded(params utils.AuditParams) (clearResolutionServerFunc func() error, err error) {
if params == nil {
err = fmt.Errorf("got empty params upon configuring resolution server")
return
}
serverDetails, err := params.ServerDetails()
if err != nil || serverDetails == nil {
// If we don't have an artifactory repo's name we don't need to configure any Artifactory server as resolution server
if params.DepsRepo() == "" {
return
}
depsRepo := params.DepsRepo()
if depsRepo == "" {
serverDetails, err := params.ServerDetails()
if err != nil {
return
}

npmCmd := npm.NewNpmCommand("install", false).SetServerDetails(serverDetails)
if err = npmCmd.PreparePrerequisites(depsRepo); err != nil {
return
}
if err = npmCmd.CreateTempNpmrc(); err != nil {
return
}
restoreNpmrcFunc = npmCmd.RestoreNpmrcFunc()
log.Info(fmt.Sprintf("Resolving dependencies from '%s' from repo '%s'", serverDetails.Url, depsRepo))
clearResolutionServerFunc, err = npm.SetArtifactoryAsResolutionServer(serverDetails, params.DepsRepo())
return
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ 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.20240118100957-b4e1537e91dd
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/eranturgeman/jfrog-cli-core/v2 v2.0.0-20240121115147-bc91eda8463b
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdf
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/eranturgeman/jfrog-cli-core/v2 v2.0.0-20240121115147-bc91eda8463b h1:l0R6StNr4Amc5M16G7yYPSl/k20MQGn7cYG/O2bJKwI=
github.com/eranturgeman/jfrog-cli-core/v2 v2.0.0-20240121115147-bc91eda8463b/go.mod h1:tbplJYWXBgQNLMWadfZYh2uaajZjG1tLgBb1txLNAQw=
github.com/forPelevin/gomoji v1.1.8 h1:JElzDdt0TyiUlecy6PfITDL6eGvIaxqYH1V52zrd0qQ=
github.com/forPelevin/gomoji v1.1.8/go.mod h1:8+Z3KNGkdslmeGZBC3tCrwMrcPy5GRzAD+gL9NAwMXg=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down Expand Up @@ -93,8 +95,6 @@ github.com/jfrog/gofrog v1.5.0 h1:OLaXpNaEniliE4Kq8lJ5evVYzzt3zdYtpMIBu6TO++c=
github.com/jfrog/gofrog v1.5.0/go.mod h1:wQqagqq2VpuCWRPlq/65GbH9gsRz+7Bgc1Q+PKD4Y+k=
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.20240118100957-b4e1537e91dd h1:7JOQANVaULKq0b2X10ERsEAZOGccfooOvstr3UZcGTc=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240118100957-b4e1537e91dd/go.mod h1:tbplJYWXBgQNLMWadfZYh2uaajZjG1tLgBb1txLNAQw=
github.com/jfrog/jfrog-client-go v1.35.6 h1:nVS94x6cwSRkhtj8OM3elbUcGgQhqsK8YMPvC/gf5sk=
github.com/jfrog/jfrog-client-go v1.35.6/go.mod h1:V+XKC27k6GA5OcWIAItpnxZAZnCigg8xCkpXKP905Fk=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down

0 comments on commit d307aaa

Please sign in to comment.