From 6fa5830db0fed127bff7f184e3f03c858df89f45 Mon Sep 17 00:00:00 2001 From: Oshrat Zairi <159787052+oshratZairi@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:41:12 +0200 Subject: [PATCH 1/3] Make the signing key optinal `jf release-bundle-create` (#2762) --- lifecycle/cli.go | 15 ------- lifecycle/cli_test.go | 4 +- lifecycle_test.go | 71 ++++++++++++++++++++------------- utils/cliutils/commandsflags.go | 2 +- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lifecycle/cli.go b/lifecycle/cli.go index b47731934..da6c3d7d7 100644 --- a/lifecycle/cli.go +++ b/lifecycle/cli.go @@ -127,10 +127,6 @@ func validateCreateReleaseBundleContext(c *cli.Context) error { return cliutils.WrongNumberOfArgumentsHandler(c) } - if err := assertSigningKeyProvided(c); err != nil { - return err - } - return assertValidCreationMethod(c) } @@ -188,10 +184,6 @@ func promote(c *cli.Context) error { return cliutils.WrongNumberOfArgumentsHandler(c) } - if err := assertSigningKeyProvided(c); err != nil { - return err - } - lcDetails, err := createLifecycleDetailsByFlags(c) if err != nil { return err @@ -358,13 +350,6 @@ func validateDistributeCommand(c *cli.Context) error { return nil } -func assertSigningKeyProvided(c *cli.Context) error { - if c.String(cliutils.SigningKey) == "" { - return errorutils.CheckErrorf("the --%s option is mandatory", cliutils.SigningKey) - } - return nil -} - func createLifecycleDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) { lcDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, commonCliUtils.Platform) if err != nil { diff --git a/lifecycle/cli_test.go b/lifecycle/cli_test.go index 65b911958..8f5aefe8b 100644 --- a/lifecycle/cli_test.go +++ b/lifecycle/cli_test.go @@ -21,10 +21,10 @@ func TestValidateCreateReleaseBundleContext(t *testing.T) { {"extraArgs", []string{"one", "two", "three", "four"}, []string{}, true}, {"bothSources", []string{"one", "two", "three"}, []string{cliutils.Builds + "=/path/to/file", cliutils.ReleaseBundles + "=/path/to/file"}, true}, {"noSources", []string{"one", "two", "three"}, []string{}, true}, - {"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, true}, + {"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, false}, {"builds correct", []string{"name", "version"}, []string{ cliutils.Builds + "=/path/to/file", cliutils.SigningKey + "=key"}, false}, - {"releaseBundles without signing key", []string{"name", "version", "env"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, true}, + {"releaseBundles without signing key", []string{"name", "version"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, false}, {"releaseBundles correct", []string{"name", "version"}, []string{ cliutils.ReleaseBundles + "=/path/to/file", cliutils.SigningKey + "=key"}, false}, {"spec without signing key", []string{"name", "version", "env"}, []string{"spec=/path/to/file"}, true}, diff --git a/lifecycle_test.go b/lifecycle_test.go index 455f035d8..ac66bcec5 100644 --- a/lifecycle_test.go +++ b/lifecycle_test.go @@ -29,14 +29,16 @@ import ( ) const ( - artifactoryLifecycleMinVersion = "7.68.3" - gpgKeyPairName = "lc-tests-key-pair" - lcTestdataPath = "lifecycle" - releaseBundlesSpec = "release-bundles-spec.json" - buildsSpec12 = "builds-spec-1-2.json" - buildsSpec3 = "builds-spec-3.json" - prodEnvironment = "PROD" - number1, number2, number3 = "111", "222", "333" + artifactoryLifecycleMinVersion = "7.68.3" + signingKeyOptionalArtifactoryMinVersion = "7.101.1" + gpgKeyPairName = "lc-tests-key-pair" + lcTestdataPath = "lifecycle" + releaseBundlesSpec = "release-bundles-spec.json" + buildsSpec12 = "builds-spec-1-2.json" + buildsSpec3 = "builds-spec-3.json" + prodEnvironment = "PROD" + number1, number2, number3 = "111", "222", "333" + withoutSigningKey = true ) var ( @@ -45,7 +47,7 @@ var ( ) func TestBackwardCompatibleReleaseBundleCreation(t *testing.T) { - cleanCallback := initLifecycleTest(t) + cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion) defer cleanCallback() lcManager := getLcServiceManager(t) @@ -87,30 +89,39 @@ func compareRbArtifacts(t *testing.T, actual services.ReleaseBundleSpecResponse, } func TestReleaseBundleCreationFromAql(t *testing.T) { - testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql()) + testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql(), false) } func TestReleaseBundleCreationFromArtifacts(t *testing.T) { - testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts()) + testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), false) } -func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string) { - cleanCallback := initLifecycleTest(t) - defer cleanCallback() - lcManager := getLcServiceManager(t) +func TestReleaseBundleCreationFromArtifactsWithoutSigningKey(t *testing.T) { + testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), withoutSigningKey) +} + +func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string, withoutSigningKey bool) { + if withoutSigningKey { + cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion) + defer cleanCallback() + } else { + cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion) + defer cleanCallback() + } + lcManager := getLcServiceManager(t) specFile, err := tests.CreateSpec(uploadSpec) assert.NoError(t, err) runRt(t, "upload", "--spec="+specFile) - createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true) + createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true, withoutSigningKey) defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1) assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, expected) } func TestLifecycleFullFlow(t *testing.T) { - cleanCallback := initLifecycleTest(t) + cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion) defer cleanCallback() lcManager := getLcServiceManager(t) @@ -119,17 +130,17 @@ func TestLifecycleFullFlow(t *testing.T) { defer deleteBuilds() // Create release bundle from builds synchronously. - createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true) + createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true, false) defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1) // Create release bundle from a build asynchronously and assert status. // This build has dependencies which are included in the release bundle. - createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false) + createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false, false) defer deleteReleaseBundle(t, lcManager, tests.LcRbName2, number2) assertStatusCompleted(t, lcManager, tests.LcRbName2, number2, "") // Create a combined release bundle from the two previous release bundle. - createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true) + createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true, false) defer deleteReleaseBundle(t, lcManager, tests.LcRbName3, number3) // Promote the last release bundle to prod repo 1. @@ -161,7 +172,7 @@ func TestLifecycleFullFlow(t *testing.T) { // Import bundles only work on onPerm platforms func TestImportReleaseBundle(t *testing.T) { - cleanCallback := initLifecycleTest(t) + cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion) defer cleanCallback() wd, err := os.Getwd() assert.NoError(t, err) @@ -195,22 +206,25 @@ func uploadBuilds(t *testing.T) func() { func createRbBackwardCompatible(t *testing.T, specName, sourceOption, rbName, rbVersion string, sync bool) { specFile, err := getSpecFile(specName) assert.NoError(t, err) - createRb(t, specFile, sourceOption, rbName, rbVersion, sync) + createRb(t, specFile, sourceOption, rbName, rbVersion, sync, false) } -func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool) { +func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool, withoutSigningKey bool) { specFile, err := tests.CreateSpec(specName) assert.NoError(t, err) - createRb(t, specFile, "spec", rbName, rbVersion, sync) + createRb(t, specFile, "spec", rbName, rbVersion, sync, withoutSigningKey) } -func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool) { +func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool, withoutSigningKey bool) { argsAndOptions := []string{ "rbc", rbName, rbVersion, getOption(sourceOption, specFilePath), - getOption(cliutils.SigningKey, gpgKeyPairName), + } + + if !withoutSigningKey { + argsAndOptions = append(argsAndOptions, getOption(cliutils.SigningKey, gpgKeyPairName)) } // Add the --sync option only if requested, to test the default value. if sync { @@ -363,11 +377,12 @@ func uploadBuildWithDeps(t *testing.T, buildName, buildNumber string) { runRt(t, "build-publish", buildName, buildNumber) } -func initLifecycleTest(t *testing.T) (cleanCallback func()) { +func initLifecycleTest(t *testing.T, minVersion string) (cleanCallback func()) { if !*tests.TestLifecycle { t.Skip("Skipping lifecycle test. To run release bundle test add the '-test.lc=true' option.") } - validateArtifactoryVersion(t, artifactoryLifecycleMinVersion) + + validateArtifactoryVersion(t, minVersion) if !isLifecycleSupported(t) { t.Skip("Skipping lifecycle test because the functionality is not enabled on the provided JPD.") diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 446f84eff..0157f6c13 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -1650,7 +1650,7 @@ var flagsMap = map[string]cli.Flag{ }, lcSigningKey: cli.StringFlag{ Name: SigningKey, - Usage: "[Mandatory] The GPG/RSA key-pair name given in Artifactory.` `", + Usage: "[Optional] The GPG/RSA key-pair name given in Artifactory. If the key isn't provided, the command creates or uses the default key.` `", }, lcPathMappingPattern: cli.StringFlag{ Name: PathMappingPattern, From 18be36984d2827b4a0882b23f8fafe219ce78ea5 Mon Sep 17 00:00:00 2001 From: Eyal Delarea Date: Thu, 21 Nov 2024 20:24:29 +0200 Subject: [PATCH 2/3] `NuGet` - Allow to set `allowInsecureConnections` package source attribute (#2758) --- buildtools/cli.go | 20 ++++++-- go.mod | 6 +-- go.sum | 12 ++--- nuget_test.go | 17 +++++-- utils/cliutils/commandsflags.go | 9 +++- utils/cliutils/utils.go | 12 +++++ utils/cliutils/utils_test.go | 85 +++++++++++++++++++++++++++++++++ 7 files changed, 144 insertions(+), 17 deletions(-) diff --git a/buildtools/cli.go b/buildtools/cli.go index fa7d87993..02eee938a 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -566,9 +566,18 @@ func NugetCmd(c *cli.Context) error { return err } + allowInsecureConnection, err := cliutils.ExtractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections") + if err != nil { + return err + } + nugetCmd := dotnet.NewNugetCommand() - nugetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). - SetBasicCommand(filteredNugetArgs[0]).SetUseNugetV2(useNugetV2) + nugetCmd.SetServerDetails(rtDetails). + SetRepoName(targetRepo). + SetBuildConfiguration(buildConfiguration). + SetBasicCommand(filteredNugetArgs[0]). + SetUseNugetV2(useNugetV2). + SetAllowInsecureConnections(allowInsecureConnection) // Since we are using the values of the command's arguments and flags along the buildInfo collection process, // we want to separate the actual NuGet basic command (restore/build...) from the arguments and flags if len(filteredNugetArgs) > 1 { @@ -604,10 +613,15 @@ func DotnetCmd(c *cli.Context) error { return err } + allowInsecureConnection, err := cliutils.ExtractBoolFlagFromArgs(&filteredDotnetArgs, "allow-insecure-connections") + if err != nil { + return err + } + // Run command. dotnetCmd := dotnet.NewDotnetCoreCliCommand() dotnetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). - SetBasicCommand(filteredDotnetArgs[0]).SetUseNugetV2(useNugetV2) + SetBasicCommand(filteredDotnetArgs[0]).SetUseNugetV2(useNugetV2).SetAllowInsecureConnections(allowInsecureConnection) // Since we are using the values of the command's arguments and flags along the buildInfo collection process, // we want to separate the actual .NET basic command (restore/build...) from the arguments and flags if len(filteredDotnetArgs) > 1 { diff --git a/go.mod b/go.mod index 5791e80aa..cfab56ecb 100644 --- a/go.mod +++ b/go.mod @@ -167,12 +167,12 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241113152357-24197a744331 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 -// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.12.5-0.20241107141149-42cf964808a1 +replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7 -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240918150101-ad5b10435a12 +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev diff --git a/go.sum b/go.sum index f3263fde9..9692db858 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= @@ -161,8 +163,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtx github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI= github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw= -github.com/jfrog/build-info-go v1.10.5 h1:cW03JlPlKv7RMUU896uLUxyLWXAmCgR5Y5QX0fwgz0Q= -github.com/jfrog/build-info-go v1.10.5/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= +github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd h1:PzxnJ1mjHIL4bAC4RPm87WnJ1TZXFBicyOhtIHRQH6g= +github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= github.com/jfrog/froggit-go v1.16.2 h1:F//S83iXH14qsCwYzv0zB2JtjS2pJVEsUoEmYA+37dQ= github.com/jfrog/froggit-go v1.16.2/go.mod h1:5VpdQfAcbuyFl9x/x8HGm7kVk719kEtW/8YJFvKcHPA= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= @@ -171,12 +173,10 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-artifactory v0.1.7 h1:/PBDO6nS6cf3PK+GRkd6BJtZnvYasi1PrQhRiayirso= github.com/jfrog/jfrog-cli-artifactory v0.1.7/go.mod h1:M5pZTHnsYNDmml/FAnoxxt4QiHOIUHPx91th30AtwfM= -github.com/jfrog/jfrog-cli-core/v2 v2.56.8 h1:UexulAwRVN20VmYACijkTFYKqtUq5myE4okEgmUrorw= -github.com/jfrog/jfrog-cli-core/v2 v2.56.8/go.mod h1:RY74eDpw1WBxruSfZ0HO1ax7c1NAj+rbBgA/hVOJNME= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 h1:cJSPTMflqE+ucC/h2/BB6BkVxz3BG8PnivCb00Dxt/Y= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs= github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc= -github.com/jfrog/jfrog-cli-security v1.12.5 h1:2JHPyapXuHQw/qEaElGxBUGrJCZlVFLXDdxkqhf10vE= -github.com/jfrog/jfrog-cli-security v1.12.5/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU= github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU= github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI= diff --git a/nuget_test.go b/nuget_test.go index e8b42d2bb..bf1235a37 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -107,6 +107,7 @@ func TestNuGetWithGlobalConfig(t *testing.T) { assert.NoError(t, err) err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) + // allow insecure connection for testings to work with localhost server testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}) cleanTestsHomeEnv() @@ -117,7 +118,10 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe assert.NoError(t, err, "Failed to get current dir") chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() + + allowInsecureConnectionForTests(&args) args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) + err = runNuGet(t, args...) if err != nil { return @@ -152,6 +156,12 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) } +// Add allow insecure connection for testings to work with localhost server +func allowInsecureConnectionForTests(args *[]string) *[]string { + *args = append(*args, "--allow-insecure-connections") + return args +} + func assertNugetDependencies(t *testing.T, module buildInfo.Module, moduleName string) { for _, dependency := range module.Dependencies { switch dependency.Id { @@ -224,10 +234,11 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR params := &dotnet.DotnetCommand{} server := &config.ServerDetails{ArtifactoryUrl: baseRtUrl, User: "user", Password: "password"} params.SetServerDetails(server). - SetUseNugetV2(testSuite.useNugetV2) - // Prepare the config file with NuGet authentication + SetUseNugetV2(testSuite.useNugetV2). + SetAllowInsecureConnections(true) - configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2) + // Prepare the config file with NuGet authentication + configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2, true) if err != nil { assert.NoError(t, err) return diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 0157f6c13..1ad558d3c 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -376,7 +376,8 @@ const ( npmDetailedSummary = npmPrefix + detailedSummary // Unique nuget/dotnet config flags - nugetV2 = "nuget-v2" + nugetV2 = "nuget-v2" + allowInsecureConnections = "allow-insecure-connections" // Unique go flags noFallback = "no-fallback" @@ -1161,6 +1162,10 @@ var flagsMap = map[string]cli.Flag{ Name: nugetV2, Usage: "[Default: false] Set to true if you'd like to use the NuGet V2 protocol when restoring packages from Artifactory.` `", }, + allowInsecureConnections: cli.BoolFlag{ + Name: allowInsecureConnections, + Usage: "[Default: false] Set to true if you wish to configure NuGet sources with unsecured connections. This is recommended for testing purposes only. ` `", + }, noFallback: cli.BoolTFlag{ Name: noFallback, Usage: "[Default: false] Set to true to avoid downloading packages from the VCS, if they are missing in Artifactory.` `", @@ -1882,7 +1887,7 @@ var commandFlags = map[string][]string{ global, serverIdResolve, repoResolve, nugetV2, }, Nuget: { - buildName, buildNumber, module, Project, + buildName, buildNumber, module, Project, allowInsecureConnections, }, DotnetConfig: { global, serverIdResolve, repoResolve, nugetV2, diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index 17781fe50..ac43b25a8 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -809,3 +809,15 @@ func getDebFlag(c *cli.Context) (deb string, err error) { } return deb, nil } + +// ExtractBoolFlagFromArgs Extracts a boolean flag from the args and removes it from the slice. +func ExtractBoolFlagFromArgs(filteredArgs *[]string, flagName string) (value bool, err error) { + var flagIndex int + var boolFlag bool + flagIndex, boolFlag, err = coreutils.FindBooleanFlag("--"+flagName, *filteredArgs) + if err != nil { + return false, err + } + coreutils.RemoveFlagFromCommand(filteredArgs, flagIndex, flagIndex) + return boolFlag, nil +} diff --git a/utils/cliutils/utils_test.go b/utils/cliutils/utils_test.go index f9bf32b2e..e67ec46c7 100644 --- a/utils/cliutils/utils_test.go +++ b/utils/cliutils/utils_test.go @@ -140,3 +140,88 @@ func TestShouldCheckLatestCliVersion(t *testing.T) { assert.NoError(t, err) assert.True(t, shouldCheck) } + +func TestExtractBoolFlagFromArgs(t *testing.T) { + testCases := []struct { + name string + args []string + flagName string + expectedValue bool + expectedErr bool + expectedArgs []string + }{ + { + name: "Flag present as --flagName (implied true)", + args: []string{"somecmd", "--flagName", "otherarg"}, + flagName: "flagName", + expectedValue: true, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present as --flagName=true", + args: []string{"somecmd", "--flagName=true", "otherarg"}, + flagName: "flagName", + expectedValue: true, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present as --flagName=false", + args: []string{"somecmd", "--flagName=false", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag not present", + args: []string{"somecmd", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present with invalid value", + args: []string{"somecmd", "--flagName=invalid", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: true, + expectedArgs: []string{"somecmd", "--flagName=invalid", "otherarg"}, + }, + { + name: "Flag present as -flagName (should not be found)", + args: []string{"somecmd", "-flagName", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "-flagName", "otherarg"}, + }, + { + name: "Flag present multiple times", + args: []string{"somecmd", "--flagName", "--flagName=false", "otherarg"}, + flagName: "flagName", + expectedValue: true, + expectedErr: false, + expectedArgs: []string{"somecmd", "--flagName=false", "otherarg"}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Make a copy to avoid modifying the original + argsCopy := append([]string(nil), tc.args...) + value, err := ExtractBoolFlagFromArgs(&argsCopy, tc.flagName) + + if tc.expectedErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + + assert.Equal(t, tc.expectedValue, value) + assert.Equal(t, tc.expectedArgs, argsCopy) + }) + } +} From ac66c42b1271cf0eb65092f935c776444e06e0ea Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Wed, 27 Nov 2024 21:08:39 +0200 Subject: [PATCH 3/3] Bump version from 2.71.5 to 2.72.0 (#2770) --- build/npm/v2-jf/package-lock.json | 2 +- build/npm/v2-jf/package.json | 2 +- build/npm/v2/package-lock.json | 2 +- build/npm/v2/package.json | 2 +- go.mod | 14 +++++++------- go.sum | 16 ++++++++-------- utils/cliutils/cli_consts.go | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/build/npm/v2-jf/package-lock.json b/build/npm/v2-jf/package-lock.json index 8cb87ed8b..e37f0140c 100644 --- a/build/npm/v2-jf/package-lock.json +++ b/build/npm/v2-jf/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2-jf", - "version": "2.71.5", + "version": "2.72.0", "lockfileVersion": 1 } diff --git a/build/npm/v2-jf/package.json b/build/npm/v2-jf/package.json index 8e6ef7991..a5c806754 100644 --- a/build/npm/v2-jf/package.json +++ b/build/npm/v2-jf/package.json @@ -1,6 +1,6 @@ { "name": "jfrog-cli-v2-jf", - "version": "2.71.5", + "version": "2.72.0", "description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸", "homepage": "https://github.com/jfrog/jfrog-cli", "preferGlobal": true, diff --git a/build/npm/v2/package-lock.json b/build/npm/v2/package-lock.json index 1728225c8..64a10c50e 100644 --- a/build/npm/v2/package-lock.json +++ b/build/npm/v2/package-lock.json @@ -1,5 +1,5 @@ { "name": "jfrog-cli-v2", - "version": "2.71.5", + "version": "2.72.0", "lockfileVersion": 2 } diff --git a/build/npm/v2/package.json b/build/npm/v2/package.json index c1e06522e..c1e57fd4b 100644 --- a/build/npm/v2/package.json +++ b/build/npm/v2/package.json @@ -1,6 +1,6 @@ { "name": "jfrog-cli-v2", - "version": "2.71.5", + "version": "2.72.0", "description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸", "homepage": "https://github.com/jfrog/jfrog-cli", "preferGlobal": true, diff --git a/go.mod b/go.mod index cfab56ecb..ac55a1b44 100644 --- a/go.mod +++ b/go.mod @@ -16,13 +16,13 @@ require ( github.com/docker/docker v27.3.1+incompatible github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 github.com/jfrog/archiver/v3 v3.6.1 - github.com/jfrog/build-info-go v1.10.5 + github.com/jfrog/build-info-go v1.10.6 github.com/jfrog/gofrog v1.7.6 github.com/jfrog/jfrog-cli-artifactory v0.1.7 - github.com/jfrog/jfrog-cli-core/v2 v2.56.8 + github.com/jfrog/jfrog-cli-core/v2 v2.57.0 github.com/jfrog/jfrog-cli-platform-services v1.4.0 - github.com/jfrog/jfrog-cli-security v1.12.5 - github.com/jfrog/jfrog-client-go v1.48.0 + github.com/jfrog/jfrog-cli-security v1.13.2 + github.com/jfrog/jfrog-client-go v1.48.1 github.com/jszwec/csvutil v1.10.0 github.com/manifoldco/promptui v0.9.0 github.com/stretchr/testify v1.9.0 @@ -167,12 +167,12 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 +// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 -replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 +// replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7 -replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd +// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev diff --git a/go.sum b/go.sum index 9692db858..379826f9b 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,6 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= -github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= -github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= @@ -163,8 +161,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtx github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI= github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw= -github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd h1:PzxnJ1mjHIL4bAC4RPm87WnJ1TZXFBicyOhtIHRQH6g= -github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= +github.com/jfrog/build-info-go v1.10.6 h1:zH1ZhXlVfi5DlFyunygHjrdOcnv5qxfeLqmsfD4+lc4= +github.com/jfrog/build-info-go v1.10.6/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= github.com/jfrog/froggit-go v1.16.2 h1:F//S83iXH14qsCwYzv0zB2JtjS2pJVEsUoEmYA+37dQ= github.com/jfrog/froggit-go v1.16.2/go.mod h1:5VpdQfAcbuyFl9x/x8HGm7kVk719kEtW/8YJFvKcHPA= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= @@ -173,12 +171,14 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-artifactory v0.1.7 h1:/PBDO6nS6cf3PK+GRkd6BJtZnvYasi1PrQhRiayirso= github.com/jfrog/jfrog-cli-artifactory v0.1.7/go.mod h1:M5pZTHnsYNDmml/FAnoxxt4QiHOIUHPx91th30AtwfM= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 h1:cJSPTMflqE+ucC/h2/BB6BkVxz3BG8PnivCb00Dxt/Y= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= +github.com/jfrog/jfrog-cli-core/v2 v2.57.0 h1:3ON0J6Sjc2+4HZrzh4eSbdciXx3sJsJUIJ3TPQXh/5c= +github.com/jfrog/jfrog-cli-core/v2 v2.57.0/go.mod h1:SThaC/fniC96oN8YgCsHjvOxp5rBM7IppuIybn1oxT0= github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs= github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc= -github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU= -github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU= +github.com/jfrog/jfrog-cli-security v1.13.2 h1:60WO6PjtIQz/21EzggDzUoeK6ScDrNAYXA0k1cqcZqQ= +github.com/jfrog/jfrog-cli-security v1.13.2/go.mod h1:0oEKO2/vVvBC3m9SSWcKx4tWG6sPmvy4Mn4RD2zlSEQ= +github.com/jfrog/jfrog-client-go v1.48.1 h1:R6x6gazy0F196XXDhDdRAxmNplSJ5SrJfEmmNBgks/8= +github.com/jfrog/jfrog-client-go v1.48.1/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU= github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI= github.com/jszwec/csvutil v1.10.0/go.mod h1:/E4ONrmGkwmWsk9ae9jpXnv9QT8pLHEPcCirMFhxG9I= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= diff --git a/utils/cliutils/cli_consts.go b/utils/cliutils/cli_consts.go index 325ead011..6ffb56a42 100644 --- a/utils/cliutils/cli_consts.go +++ b/utils/cliutils/cli_consts.go @@ -4,7 +4,7 @@ import "time" const ( // General CLI constants - CliVersion = "2.71.5" + CliVersion = "2.72.0" ClientAgent = "jfrog-cli-go" // CLI base commands constants: