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

Support pip for curation #1155

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion artifactory/commands/python/poetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (pc *PoetryCommand) SetCommandName(commandName string) *PoetryCommand {
}

func (pc *PoetryCommand) SetPypiRepoUrlWithCredentials() error {
rtUrl, username, password, err := python.GetPypiRepoUrlWithCredentials(pc.serverDetails, pc.repository)
rtUrl, username, password, err := python.GetPypiRepoUrlWithCredentials(pc.serverDetails, pc.repository, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion artifactory/commands/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (pc *PythonCommand) SetCommandName(commandName string) *PythonCommand {
}

func (pc *PythonCommand) SetPypiRepoUrlWithCredentials() error {
rtUrl, err := python.GetPypiRepoUrl(pc.serverDetails, pc.repository)
rtUrl, err := python.GetPypiRepoUrl(pc.serverDetails, pc.repository, false)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions utils/coreutils/coreconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
JfrogTransferStateFileName = "state.json"
PluginsExecDirName = "bin"
PluginsResourcesDirName = "resources"
//#nosec G101
CurationPassThroughApi = "api/curation/audit/"

//#nosec G101
ErrorHandling = "JFROG_CLI_ERROR_HANDLING"
Expand Down
11 changes: 8 additions & 3 deletions utils/python/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"net/url"
"os"
"path/filepath"
Expand All @@ -25,7 +26,7 @@ const (
pyproject = "pyproject.toml"
)

func GetPypiRepoUrlWithCredentials(serverDetails *config.ServerDetails, repository string) (*url.URL, string, string, error) {
func GetPypiRepoUrlWithCredentials(serverDetails *config.ServerDetails, repository string, isCurationCmd bool) (*url.URL, string, string, error) {
rtUrl, err := url.Parse(serverDetails.GetArtifactoryUrl())
if err != nil {
return nil, "", "", errorutils.CheckError(err)
Expand All @@ -41,6 +42,10 @@ func GetPypiRepoUrlWithCredentials(serverDetails *config.ServerDetails, reposito
}
password = serverDetails.GetAccessToken()
}
// In case of curation command, the download urls should be routed through a dedicated api.
if isCurationCmd {
rtUrl.Path += coreutils.CurationPassThroughApi
}
rtUrl.Path += "api/pypi/" + repository + "/simple"
return rtUrl, username, password, err
}
Expand All @@ -52,8 +57,8 @@ func GetPypiRemoteRegistryFlag(tool pythonutils.PythonTool) string {
return pipenvRemoteRegistryFlag
}

func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string) (string, error) {
rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(serverDetails, repository)
func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string, isCurationCmd bool) (string, error) {
rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(serverDetails, repository, isCurationCmd)
if err != nil {
return "", err
}
Expand Down
28 changes: 28 additions & 0 deletions utils/python/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package utils

import (
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/stretchr/testify/require"
"path/filepath"
"strings"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
Expand Down Expand Up @@ -31,3 +35,27 @@ func initPoetryTest(t *testing.T) (string, func()) {
poetryProjectPath, cleanUp := tests.CreateTestWorkspace(t, testAbs)
return poetryProjectPath, cleanUp
}

func TestGetPypiRepoUrlWithCredentials(t *testing.T) {
tests := []struct {
name string
curationCmd bool
}{
{
name: "test curation command true",
curationCmd: true,
},
{
name: "test curation command false",
curationCmd: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
url, _, _, err := GetPypiRepoUrlWithCredentials(&config.ServerDetails{}, "test", tt.curationCmd)
require.NoError(t, err)
assert.Equal(t, tt.curationCmd, strings.Contains(url.Path, coreutils.CurationPassThroughApi))
})
}
}
Loading