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

Upgrade jfrog-cli-core to 2.31.1 #739

Merged
merged 8 commits into from
Apr 5, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x
- name: Static Code Analysis
uses: dominikh/staticcheck-action@v1
with:
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x
- name: Install gosec
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: Run gosec
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frogbot-scan-and-fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x

- uses: jfrog/frogbot@v2
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frogbot-scan-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x

- uses: jfrog/frogbot@v2
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x

- name: Install NuGet
uses: nuget/setup-nuget@v1
with:
nuget-version: 5.x
nuget-version: 6.x

- name: Install dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '3.x'
dotnet-version: '6.x'

- name: Go Cache
uses: actions/cache@v3
Expand All @@ -52,4 +52,4 @@ jobs:

- name: Tests
run: go test -v github.com/jfrog/jfrog-cli-core/v2/tests -timeout 0 -race

7 changes: 6 additions & 1 deletion artifactory/commands/buildinfo/addgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ func (config *BuildAddGitCommand) DoCollect(issuesConfig *IssuesConfiguration, l
if errorutils.CheckError(err) != nil {
return nil, err
}
defer os.Chdir(wd)
defer func() {
e := os.Chdir(wd)
if err == nil {
err = errorutils.CheckError(e)
}
}()
err = os.Chdir(config.dotGitPath)
if errorutils.CheckError(err) != nil {
return nil, err
Expand Down
45 changes: 34 additions & 11 deletions artifactory/commands/generic/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (dc *DownloadCommand) Run() error {
return dc.download()
}

func (dc *DownloadCommand) download() error {
func (dc *DownloadCommand) download() (err error) {
// Init progress bar if needed
if dc.progress != nil {
dc.progress.InitProgressReaders()
Expand All @@ -79,11 +79,12 @@ func (dc *DownloadCommand) download() error {
return err
}
if toCollect && !dc.DryRun() {
buildName, err := dc.buildConfiguration.GetBuildName()
var buildName, buildNumber string
buildName, err = dc.buildConfiguration.GetBuildName()
if err != nil {
return err
}
buildNumber, err := dc.buildConfiguration.GetBuildNumber()
buildNumber, err = dc.buildConfiguration.GetBuildNumber()
if err != nil {
return err
}
Expand All @@ -95,8 +96,9 @@ func (dc *DownloadCommand) download() error {
var errorOccurred = false
var downloadParamsArray []services.DownloadParams
// Create DownloadParams for all File-Spec groups.
var downParams services.DownloadParams
for i := 0; i < len(dc.Spec().Files); i++ {
downParams, err := getDownloadParams(dc.Spec().Get(i), dc.configuration)
downParams, err = getDownloadParams(dc.Spec().Get(i), dc.configuration)
if err != nil {
errorOccurred = true
log.Error(err)
Expand All @@ -116,13 +118,23 @@ func (dc *DownloadCommand) download() error {
log.Error(err)
}
if summary != nil {
defer summary.ArtifactsDetailsReader.Close()
defer func() {
e := summary.ArtifactsDetailsReader.Close()
if err == nil {
err = e
}
}()
// If 'detailed summary' was requested, then the reader should not be closed here.
// It will be closed after it will be used to generate the summary.
if dc.DetailedSummary() {
dc.result.SetReader(summary.TransferDetailsReader)
} else {
defer summary.TransferDetailsReader.Close()
defer func() {
e := summary.TransferDetailsReader.Close()
if err == nil {
err = e
}
}()
}
totalDownloaded = summary.TotalSucceeded
totalFailed = summary.TotalFailed
Expand All @@ -145,14 +157,21 @@ func (dc *DownloadCommand) download() error {
dc.result.SetFailCount(0)
return err
} else if dc.SyncDeletesPath() != "" {
absSyncDeletesPath, err := filepath.Abs(dc.SyncDeletesPath())
var absSyncDeletesPath string
absSyncDeletesPath, err = filepath.Abs(dc.SyncDeletesPath())
if err != nil {
return errorutils.CheckError(err)
}
if _, err = os.Stat(absSyncDeletesPath); err == nil {
// Unmarshal the local paths of the downloaded files from the results file reader
tmpRoot, err := createDownloadResultEmptyTmpReflection(summary.TransferDetailsReader)
defer fileutils.RemoveTempDir(tmpRoot)
var tmpRoot string
tmpRoot, err = createDownloadResultEmptyTmpReflection(summary.TransferDetailsReader)
defer func() {
e := fileutils.RemoveTempDir(tmpRoot)
if err == nil {
err = e
}
}()
if err != nil {
return err
}
Expand All @@ -169,11 +188,12 @@ func (dc *DownloadCommand) download() error {

// Build Info
if toCollect {
buildName, err := dc.buildConfiguration.GetBuildName()
var buildName, buildNumber string
buildName, err = dc.buildConfiguration.GetBuildName()
if err != nil {
return err
}
buildNumber, err := dc.buildConfiguration.GetBuildNumber()
buildNumber, err = dc.buildConfiguration.GetBuildNumber()
if err != nil {
return err
}
Expand Down Expand Up @@ -296,6 +316,9 @@ func createLegalPath(root, path string) string {

func createSyncDeletesWalkFunction(tempRoot string) gofrog.WalkFunc {
return func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Convert path to absolute path
path, err = filepath.Abs(path)
if errorutils.CheckError(err) != nil {
Expand Down
4 changes: 3 additions & 1 deletion artifactory/commands/golang/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func archiveProject(writer io.Writer, dir, mod, version string) error {
var files []File

err := filepath.Walk(dir, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(dir, filePath)
if err != nil {
return err
Expand Down Expand Up @@ -131,7 +134,6 @@ func archiveProject(writer io.Writer, dir, mod, version string) error {
if goModInfo, err := os.Lstat(filepath.Join(filePath, "go.mod")); err == nil && !goModInfo.IsDir() {
return filepath.SkipDir
}
return nil
}
if info.Mode().IsRegular() {
if !isVendoredPackage(slashPath) {
Expand Down
2 changes: 1 addition & 1 deletion artifactory/commands/gradle/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (gc *GradleCommand) SetServerDetails(serverDetails *config.ServerDetails) *

func (gc *GradleCommand) init() (vConfig *viper.Viper, err error) {
// Read config
vConfig, err = utils.ReadGradleConfig(gc.configPath, nil)
vConfig, err = utils.ReadConfigFile(gc.configPath, utils.YAML)
if err != nil {
return
}
Expand Down
5 changes: 1 addition & 4 deletions artifactory/commands/utils/remoteurlchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import (
type RemoteUrlCheckStatus string

const (
longPropertyCheckName = "Remote repositories URL connectivity"
success RemoteUrlCheckStatus = "SUCCESS"
inProgress RemoteUrlCheckStatus = "IN_PROGRESS"

longPropertyCheckName = "Remote repositories URL connectivity"
remoteUrlCheckPollingTimeout = 30 * time.Minute
remoteUrlCheckPollingInterval = 5 * time.Second
remoteUrlCheckRetries = 3
Expand Down
13 changes: 13 additions & 0 deletions artifactory/commands/utils/transferconfigbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
Expand Down Expand Up @@ -73,10 +74,22 @@ func (tcb *TransferConfigBase) ValidateMinVersionAndDifferentServers() (string,
if err != nil {
return "", err
}
targetArtifactoryVersion, err := tcb.TargetArtifactoryManager.GetVersion()
if err != nil {
return "", err
}

// Validate minimal Artifactory version in the source server
err = coreutils.ValidateMinimumVersion(coreutils.Artifactory, sourceArtifactoryVersion, minTransferConfigArtifactoryVersion)
if err != nil {
return "", err
}

// Validate that the target Artifactory server version is >= than the source Artifactory server version
if !version.NewVersion(targetArtifactoryVersion).AtLeast(sourceArtifactoryVersion) {
return "", errorutils.CheckErrorf("The source Artifactory version (%s) can't be higher than the target Artifactory version (%s).", sourceArtifactoryVersion, targetArtifactoryVersion)
}

// Avoid exporting and importing to the same server
log.Info("Verifying source and target servers are different...")
if tcb.SourceServerDetails.GetArtifactoryUrl() == tcb.TargetServerDetails.GetArtifactoryUrl() {
Expand Down
58 changes: 41 additions & 17 deletions artifactory/commands/utils/transferconfigbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,55 @@ func TestIsDefaultCredentialsLocked(t *testing.T) {
assert.Equal(t, 0, unlockCounter)
}

var validateMinVersionAndDifferentServersCases = []struct {
testName string
sourceVersion string
targetVersion string
expectedError string
}{
{testName: "Same version", sourceVersion: minTransferConfigArtifactoryVersion, targetVersion: minTransferConfigArtifactoryVersion, expectedError: ""},
{testName: "Different versions", sourceVersion: "7.0.0", targetVersion: "7.0.1", expectedError: ""},
{testName: "Low Artifactory version", sourceVersion: "6.0.0", targetVersion: "7.0.0", expectedError: "while this operation requires version"},
{testName: "Source newer than target", sourceVersion: "7.0.1", targetVersion: "7.0.0", expectedError: "can't be higher than the target Artifactory version"},
}

func TestValidateMinVersionAndDifferentServers(t *testing.T) {
var rtVersion string
var sourceRtVersion, targetRtVersion string
// Create transfer config command
testServer, serverDetails, _ := commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) {
content, err := json.Marshal(VersionResponse{Version: rtVersion})
sourceTestServer, sourceServerDetails, _ := commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, _ *http.Request) {
content, err := json.Marshal(VersionResponse{Version: sourceRtVersion})
assert.NoError(t, err)
_, err = w.Write(content)
assert.NoError(t, err)
})
defer testServer.Close()

// Test low Artifactory version
rtVersion = "6.0.0"
_, err := createTransferConfigBase(t, serverDetails, serverDetails).ValidateMinVersionAndDifferentServers()
assert.ErrorContains(t, err, "while this operation requires version")
defer sourceTestServer.Close()
targetTestServer, targetServerDetails, _ := commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, _ *http.Request) {
content, err := json.Marshal(VersionResponse{Version: targetRtVersion})
assert.NoError(t, err)
_, err = w.Write(content)
assert.NoError(t, err)
})
defer targetTestServer.Close()

// Test same source and target Artifactory servers
rtVersion = minTransferConfigArtifactoryVersion
_, err = createTransferConfigBase(t, serverDetails, serverDetails).ValidateMinVersionAndDifferentServers()
assert.ErrorContains(t, err, "The source and target Artifactory servers are identical, but should be different.")
for _, testCase := range validateMinVersionAndDifferentServersCases {
t.Run(testCase.testName, func(t *testing.T) {
sourceRtVersion = testCase.sourceVersion
targetRtVersion = testCase.targetVersion
actualSourceVersion, err := createTransferConfigBase(t, sourceServerDetails, targetServerDetails).ValidateMinVersionAndDifferentServers()
if testCase.expectedError == "" {
assert.NoError(t, err)
assert.Equal(t, testCase.sourceVersion, actualSourceVersion)
} else {
assert.ErrorContains(t, err, testCase.expectedError)
}
})
}

// Positive test
actualVersion, err := createTransferConfigBase(t, serverDetails, &config.ServerDetails{ArtifactoryUrl: "some-different-url"}).ValidateMinVersionAndDifferentServers()
assert.NoError(t, err)
assert.Equal(t, rtVersion, actualVersion)
t.Run("Same source and target servers", func(t *testing.T) {
sourceRtVersion = minTransferConfigArtifactoryVersion
_, err := createTransferConfigBase(t, sourceServerDetails, sourceServerDetails).ValidateMinVersionAndDifferentServers()
assert.ErrorContains(t, err, "The source and target Artifactory servers are identical, but should be different.")
})
}

func TestGetSelectedRepositories(t *testing.T) {
Expand Down
9 changes: 0 additions & 9 deletions artifactory/utils/buildinfoproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ func ReadConfigFile(configPath string, configType ConfigType) (config *viper.Vip
return config, errorutils.CheckError(err)
}

func ReadGradleConfig(path string, gradleConfigParams map[string]any) (config *viper.Viper, err error) {
if path == "" {
config = createDefaultConfigWithParams(YAML, Gradle.String(), gradleConfigParams)
} else {
config, err = ReadConfigFile(path, YAML)
}
return
}

func ReadMavenConfig(path string, mvnProps map[string]any) (config *viper.Viper, err error) {
if path == "" {
config = createDefaultConfigWithParams(YAML, Maven.String(), mvnProps)
Expand Down
Loading