From 00f1232cdd039e79420272974c6c8510f588bd50 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sat, 9 Sep 2023 15:20:42 +0300 Subject: [PATCH] copy dir Signed-off-by: Michael Sverdlov --- artifactory/commands/python/python.go | 2 +- utils/python/utils.go | 6 ++--- xray/commands/audit/sca/python/python.go | 28 +++++++++++------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/artifactory/commands/python/python.go b/artifactory/commands/python/python.go index 8d1afeea6..8a32a689c 100644 --- a/artifactory/commands/python/python.go +++ b/artifactory/commands/python/python.go @@ -106,7 +106,7 @@ func (pc *PythonCommand) SetPypiRepoUrlWithCredentials() error { if err != nil { return err } - pc.args = append(pc.args, python.GetPypiRemoteRegistryFlag(pc.pythonTool), rtUrl.String()) + pc.args = append(pc.args, python.GetPypiRemoteRegistryFlag(pc.pythonTool), rtUrl) return nil } diff --git a/utils/python/utils.go b/utils/python/utils.go index d5057b894..c44c0385a 100644 --- a/utils/python/utils.go +++ b/utils/python/utils.go @@ -51,15 +51,15 @@ func GetPypiRemoteRegistryFlag(tool pythonutils.PythonTool) string { return pipenvRemoteRegistryFlag } -func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string) (*url.URL, error) { +func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string) (string, error) { rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(serverDetails, repository) if err != nil { - return nil, err + return "", err } if password != "" { rtUrl.User = url.UserPassword(username, password) } - return rtUrl, err + return rtUrl.String(), err } func ConfigPoetryRepo(url, username, password, configRepoName string) error { diff --git a/xray/commands/audit/sca/python/python.go b/xray/commands/audit/sca/python/python.go index ae7c660fc..49ce608e7 100644 --- a/xray/commands/audit/sca/python/python.go +++ b/xray/commands/audit/sca/python/python.go @@ -158,14 +158,19 @@ func installPipDeps(auditPython *AuditPython) (restoreEnv func() error, err erro if err != nil { return } + + remoteUrl := "" if auditPython.RemotePypiRepo != "" { - return restoreEnv, runPipInstallFromRemoteRegistry(auditPython.Server, auditPython.RemotePypiRepo, auditPython.PipRequirementsFile) + remoteUrl, err = utils.GetPypiRepoUrl(auditPython.Server, auditPython.RemotePypiRepo) + if err != nil { + return + } } - pipInstallArgs := getPipInstallArgs(auditPython.PipRequirementsFile) + pipInstallArgs := getPipInstallArgs(auditPython.PipRequirementsFile, remoteUrl) err = executeCommand("python", pipInstallArgs...) if err != nil && auditPython.PipRequirementsFile == "" { log.Debug(err.Error() + "\nTrying to install using a requirements file...") - pipInstallArgs = getPipInstallArgs("requirements.txt") + pipInstallArgs = getPipInstallArgs("requirements.txt", remoteUrl) reqErr := executeCommand("python", pipInstallArgs...) if reqErr != nil { // Return Pip install error and log the requirements fallback error. @@ -188,7 +193,7 @@ func executeCommand(executable string, args ...string) error { return nil } -func getPipInstallArgs(requirementsFile string) []string { +func getPipInstallArgs(requirementsFile, remoteUrl string) []string { args := []string{"-m", "pip", "install"} if requirementsFile == "" { // Run 'pip install .' @@ -197,17 +202,10 @@ func getPipInstallArgs(requirementsFile string) []string { // Run pip 'install -r requirements ' args = append(args, "-r", requirementsFile) } - return args -} - -func runPipInstallFromRemoteRegistry(server *config.ServerDetails, depsRepoName, pipRequirementsFile string) (err error) { - rtUrl, err := utils.GetPypiRepoUrl(server, depsRepoName) - if err != nil { - return err + if remoteUrl != "" { + args = append(args, utils.GetPypiRemoteRegistryFlag(pythonutils.Pip), remoteUrl) } - args := getPipInstallArgs(pipRequirementsFile) - args = append(args, utils.GetPypiRemoteRegistryFlag(pythonutils.Pip), rtUrl.String()) - return executeCommand("python", args...) + return args } func runPipenvInstallFromRemoteRegistry(server *config.ServerDetails, depsRepoName string) (err error) { @@ -215,7 +213,7 @@ func runPipenvInstallFromRemoteRegistry(server *config.ServerDetails, depsRepoNa if err != nil { return err } - args := []string{"install", "-d", utils.GetPypiRemoteRegistryFlag(pythonutils.Pipenv), rtUrl.String()} + args := []string{"install", "-d", utils.GetPypiRemoteRegistryFlag(pythonutils.Pipenv), rtUrl} return executeCommand("pipenv", args...) }