Skip to content

Commit

Permalink
copy dir
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Sep 9, 2023
1 parent fadddc4 commit 00f1232
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion artifactory/commands/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions utils/python/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 13 additions & 15 deletions xray/commands/audit/sca/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 .'
Expand All @@ -197,25 +202,18 @@ func getPipInstallArgs(requirementsFile string) []string {
// Run pip 'install -r requirements <requirementsFile>'
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) {
rtUrl, err := utils.GetPypiRepoUrl(server, depsRepoName)
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...)
}

Expand Down

0 comments on commit 00f1232

Please sign in to comment.