@@ -9,16 +9,16 @@ import (
99 biutils "github.com/jfrog/build-info-go/utils"
1010 "github.com/jfrog/build-info-go/utils/pythonutils"
1111 "github.com/jfrog/gofrog/datastructures"
12- utils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
12+ artifactoryutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
1313 "github.com/jfrog/jfrog-cli-core/v2/utils/config"
1414 "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1515 "github.com/jfrog/jfrog-cli-security/commands/audit/sca"
16- xrayutils2 "github.com/jfrog/jfrog-cli-security/utils"
16+ "github.com/jfrog/jfrog-cli-security/utils"
1717 "github.com/jfrog/jfrog-cli-security/utils/techutils"
1818 "github.com/jfrog/jfrog-client-go/utils/errorutils"
1919 "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
2020 "github.com/jfrog/jfrog-client-go/utils/log"
21- xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
21+ clientutils "github.com/jfrog/jfrog-client-go/xray/services/utils"
2222
2323 "os"
2424 "os/exec"
@@ -34,6 +34,7 @@ const (
3434 CurationPipMinimumVersion = "23.0.0"
3535)
3636
37+ /* TODO eran delete at the end
3738type AuditPython struct {
3839 Server *config.ServerDetails
3940 Tool pythonutils.PythonTool
@@ -43,33 +44,35 @@ type AuditPython struct {
4344 IsCurationCmd bool
4445}
4546
46- func BuildDependencyTree (params xrayutils2.AuditParams ) (dependencyTree []* xrayUtils.GraphNode , uniqueDeps []string , downloadUrls map [string ]string , err error ) {
47+ */
48+
49+ func BuildDependencyTree (params utils.AuditParams ) (dependencyTree []* clientutils.GraphNode , uniqueDeps []string , downloadUrls map [string ]string , err error ) {
4750 dependenciesGraph , directDependenciesList , pipUrls , errGetTree := getDependencies (params )
4851 if errGetTree != nil {
4952 err = errGetTree
5053 return
5154 }
5255 downloadUrls = pipUrls
53- directDependencies := []* xrayUtils .GraphNode {}
56+ directDependencies := []* clientutils .GraphNode {}
5457 uniqueDepsSet := datastructures .MakeSet [string ]()
5558 for _ , rootDep := range directDependenciesList {
56- directDependency := & xrayUtils .GraphNode {
59+ directDependency := & clientutils .GraphNode {
5760 Id : PythonPackageTypeIdentifier + rootDep ,
58- Nodes : []* xrayUtils .GraphNode {},
61+ Nodes : []* clientutils .GraphNode {},
5962 }
6063 populatePythonDependencyTree (directDependency , dependenciesGraph , uniqueDepsSet )
6164 directDependencies = append (directDependencies , directDependency )
6265 }
63- root := & xrayUtils .GraphNode {
66+ root := & clientutils .GraphNode {
6467 Id : "root" ,
6568 Nodes : directDependencies ,
6669 }
67- dependencyTree = []* xrayUtils .GraphNode {root }
70+ dependencyTree = []* clientutils .GraphNode {root }
6871 uniqueDeps = uniqueDepsSet .ToSlice ()
6972 return
7073}
7174
72- func getDependencies (params xrayutils2 .AuditParams ) (dependenciesGraph map [string ][]string , directDependencies []string , pipUrls map [string ]string , err error ) {
75+ func getDependencies (params utils .AuditParams ) (dependenciesGraph map [string ][]string , directDependencies []string , pipUrls map [string ]string , err error ) {
7376 wd , err := os .Getwd ()
7477 if errorutils .CheckError (err ) != nil {
7578 return
@@ -99,17 +102,22 @@ func getDependencies(params xrayutils2.AuditParams) (dependenciesGraph map[strin
99102 if err != nil {
100103 return
101104 }
102- pythonTool := pythonutils .Pip
103- if len (params .Technologies ()) > 0 {
104- pythonTool = pythonutils .PythonTool (params .Technologies ()[0 ])
105- }
105+
106+ // TODO eran - is it possible to not have the technology here so we need to place pip first? is that even correct doing that?
107+ /*
108+ pythonTool := pythonutils.Pip
109+ if len(params.Technologies()) > 0 {
110+ pythonTool = pythonutils.PythonTool(params.Technologies()[0])
111+ }
112+ */
113+ pythonTool := pythonutils .PythonTool (params .Technologies ()[0 ])
106114 if ! params .SkipAutoInstall () {
107- restoreEnv , restoreEnvErr := runPythonInstall (params , pythonTool )
115+ var restoreEnv func () error
116+ restoreEnv , err = runPythonInstall (params , pythonTool )
108117 defer func () {
109- restoreEnvErr = errors .Join (restoreEnvErr , restoreEnv ())
118+ err = errors .Join (err , restoreEnv ())
110119 }()
111- if restoreEnvErr != nil {
112- err = restoreEnvErr
120+ if err != nil {
113121 return
114122 }
115123 }
@@ -187,7 +195,7 @@ type pypiMetaData struct {
187195 Version string `json:"version"`
188196}
189197
190- func runPythonInstall (params xrayutils2 .AuditParams , tool pythonutils.PythonTool ) (restoreEnv func () error , err error ) {
198+ func runPythonInstall (params utils .AuditParams , tool pythonutils.PythonTool ) (restoreEnv func () error , err error ) {
191199 switch tool {
192200 case pythonutils .Pip :
193201 return installPipDeps (params )
@@ -199,7 +207,7 @@ func runPythonInstall(params xrayutils2.AuditParams, tool pythonutils.PythonTool
199207 return
200208}
201209
202- func installPoetryDeps (params xrayutils2 .AuditParams ) (restoreEnv func () error , err error ) {
210+ func installPoetryDeps (params utils .AuditParams ) (restoreEnv func () error , err error ) {
203211 restoreEnv = func () error {
204212 return nil
205213 }
@@ -209,12 +217,12 @@ func installPoetryDeps(params xrayutils2.AuditParams) (restoreEnv func() error,
209217 if err != nil {
210218 return restoreEnv , err
211219 }
212- rtUrl , username , password , err := utils .GetPypiRepoUrlWithCredentials (serverDetails , params .DepsRepo (), false )
220+ rtUrl , username , password , err := artifactoryutils .GetPypiRepoUrlWithCredentials (serverDetails , params .DepsRepo (), false )
213221 if err != nil {
214222 return restoreEnv , err
215223 }
216224 if password != "" {
217- err = utils .ConfigPoetryRepo (rtUrl .Scheme + "://" + rtUrl .Host + rtUrl .Path , username , password , params .DepsRepo ())
225+ err = artifactoryutils .ConfigPoetryRepo (rtUrl .Scheme + "://" + rtUrl .Host + rtUrl .Path , username , password , params .DepsRepo ())
218226 if err != nil {
219227 return restoreEnv , err
220228 }
@@ -225,7 +233,7 @@ func installPoetryDeps(params xrayutils2.AuditParams) (restoreEnv func() error,
225233 return restoreEnv , err
226234}
227235
228- func installPipenvDeps (params xrayutils2 .AuditParams ) (restoreEnv func () error , err error ) {
236+ func installPipenvDeps (params utils .AuditParams ) (restoreEnv func () error , err error ) {
229237 // Set virtualenv path to venv dir
230238 err = os .Setenv ("WORKON_HOME" , ".jfrog" )
231239 if err != nil {
@@ -247,7 +255,7 @@ func installPipenvDeps(params xrayutils2.AuditParams) (restoreEnv func() error,
247255 return restoreEnv , err
248256}
249257
250- func installPipDeps (params xrayutils2 .AuditParams ) (restoreEnv func () error , err error ) {
258+ func installPipDeps (params utils .AuditParams ) (restoreEnv func () error , err error ) {
251259 restoreEnv , err = SetPipVirtualEnvPath ()
252260 if err != nil {
253261 return
@@ -260,7 +268,7 @@ func installPipDeps(params xrayutils2.AuditParams) (restoreEnv func() error, err
260268 if err != nil {
261269 return
262270 }
263- remoteUrl , err = utils .GetPypiRepoUrl (serverDetails , params .DepsRepo (), params .IsCurationCmd ())
271+ remoteUrl , err = artifactoryutils .GetPypiRepoUrl (serverDetails , params .DepsRepo (), params .IsCurationCmd ())
264272 if err != nil {
265273 return
266274 }
@@ -273,7 +281,7 @@ func installPipDeps(params xrayutils2.AuditParams) (restoreEnv func() error, err
273281 if err = upgradePipVersion (CurationPipMinimumVersion ); err != nil {
274282 log .Warn (fmt .Sprintf ("Failed to upgrade pip version, err: %v" , err ))
275283 }
276- if curationCachePip , err = xrayutils2 .GetCurationPipCacheFolder (); err != nil {
284+ if curationCachePip , err = utils .GetCurationPipCacheFolder (); err != nil {
277285 return
278286 }
279287 reportFileName = pythonReportFile
@@ -339,7 +347,7 @@ func getPipInstallArgs(requirementsFile, remoteUrl, cacheFolder, reportFileName
339347 args = append (args , "-r" , requirementsFile )
340348 }
341349 if remoteUrl != "" {
342- args = append (args , utils .GetPypiRemoteRegistryFlag (pythonutils .Pip ), remoteUrl )
350+ args = append (args , artifactoryutils .GetPypiRemoteRegistryFlag (pythonutils .Pip ), remoteUrl )
343351 }
344352 if cacheFolder != "" {
345353 args = append (args , "--cache-dir" , cacheFolder )
@@ -380,7 +388,7 @@ func parseCustomArgs(remoteUrl, cacheFolder, reportFileName string, customArgs .
380388 continue
381389 }
382390 }
383- if remoteUrl != "" && strings .Contains (customArgs [i ], utils .GetPypiRemoteRegistryFlag (pythonutils .Pip )) {
391+ if remoteUrl != "" && strings .Contains (customArgs [i ], artifactoryutils .GetPypiRemoteRegistryFlag (pythonutils .Pip )) {
384392 log .Warn ("The remote registry flag is not supported in the custom arguments list. skipping..." )
385393 i ++
386394 continue
@@ -391,11 +399,11 @@ func parseCustomArgs(remoteUrl, cacheFolder, reportFileName string, customArgs .
391399}
392400
393401func runPipenvInstallFromRemoteRegistry (server * config.ServerDetails , depsRepoName string ) (err error ) {
394- rtUrl , err := utils .GetPypiRepoUrl (server , depsRepoName , false )
402+ rtUrl , err := artifactoryutils .GetPypiRepoUrl (server , depsRepoName , false )
395403 if err != nil {
396404 return err
397405 }
398- args := []string {"install" , "-d" , utils .GetPypiRemoteRegistryFlag (pythonutils .Pipenv ), rtUrl }
406+ args := []string {"install" , "-d" , artifactoryutils .GetPypiRemoteRegistryFlag (pythonutils .Pipenv ), rtUrl }
399407 _ , err = executeCommand ("pipenv" , args ... )
400408 return err
401409}
@@ -445,17 +453,17 @@ func SetPipVirtualEnvPath() (restoreEnv func() error, err error) {
445453 return
446454}
447455
448- func populatePythonDependencyTree (currNode * xrayUtils .GraphNode , dependenciesGraph map [string ][]string , uniqueDepsSet * datastructures.Set [string ]) {
456+ func populatePythonDependencyTree (currNode * clientutils .GraphNode , dependenciesGraph map [string ][]string , uniqueDepsSet * datastructures.Set [string ]) {
449457 if currNode .NodeHasLoop () {
450458 return
451459 }
452460 uniqueDepsSet .Add (currNode .Id )
453461 currDepChildren := dependenciesGraph [strings .TrimPrefix (currNode .Id , PythonPackageTypeIdentifier )]
454462 // Recursively create & append all node's dependencies.
455463 for _ , dependency := range currDepChildren {
456- childNode := & xrayUtils .GraphNode {
464+ childNode := & clientutils .GraphNode {
457465 Id : PythonPackageTypeIdentifier + dependency ,
458- Nodes : []* xrayUtils .GraphNode {},
466+ Nodes : []* clientutils .GraphNode {},
459467 Parent : currNode ,
460468 }
461469 currNode .Nodes = append (currNode .Nodes , childNode )
0 commit comments