Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Apr 15, 2024
2 parents a063de8 + d0547c3 commit 670986e
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 24 deletions.
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
34 changes: 30 additions & 4 deletions artifactory/utils/npm/pack.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package npm

import (
"fmt"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"strings"

gofrogcmd "github.com/jfrog/gofrog/io"
npmutils "github.com/jfrog/jfrog-cli-core/v2/utils/npm"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
)

const (
npmPackedTarballSuffix = ".tgz"
)

func Pack(npmFlags []string, executablePath string) ([]string, error) {
configListCmdConfig := createPackCmdConfig(executablePath, npmFlags)
output, err := gofrogcmd.RunCmdOutput(configListCmdConfig)
if err != nil {
return []string{}, errorutils.CheckError(err)
}
return getPackageFileNameFromOutput(output), nil
return getPackageFileNameFromOutput(output)
}

func createPackCmdConfig(executablePath string, splitFlags []string) *npmutils.NpmConfig {
Expand All @@ -27,7 +33,27 @@ func createPackCmdConfig(executablePath string, splitFlags []string) *npmutils.N
}
}

func getPackageFileNameFromOutput(output string) []string {
output = strings.TrimSpace(output)
return strings.Split(output, "\n")
// Extracts packed file names from npm pack command output
// The output can differ when a prePack script exists,
// This function will filter the output and search for the .tgz files
// To avoid misidentifying files, we will verify file exists
func getPackageFileNameFromOutput(output string) (packedTgzFiles []string, err error) {
lines := strings.Split(output, "\n")
var packedFileNamesFromOutput []string
for _, line := range lines {
line = strings.TrimSpace(line)
if strings.HasSuffix(line, npmPackedTarballSuffix) {
packedFileNamesFromOutput = append(packedFileNamesFromOutput, line)
}
}
for _, file := range packedFileNamesFromOutput {
exists, err := fileutils.IsFileExists(file, true)
if err != nil {
return nil, fmt.Errorf("error occurred while checking packed npm tarball exists: %w", err)
}
if exists {
packedTgzFiles = append(packedTgzFiles, file)
}
}
return
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/google/uuid v1.6.0
github.com/gookit/color v1.5.4
github.com/jedib0t/go-pretty/v6 v6.5.6
github.com/jfrog/build-info-go v1.9.25
github.com/jfrog/gofrog v1.6.3
github.com/jfrog/jfrog-client-go v1.39.0
github.com/jfrog/build-info-go v1.9.26
github.com/jfrog/gofrog v1.7.1
github.com/jfrog/jfrog-client-go v1.40.1
github.com/magiconair/properties v1.8.7
github.com/manifoldco/promptui v0.9.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
Expand Down Expand Up @@ -96,8 +96,8 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240327154209-77a304635e42
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240408071430-62ee0279ac58

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240319160313-0093dee91fc1
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go dev

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ github.com/jedib0t/go-pretty/v6 v6.5.6 h1:nKXVLqPfAwY7sWcYXdNZZZ2fjqDpAtj9UeWupg
github.com/jedib0t/go-pretty/v6 v6.5.6/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg=
github.com/jfrog/archiver/v3 v3.6.0 h1:OVZ50vudkIQmKMgA8mmFF9S0gA47lcag22N13iV3F1w=
github.com/jfrog/archiver/v3 v3.6.0/go.mod h1:fCAof46C3rAXgZurS8kNRNdSVMKBbZs+bNNhPYxLldI=
github.com/jfrog/build-info-go v1.9.25 h1:IkjydGQA/HjOWjRaoKq1hOEgCCyBEJwQgXJSo4WVBSA=
github.com/jfrog/build-info-go v1.9.25/go.mod h1:doFB4bFDVHeGulD6GF9LzsrRaIOrSoklV9DgIAEqHgc=
github.com/jfrog/gofrog v1.6.3 h1:F7He0+75HcgCe6SGTSHLFCBDxiE2Ja0tekvvcktW6wc=
github.com/jfrog/gofrog v1.6.3/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg=
github.com/jfrog/jfrog-client-go v1.39.0 h1:GZ1qbpUDzYz8ZEycYicDkbVMN2H0VSCuz8mUNTyf7tc=
github.com/jfrog/jfrog-client-go v1.39.0/go.mod h1:tUyEmxznphh0nwAGo6xz9Sps7RRW/TBMxIJZteo+j2k=
github.com/jfrog/build-info-go v1.9.26 h1:1Ddc6+Ecvhc+UMnKhRVG1jGM6fYNwA49207azTBGBc8=
github.com/jfrog/build-info-go v1.9.26/go.mod h1:8T7/ajM9aGshvgpwCtXwIFpyF/R6CEn4W+/FLryNXWw=
github.com/jfrog/gofrog v1.7.1 h1:ME1Meg4hukAT/7X6HUQCVSe4DNjMZACCP8aCY37EW/w=
github.com/jfrog/gofrog v1.7.1/go.mod h1:X7bjfWoQDN0Z4FQGbE91j3gbPP7Urwzm4Z8tkvrlbRI=
github.com/jfrog/jfrog-client-go v1.40.1 h1:ISSSV7/IUS8R+QCPfH2lVKLburbv2Xn07fvNyDc17rI=
github.com/jfrog/jfrog-client-go v1.40.1/go.mod h1:FprEW0Sqhj6ZSFTFk9NCni+ovFAYMA3zCBmNX4hGXgQ=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand Down
60 changes: 60 additions & 0 deletions lifecycle/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package lifecycle

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)

type ReleaseBundleImportCommand struct {
releaseBundleCmd
filePath string
}

func (rbi *ReleaseBundleImportCommand) ServerDetails() (*config.ServerDetails, error) {
return rbi.serverDetails, nil
}

func (rbi *ReleaseBundleImportCommand) CommandName() string {
return "rb_import"
}

func NewReleaseBundleImportCommand() *ReleaseBundleImportCommand {
return &ReleaseBundleImportCommand{}
}
func (rbi *ReleaseBundleImportCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReleaseBundleImportCommand {
rbi.serverDetails = serverDetails
return rbi
}

func (rbi *ReleaseBundleImportCommand) SetFilepath(filePath string) *ReleaseBundleImportCommand {
rbi.filePath = filePath
return rbi
}

func (rbi *ReleaseBundleImportCommand) Run() (err error) {
if err = validateArtifactoryVersionSupported(rbi.serverDetails); err != nil {
return
}
artService, err := utils.CreateServiceManager(rbi.serverDetails, 3, 0, false)
if err != nil {
return
}

exists, err := fileutils.IsFileExists(rbi.filePath, false)
if err != nil {
return
}
if !exists {
return fmt.Errorf("file not found: %s", rbi.filePath)
}

log.Info("Importing the release bundle archive...")
if err = artService.ImportReleaseBundle(rbi.filePath); err != nil {
return
}
log.Info("Successfully imported the release bundle archive")
return
}
4 changes: 2 additions & 2 deletions plugins/components/conversionlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ConvertApp(jfrogApp App) (*cli.App, error) {
app.Name = jfrogApp.Name
app.Description = jfrogApp.Description
app.Version = jfrogApp.Version
app.Commands, err = ConvertAppCommands(jfrogApp, jfrogApp.Name)
app.Commands, err = ConvertAppCommands(jfrogApp)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func createCommandUsages(cmd Command, convertedStringFlags map[string]StringFlag
}

func getCmdUsageString(cmd Command, namespaces ...string) string {
return coreutils.GetCliExecutableName() + " " + strings.Join(append(removeEmptyValues(namespaces), cmd.Name), " ")
return strings.Join(append(removeEmptyValues(namespaces), cmd.Name), " ")
}

// Generated usages are based on the command's flags and arguments:
Expand Down
2 changes: 1 addition & 1 deletion plugins/components/conversionlayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestCreateCommandUsages(t *testing.T) {
appNameSpace := "test-app"
cmdName := "test-command"
expectedPrefix := fmt.Sprintf("%s %s %s", coreutils.GetCliExecutableName(), appNameSpace, cmdName)
expectedPrefix := fmt.Sprintf("%s %s", appNameSpace, cmdName)

optFlag := NewBoolFlag("dummyFlag", "")
optStrFlag := NewStringFlag("optFlag", "", WithHelpValue("alias"))
Expand Down
3 changes: 2 additions & 1 deletion tests/testdata/npm-workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepack": "echo 'prepack script executed'"
},
"keywords": [],
"author": "",
Expand Down
15 changes: 15 additions & 0 deletions utils/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
xrayAuth "github.com/jfrog/jfrog-client-go/xray/auth"
xscAuth "github.com/jfrog/jfrog-client-go/xsc/auth"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -572,6 +573,7 @@ type ServerDetails struct {
ArtifactoryUrl string `json:"artifactoryUrl,omitempty"`
DistributionUrl string `json:"distributionUrl,omitempty"`
XrayUrl string `json:"xrayUrl,omitempty"`
XscUrl string `json:"xscUrl,omitempty"`
MissionControlUrl string `json:"missionControlUrl,omitempty"`
PipelinesUrl string `json:"pipelinesUrl,omitempty"`
AccessUrl string `json:"accessUrl,omitempty"`
Expand Down Expand Up @@ -708,6 +710,19 @@ func (serverDetails *ServerDetails) CreateXrayAuthConfig() (auth.ServiceDetails,
return serverDetails.createAuthConfig(artAuth)
}

func (serverDetails *ServerDetails) CreateXscAuthConfig() (auth.ServiceDetails, error) {
ascAuth := xscAuth.NewXscDetails()
ascAuth.SetUrl(serverDetails.convertXrayUrlToXscUrl())
return serverDetails.createAuthConfig(ascAuth)
}

// Xray and Xsc will always have the same platform url.
func (serverDetails *ServerDetails) convertXrayUrlToXscUrl() string {
xscUrl := strings.TrimSuffix(serverDetails.XrayUrl, "/")
xscUrl = strings.TrimSuffix(xscUrl, "/xray")
return xscUrl + "/xsc/"
}

func (serverDetails *ServerDetails) CreatePipelinesAuthConfig() (auth.ServiceDetails, error) {
pAuth := pipelinesAuth.NewPipelinesDetails()
pAuth.SetUrl(serverDetails.PipelinesUrl)
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))
})
}
}

0 comments on commit 670986e

Please sign in to comment.