From 8150e766c9788cf3a7bd2337feae461cd0e98e5e Mon Sep 17 00:00:00 2001 From: yahavi Date: Mon, 8 Feb 2021 08:34:09 +0200 Subject: [PATCH] Add 'jfrog config' command --- THIRD_PARTY_NOTICES | 8 + artifactory/cli.go | 397 ++++++++++++++------------------ artifactory_test.go | 204 ++++++++-------- bintray/cli.go | 42 ++-- buildinfo_test.go | 72 +++--- completion/cli.go | 4 +- config/cli.go | 182 +++++++++++++++ distribution_test.go | 6 +- docker_test.go | 22 +- docs/config/create/help.go | 8 + docs/config/delete/help.go | 9 + docs/config/exportcmd/help.go | 8 + docs/config/importcmd/help.go | 8 + docs/config/show/help.go | 8 + docs/config/use/help.go | 8 + go_test.go | 14 +- gradle_test.go | 10 +- inttestutils/distribution.go | 2 +- inttestutils/docker.go | 16 +- main.go | 39 +++- maven_test.go | 8 +- missioncontrol/cli.go | 166 +++++-------- npm_test.go | 10 +- nuget_test.go | 6 +- pip_test.go | 4 +- plugins/cli.go | 4 +- utils/cliutils/cli_consts.go | 1 + utils/cliutils/commandsflags.go | 37 ++- utils/cliutils/utils.go | 59 +++++ utils/tests/utils.go | 6 +- xray/cli.go | 2 +- 31 files changed, 804 insertions(+), 566 deletions(-) create mode 100644 THIRD_PARTY_NOTICES create mode 100644 config/cli.go create mode 100644 docs/config/create/help.go create mode 100644 docs/config/delete/help.go create mode 100644 docs/config/exportcmd/help.go create mode 100644 docs/config/importcmd/help.go create mode 100644 docs/config/show/help.go create mode 100644 docs/config/use/help.go diff --git a/THIRD_PARTY_NOTICES b/THIRD_PARTY_NOTICES new file mode 100644 index 000000000..adce35844 --- /dev/null +++ b/THIRD_PARTY_NOTICES @@ -0,0 +1,8 @@ +JFrog + + THIRD-PARTY SOFTWARE NOTICES AND INFORMATION + Do Not Translate or Localize + + This project incorporates various components from those projects listed below. JFrog is using such components under the following original copyright notices and the licenses + + 1. manifoldco/promptui (https://github.com/manifoldco/promptui) - Copyright (c) 2017, Arigato Machine Inc; Licensed under BSD 3-Clause License (https://github.com/manifoldco/promptui/blob/master/LICENSE.md) \ No newline at end of file diff --git a/artifactory/cli.go b/artifactory/cli.go index c7e77116d..6e24f1443 100644 --- a/artifactory/cli.go +++ b/artifactory/cli.go @@ -14,6 +14,7 @@ import ( "github.com/jfrog/jfrog-cli-core/artifactory/commands/permissiontarget" "github.com/jfrog/jfrog-cli-core/artifactory/commands/usersmanagement" containerutils "github.com/jfrog/jfrog-cli-core/artifactory/utils/container" + coreCommonCommands "github.com/jfrog/jfrog-cli-core/common/commands" "github.com/jfrog/jfrog-cli-core/utils/coreutils" "github.com/jfrog/jfrog-cli-core/utils/ioutils" "github.com/jfrog/jfrog-cli/docs/artifactory/accesstokencreate" @@ -54,7 +55,8 @@ import ( "github.com/jfrog/jfrog-cli-core/artifactory/utils" npmUtils "github.com/jfrog/jfrog-cli-core/artifactory/utils/npm" corecommon "github.com/jfrog/jfrog-cli-core/docs/common" - "github.com/jfrog/jfrog-cli-core/utils/config" + coreConfig "github.com/jfrog/jfrog-cli-core/utils/config" + "github.com/jfrog/jfrog-cli/config" "github.com/jfrog/jfrog-cli/docs/artifactory/buildadddependencies" "github.com/jfrog/jfrog-cli/docs/artifactory/buildaddgit" "github.com/jfrog/jfrog-cli/docs/artifactory/buildappend" @@ -125,9 +127,9 @@ func GetCommands() []cli.Command { return []cli.Command{ { Name: "config", - Flags: cliutils.GetCommandFlags(cliutils.Config), + Flags: cliutils.GetCommandFlags(cliutils.RtConfig), Aliases: []string{"c"}, - Usage: configdocs.Description, + Description: configdocs.Description, HelpName: corecommon.CreateUsage("rt config", configdocs.Description, configdocs.Usage), UsageText: configdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -138,11 +140,11 @@ func GetCommands() []cli.Command { }, { Name: "use", - Usage: use.Description, + Description: use.Description, HelpName: corecommon.CreateUsage("rt use", use.Description, use.Usage), UsageText: use.Arguments, ArgsUsage: common.CreateEnvVars(), - BashComplete: corecommon.CreateBashCompletionFunc(commands.GetAllArtifactoryServerIds()...), + BashComplete: corecommon.CreateBashCompletionFunc(coreCommonCommands.GetAllServerIds()...), Action: func(c *cli.Context) error { return useCmd(c) }, @@ -151,7 +153,7 @@ func GetCommands() []cli.Command { Name: "upload", Flags: cliutils.GetCommandFlags(cliutils.Upload), Aliases: []string{"u"}, - Usage: upload.Description, + Description: upload.Description, HelpName: corecommon.CreateUsage("rt upload", upload.Description, upload.Usage), UsageText: upload.Arguments, ArgsUsage: common.CreateEnvVars(upload.EnvVar), @@ -164,7 +166,7 @@ func GetCommands() []cli.Command { Name: "download", Flags: cliutils.GetCommandFlags(cliutils.Download), Aliases: []string{"dl"}, - Usage: download.Description, + Description: download.Description, HelpName: corecommon.CreateUsage("rt download", download.Description, download.Usage), UsageText: download.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -177,7 +179,7 @@ func GetCommands() []cli.Command { Name: "move", Flags: cliutils.GetCommandFlags(cliutils.Move), Aliases: []string{"mv"}, - Usage: move.Description, + Description: move.Description, HelpName: corecommon.CreateUsage("rt move", move.Description, move.Usage), UsageText: move.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -190,7 +192,7 @@ func GetCommands() []cli.Command { Name: "copy", Flags: cliutils.GetCommandFlags(cliutils.Copy), Aliases: []string{"cp"}, - Usage: copydocs.Description, + Description: copydocs.Description, HelpName: corecommon.CreateUsage("rt copy", copydocs.Description, copydocs.Usage), UsageText: copydocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -203,7 +205,7 @@ func GetCommands() []cli.Command { Name: "delete", Flags: cliutils.GetCommandFlags(cliutils.Delete), Aliases: []string{"del"}, - Usage: delete.Description, + Description: delete.Description, HelpName: corecommon.CreateUsage("rt delete", delete.Description, delete.Usage), UsageText: delete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -216,7 +218,7 @@ func GetCommands() []cli.Command { Name: "search", Flags: cliutils.GetCommandFlags(cliutils.Search), Aliases: []string{"s"}, - Usage: search.Description, + Description: search.Description, HelpName: corecommon.CreateUsage("rt search", search.Description, search.Usage), UsageText: search.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -229,7 +231,7 @@ func GetCommands() []cli.Command { Name: "set-props", Flags: cliutils.GetCommandFlags(cliutils.Properties), Aliases: []string{"sp"}, - Usage: setprops.Description, + Description: setprops.Description, HelpName: corecommon.CreateUsage("rt set-props", setprops.Description, setprops.Usage), UsageText: setprops.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -242,7 +244,7 @@ func GetCommands() []cli.Command { Name: "delete-props", Flags: cliutils.GetCommandFlags(cliutils.Properties), Aliases: []string{"delp"}, - Usage: deleteprops.Description, + Description: deleteprops.Description, HelpName: corecommon.CreateUsage("rt delete-props", deleteprops.Description, deleteprops.Usage), UsageText: deleteprops.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -255,7 +257,7 @@ func GetCommands() []cli.Command { Name: "build-publish", Flags: cliutils.GetCommandFlags(cliutils.BuildPublish), Aliases: []string{"bp"}, - Usage: buildpublish.Description, + Description: buildpublish.Description, HelpName: corecommon.CreateUsage("rt build-publish", buildpublish.Description, buildpublish.Usage), UsageText: buildpublish.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -267,7 +269,7 @@ func GetCommands() []cli.Command { { Name: "build-collect-env", Aliases: []string{"bce"}, - Usage: buildcollectenv.Description, + Description: buildcollectenv.Description, HelpName: corecommon.CreateUsage("rt build-collect-env", buildcollectenv.Description, buildcollectenv.Usage), UsageText: buildcollectenv.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -280,7 +282,7 @@ func GetCommands() []cli.Command { Name: "build-append", Flags: cliutils.GetCommandFlags(cliutils.BuildAppend), Aliases: []string{"ba"}, - Usage: buildadddependencies.Description, + Description: buildadddependencies.Description, HelpName: corecommon.CreateUsage("rt build-append", buildappend.Description, buildappend.Usage), UsageText: buildappend.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -293,7 +295,7 @@ func GetCommands() []cli.Command { Name: "build-add-dependencies", Flags: cliutils.GetCommandFlags(cliutils.BuildAddDependencies), Aliases: []string{"bad"}, - Usage: buildadddependencies.Description, + Description: buildadddependencies.Description, HelpName: corecommon.CreateUsage("rt build-add-dependencies", buildadddependencies.Description, buildadddependencies.Usage), UsageText: buildadddependencies.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -306,7 +308,7 @@ func GetCommands() []cli.Command { Name: "build-add-git", Flags: cliutils.GetCommandFlags(cliutils.BuildAddGit), Aliases: []string{"bag"}, - Usage: buildaddgit.Description, + Description: buildaddgit.Description, HelpName: corecommon.CreateUsage("rt build-add-git", buildaddgit.Description, buildaddgit.Usage), UsageText: buildaddgit.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -319,7 +321,7 @@ func GetCommands() []cli.Command { Name: "build-scan", Flags: cliutils.GetCommandFlags(cliutils.BuildScan), Aliases: []string{"bs"}, - Usage: buildscan.Description, + Description: buildscan.Description, HelpName: corecommon.CreateUsage("rt build-scan", buildscan.Description, buildscan.Usage), UsageText: buildscan.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -331,7 +333,7 @@ func GetCommands() []cli.Command { { Name: "build-clean", Aliases: []string{"bc"}, - Usage: buildclean.Description, + Description: buildclean.Description, HelpName: corecommon.CreateUsage("rt build-clean", buildclean.Description, buildclean.Usage), UsageText: buildclean.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -344,7 +346,7 @@ func GetCommands() []cli.Command { Name: "build-promote", Flags: cliutils.GetCommandFlags(cliutils.BuildPromote), Aliases: []string{"bpr"}, - Usage: buildpromote.Description, + Description: buildpromote.Description, HelpName: corecommon.CreateUsage("rt build-promote", buildpromote.Description, buildpromote.Usage), UsageText: buildpromote.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -357,7 +359,7 @@ func GetCommands() []cli.Command { Name: "build-distribute", Flags: cliutils.GetCommandFlags(cliutils.BuildDistribute), Aliases: []string{"bd"}, - Usage: builddistribute.Description, + Description: builddistribute.Description, HelpName: corecommon.CreateUsage("rt build-distribute", builddistribute.Description, builddistribute.Usage), UsageText: builddistribute.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -370,7 +372,7 @@ func GetCommands() []cli.Command { Name: "build-discard", Flags: cliutils.GetCommandFlags(cliutils.BuildDiscard), Aliases: []string{"bdi"}, - Usage: builddiscard.Description, + Description: builddiscard.Description, HelpName: corecommon.CreateUsage("rt build-discard", builddiscard.Description, builddiscard.Usage), UsageText: builddiscard.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -383,7 +385,7 @@ func GetCommands() []cli.Command { Name: "git-lfs-clean", Flags: cliutils.GetCommandFlags(cliutils.GitLfsClean), Aliases: []string{"glc"}, - Usage: gitlfsclean.Description, + Description: gitlfsclean.Description, HelpName: corecommon.CreateUsage("rt git-lfs-clean", gitlfsclean.Description, gitlfsclean.Usage), UsageText: gitlfsclean.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -396,7 +398,7 @@ func GetCommands() []cli.Command { Name: "mvn-config", Aliases: []string{"mvnc"}, Flags: cliutils.GetCommandFlags(cliutils.MvnConfig), - Usage: mvnconfig.Description, + Description: mvnconfig.Description, HelpName: corecommon.CreateUsage("rt mvn-config", mvnconfig.Description, mvnconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -407,7 +409,7 @@ func GetCommands() []cli.Command { { Name: "mvn", Flags: cliutils.GetCommandFlags(cliutils.Mvn), - Usage: mvndoc.Description, + Description: mvndoc.Description, HelpName: corecommon.CreateUsage("rt mvn", mvndoc.Description, mvndoc.Usage), UsageText: mvndoc.Arguments, ArgsUsage: common.CreateEnvVars(mvndoc.EnvVar), @@ -421,7 +423,7 @@ func GetCommands() []cli.Command { Name: "gradle-config", Aliases: []string{"gradlec"}, Flags: cliutils.GetCommandFlags(cliutils.GradleConfig), - Usage: gradleconfig.Description, + Description: gradleconfig.Description, HelpName: corecommon.CreateUsage("rt gradle-config", gradleconfig.Description, gradleconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -432,7 +434,7 @@ func GetCommands() []cli.Command { { Name: "gradle", Flags: cliutils.GetCommandFlags(cliutils.Gradle), - Usage: gradledoc.Description, + Description: gradledoc.Description, HelpName: corecommon.CreateUsage("rt gradle", gradledoc.Description, gradledoc.Usage), UsageText: gradledoc.Arguments, ArgsUsage: common.CreateEnvVars(gradledoc.EnvVar), @@ -446,7 +448,7 @@ func GetCommands() []cli.Command { Name: "docker-promote", Flags: cliutils.GetCommandFlags(cliutils.DockerPromote), Aliases: []string{"dpr"}, - Usage: dockerpromote.Description, + Description: dockerpromote.Description, HelpName: corecommon.CreateUsage("rt docker-promote", dockerpromote.Description, dockerpromote.Usage), UsageText: dockerpromote.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -459,7 +461,7 @@ func GetCommands() []cli.Command { Name: "docker-push", Flags: cliutils.GetCommandFlags(cliutils.ContainerPush), Aliases: []string{"dp"}, - Usage: dockerpush.Description, + Description: dockerpush.Description, HelpName: corecommon.CreateUsage("rt docker-push", dockerpush.Description, dockerpush.Usage), UsageText: dockerpush.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -472,7 +474,7 @@ func GetCommands() []cli.Command { Name: "docker-pull", Flags: cliutils.GetCommandFlags(cliutils.ContainerPull), Aliases: []string{"dpl"}, - Usage: dockerpull.Description, + Description: dockerpull.Description, HelpName: corecommon.CreateUsage("rt docker-pull", dockerpull.Description, dockerpull.Usage), UsageText: dockerpull.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -485,7 +487,7 @@ func GetCommands() []cli.Command { Name: "podman-push", Flags: cliutils.GetCommandFlags(cliutils.ContainerPush), Aliases: []string{"pp"}, - Usage: podmanpush.Description, + Description: podmanpush.Description, HelpName: corecommon.CreateUsage("rt podman-push", podmanpush.Description, podmanpush.Usage), UsageText: podmanpush.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -498,7 +500,7 @@ func GetCommands() []cli.Command { Name: "podman-pull", Flags: cliutils.GetCommandFlags(cliutils.ContainerPull), Aliases: []string{"ppl"}, - Usage: podmanpull.Description, + Description: podmanpull.Description, HelpName: corecommon.CreateUsage("rt podman-pull", podmanpull.Description, podmanpull.Usage), UsageText: podmanpull.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -511,7 +513,7 @@ func GetCommands() []cli.Command { Name: "build-docker-create", Flags: cliutils.GetCommandFlags(cliutils.BuildDockerCreate), Aliases: []string{"bdc"}, - Usage: builddockercreate.Description, + Description: builddockercreate.Description, HelpName: corecommon.CreateUsage("rt build-docker-create", builddockercreate.Description, builddockercreate.Usage), UsageText: builddockercreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -524,7 +526,7 @@ func GetCommands() []cli.Command { Name: "npm-config", Flags: cliutils.GetCommandFlags(cliutils.NpmConfig), Aliases: []string{"npmc"}, - Usage: npmconfig.Description, + Description: npmconfig.Description, HelpName: corecommon.CreateUsage("rt npm-config", npmconfig.Description, npmconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -536,7 +538,7 @@ func GetCommands() []cli.Command { Name: "npm-install", Flags: cliutils.GetCommandFlags(cliutils.Npm), Aliases: []string{"npmi"}, - Usage: npminstall.Description, + Description: npminstall.Description, HelpName: corecommon.CreateUsage("rt npm-install", npminstall.Description, npminstall.Usage), UsageText: npminstall.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -550,7 +552,7 @@ func GetCommands() []cli.Command { Name: "npm-ci", Flags: cliutils.GetCommandFlags(cliutils.Npm), Aliases: []string{"npmci"}, - Usage: npmci.Description, + Description: npmci.Description, HelpName: corecommon.CreateUsage("rt npm-ci", npmci.Description, npmci.Usage), UsageText: npmci.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -564,7 +566,7 @@ func GetCommands() []cli.Command { Name: "npm-publish", Flags: cliutils.GetCommandFlags(cliutils.NpmPublish), Aliases: []string{"npmp"}, - Usage: npmpublish.Description, + Description: npmpublish.Description, HelpName: corecommon.CreateUsage("rt npm-publish", npmpublish.Description, npmpublish.Usage), ArgsUsage: common.CreateEnvVars(), SkipFlagParsing: shouldSkipNpmFlagParsing(), @@ -577,7 +579,7 @@ func GetCommands() []cli.Command { Name: "nuget-config", Flags: cliutils.GetCommandFlags(cliutils.NugetConfig), Aliases: []string{"nugetc"}, - Usage: nugetconfig.Description, + Description: nugetconfig.Description, HelpName: corecommon.CreateUsage("rt nuget-config", nugetconfig.Description, nugetconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -588,7 +590,7 @@ func GetCommands() []cli.Command { { Name: "nuget", Flags: cliutils.GetCommandFlags(cliutils.Nuget), - Usage: nugetdocs.Description, + Description: nugetdocs.Description, HelpName: corecommon.CreateUsage("rt nuget", nugetdocs.Description, nugetdocs.Usage), UsageText: nugetdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -601,7 +603,7 @@ func GetCommands() []cli.Command { { Name: "nuget-deps-tree", Aliases: []string{"ndt"}, - Usage: nugettree.Description, + Description: nugettree.Description, HelpName: corecommon.CreateUsage("rt nuget-deps-tree", nugettree.Description, nugettree.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -613,7 +615,7 @@ func GetCommands() []cli.Command { Name: "dotnet-config", Flags: cliutils.GetCommandFlags(cliutils.DotnetConfig), Aliases: []string{"dotnetc"}, - Usage: dotnetconfig.Description, + Description: dotnetconfig.Description, HelpName: corecommon.CreateUsage("rt dotnet-config", dotnetconfig.Description, dotnetconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -624,7 +626,7 @@ func GetCommands() []cli.Command { { Name: "dotnet", Flags: cliutils.GetCommandFlags(cliutils.Dotnet), - Usage: dotnetdocs.Description, + Description: dotnetdocs.Description, HelpName: corecommon.CreateUsage("rt dotnet", dotnetdocs.Description, dotnetdocs.Usage), UsageText: dotnetdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -637,7 +639,7 @@ func GetCommands() []cli.Command { { Name: "go-config", Flags: cliutils.GetCommandFlags(cliutils.GoConfig), - Usage: goconfig.Description, + Description: goconfig.Description, HelpName: corecommon.CreateUsage("rt go-config", goconfig.Description, goconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -649,7 +651,7 @@ func GetCommands() []cli.Command { Name: "go-publish", Flags: cliutils.GetCommandFlags(cliutils.GoPublish), Aliases: []string{"gp"}, - Usage: gopublish.Description, + Description: gopublish.Description, HelpName: corecommon.CreateUsage("rt go-publish", gopublish.Description, gopublish.Usage), UsageText: gopublish.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -662,7 +664,7 @@ func GetCommands() []cli.Command { Name: "go", Flags: cliutils.GetCommandFlags(cliutils.Go), Aliases: []string{"go"}, - Usage: gocommand.Description, + Description: gocommand.Description, HelpName: corecommon.CreateUsage("rt go", gocommand.Description, gocommand.Usage), UsageText: gocommand.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -676,7 +678,7 @@ func GetCommands() []cli.Command { Name: "go-recursive-publish", Flags: cliutils.GetCommandFlags(cliutils.GoRecursivePublish), Aliases: []string{"grp"}, - Usage: gorecursivepublish.Description, + Description: gorecursivepublish.Description, HelpName: corecommon.CreateUsage("rt grp", gorecursivepublish.Description, gorecursivepublish.Usage), UsageText: gorecursivepublish.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -689,7 +691,7 @@ func GetCommands() []cli.Command { Name: "ping", Flags: cliutils.GetCommandFlags(cliutils.Ping), Aliases: []string{"p"}, - Usage: ping.Description, + Description: ping.Description, HelpName: corecommon.CreateUsage("rt ping", ping.Description, ping.Usage), UsageText: ping.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -702,7 +704,7 @@ func GetCommands() []cli.Command { Name: "curl", Flags: cliutils.GetCommandFlags(cliutils.Curl), Aliases: []string{"cl"}, - Usage: curldocs.Description, + Description: curldocs.Description, HelpName: corecommon.CreateUsage("rt curl", curldocs.Description, curldocs.Usage), UsageText: curldocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -716,7 +718,7 @@ func GetCommands() []cli.Command { Name: "pip-config", Flags: cliutils.GetCommandFlags(cliutils.PipConfig), Aliases: []string{"pipc"}, - Usage: pipconfig.Description, + Description: pipconfig.Description, HelpName: corecommon.CreateUsage("rt pipc", pipconfig.Description, pipconfig.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -728,7 +730,7 @@ func GetCommands() []cli.Command { Name: "pip-install", Flags: cliutils.GetCommandFlags(cliutils.PipInstall), Aliases: []string{"pipi"}, - Usage: pipinstall.Description, + Description: pipinstall.Description, HelpName: corecommon.CreateUsage("rt pipi", pipinstall.Description, pipinstall.Usage), UsageText: pipinstall.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -742,7 +744,7 @@ func GetCommands() []cli.Command { Name: "release-bundle-create", Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleCreate), Aliases: []string{"rbc"}, - Usage: releasebundlecreate.Description, + Description: releasebundlecreate.Description, HelpName: corecommon.CreateUsage("rt rbc", releasebundlecreate.Description, releasebundlecreate.Usage), UsageText: releasebundlecreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -755,7 +757,7 @@ func GetCommands() []cli.Command { Name: "release-bundle-update", Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleUpdate), Aliases: []string{"rbu"}, - Usage: releasebundleupdate.Description, + Description: releasebundleupdate.Description, HelpName: corecommon.CreateUsage("rt rbu", releasebundleupdate.Description, releasebundleupdate.Usage), UsageText: releasebundleupdate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -768,7 +770,7 @@ func GetCommands() []cli.Command { Name: "release-bundle-sign", Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleSign), Aliases: []string{"rbs"}, - Usage: releasebundlesign.Description, + Description: releasebundlesign.Description, HelpName: corecommon.CreateUsage("rt rbs", releasebundlesign.Description, releasebundlesign.Usage), UsageText: releasebundlesign.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -781,7 +783,7 @@ func GetCommands() []cli.Command { Name: "release-bundle-distribute", Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDistribute), Aliases: []string{"rbd"}, - Usage: releasebundledistribute.Description, + Description: releasebundledistribute.Description, HelpName: corecommon.CreateUsage("rt rbd", releasebundledistribute.Description, releasebundledistribute.Usage), UsageText: releasebundledistribute.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -794,7 +796,7 @@ func GetCommands() []cli.Command { Name: "release-bundle-delete", Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDelete), Aliases: []string{"rbdel"}, - Usage: releasebundledelete.Description, + Description: releasebundledelete.Description, HelpName: corecommon.CreateUsage("rt rbdel", releasebundledelete.Description, releasebundledelete.Usage), UsageText: releasebundledelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -806,7 +808,7 @@ func GetCommands() []cli.Command { { Name: "repo-template", Aliases: []string{"rpt"}, - Usage: repotemplate.Description, + Description: repotemplate.Description, HelpName: corecommon.CreateUsage("rt rpt", repotemplate.Description, repotemplate.Usage), UsageText: repotemplate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -819,7 +821,7 @@ func GetCommands() []cli.Command { Name: "repo-create", Aliases: []string{"rc"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: repocreate.Description, + Description: repocreate.Description, HelpName: corecommon.CreateUsage("rt rc", repocreate.Description, repocreate.Usage), UsageText: repocreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -832,7 +834,7 @@ func GetCommands() []cli.Command { Name: "repo-update", Aliases: []string{"ru"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: repoupdate.Description, + Description: repoupdate.Description, HelpName: corecommon.CreateUsage("rt ru", repoupdate.Description, repoupdate.Usage), UsageText: repoupdate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -845,7 +847,7 @@ func GetCommands() []cli.Command { Name: "repo-delete", Aliases: []string{"rdel"}, Flags: cliutils.GetCommandFlags(cliutils.RepoDelete), - Usage: repodelete.Description, + Description: repodelete.Description, HelpName: corecommon.CreateUsage("rt rdel", repodelete.Description, repodelete.Usage), UsageText: repodelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -858,7 +860,7 @@ func GetCommands() []cli.Command { Name: "replication-template", Aliases: []string{"rplt"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: replicationtemplate.Description, + Description: replicationtemplate.Description, HelpName: corecommon.CreateUsage("rt rplt", replicationtemplate.Description, replicationtemplate.Usage), UsageText: replicationtemplate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -871,7 +873,7 @@ func GetCommands() []cli.Command { Name: "replication-create", Aliases: []string{"rplc"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: replicationcreate.Description, + Description: replicationcreate.Description, HelpName: corecommon.CreateUsage("rt rplc", replicationcreate.Description, replicationcreate.Usage), UsageText: replicationcreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -884,7 +886,7 @@ func GetCommands() []cli.Command { Name: "replication-delete", Aliases: []string{"rpldel"}, Flags: cliutils.GetCommandFlags(cliutils.ReplicationDelete), - Usage: replicationdelete.Description, + Description: replicationdelete.Description, HelpName: corecommon.CreateUsage("rt rpldel", replicationdelete.Description, replicationdelete.Usage), UsageText: replicationdelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -896,7 +898,7 @@ func GetCommands() []cli.Command { { Name: "permission-target-template", Aliases: []string{"ptt"}, - Usage: permissiontargettemplate.Description, + Description: permissiontargettemplate.Description, HelpName: corecommon.CreateUsage("rt ptt", permissiontargettemplate.Description, permissiontargettemplate.Usage), UsageText: permissiontargettemplate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -909,7 +911,7 @@ func GetCommands() []cli.Command { Name: "permission-target-create", Aliases: []string{"ptc"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: permissiontargetcreate.Description, + Description: permissiontargetcreate.Description, HelpName: corecommon.CreateUsage("rt ptc", permissiontargetcreate.Description, permissiontargetcreate.Usage), UsageText: permissiontargetcreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -922,7 +924,7 @@ func GetCommands() []cli.Command { Name: "permission-target-update", Aliases: []string{"ptu"}, Flags: cliutils.GetCommandFlags(cliutils.TemplateConsumer), - Usage: permissiontargetupdate.Description, + Description: permissiontargetupdate.Description, HelpName: corecommon.CreateUsage("rt ptu", permissiontargetupdate.Description, permissiontargetupdate.Usage), UsageText: permissiontargetupdate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -935,7 +937,7 @@ func GetCommands() []cli.Command { Name: "permission-target-delete", Aliases: []string{"ptdel"}, Flags: cliutils.GetCommandFlags(cliutils.PermissionTargetDelete), - Usage: permissiontargetdelete.Description, + Description: permissiontargetdelete.Description, HelpName: corecommon.CreateUsage("rt ptdel", permissiontargetdelete.Description, permissiontargetdelete.Usage), UsageText: permissiontargetdelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -948,7 +950,7 @@ func GetCommands() []cli.Command { Name: "users-create", Aliases: []string{"uc"}, Flags: cliutils.GetCommandFlags(cliutils.UsersCreate), - Usage: userscreate.Description, + Description: userscreate.Description, HelpName: corecommon.CreateUsage("rt uc", userscreate.Description, userscreate.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -960,7 +962,7 @@ func GetCommands() []cli.Command { Name: "users-delete", Aliases: []string{"udel"}, Flags: cliutils.GetCommandFlags(cliutils.UsersDelete), - Usage: usersdelete.Description, + Description: usersdelete.Description, HelpName: corecommon.CreateUsage("rt udel", usersdelete.Description, usersdelete.Usage), UsageText: usersdelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -973,7 +975,7 @@ func GetCommands() []cli.Command { Name: "group-create", Aliases: []string{"gc"}, Flags: cliutils.GetCommandFlags(cliutils.GroupCreate), - Usage: groupcreate.Description, + Description: groupcreate.Description, HelpName: corecommon.CreateUsage("rt gc", groupcreate.Description, groupcreate.Usage), UsageText: groupcreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -986,7 +988,7 @@ func GetCommands() []cli.Command { Name: "group-add-users", Aliases: []string{"gau"}, Flags: cliutils.GetCommandFlags(cliutils.GroupAddUsers), - Usage: groupaddusers.Description, + Description: groupaddusers.Description, HelpName: corecommon.CreateUsage("rt gau", groupaddusers.Description, groupaddusers.Usage), UsageText: groupaddusers.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -999,7 +1001,7 @@ func GetCommands() []cli.Command { Name: "group-delete", Aliases: []string{"gdel"}, Flags: cliutils.GetCommandFlags(cliutils.GroupDelete), - Usage: groupdelete.Description, + Description: groupdelete.Description, HelpName: corecommon.CreateUsage("rt gdel", groupdelete.Description, groupdelete.Usage), UsageText: groupdelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -1012,7 +1014,7 @@ func GetCommands() []cli.Command { Name: "access-token-create", Aliases: []string{"atc"}, Flags: cliutils.GetCommandFlags(cliutils.AccessTokenCreate), - Usage: accesstokencreate.Description, + Description: accesstokencreate.Description, HelpName: corecommon.CreateUsage("rt atc", accesstokencreate.Description, accesstokencreate.Usage), UsageText: accesstokencreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -1024,7 +1026,7 @@ func GetCommands() []cli.Command { } } -func createArtifactoryDetailsByFlags(c *cli.Context, distribution bool) (*config.ArtifactoryDetails, error) { +func createArtifactoryDetailsByFlags(c *cli.Context, distribution bool) (*coreConfig.ServerDetails, error) { artDetails, err := createArtifactoryDetailsWithConfigOffer(c, distribution) if err != nil { return nil, err @@ -1034,7 +1036,7 @@ func createArtifactoryDetailsByFlags(c *cli.Context, distribution bool) (*config return nil, errors.New("the --dist-url option is mandatory") } } else { - if artDetails.Url == "" { + if artDetails.ArtifactoryUrl == "" { return nil, errors.New("the --url option is mandatory") } } @@ -1101,16 +1103,6 @@ func getRetries(c *cli.Context) (retries int, err error) { return retries, nil } -func validateServerId(serverId string) error { - reservedIds := []string{"delete", "use", "show", "clear"} - for _, reservedId := range reservedIds { - if serverId == reservedId { - return errors.New(fmt.Sprintf("Server can't have one of the following ID's: %s\n %s", strings.Join(reservedIds, ", "), cliutils.GetDocumentationMessage())) - } - } - return nil -} - func validateCommand(args []string, notAllowedFlags []cli.Flag) error { for _, arg := range args { for _, flag := range notAllowedFlags { @@ -1124,23 +1116,11 @@ func validateCommand(args []string, notAllowedFlags []cli.Flag) error { } func useCmd(c *cli.Context) error { - var serverId string - var err error = nil - if len(c.Args()) == 1 { - serverId = c.Args()[0] - err = validateServerId(serverId) - if err != nil { - return err - } - err = commands.Use(serverId) - if err != nil { - return err - } - } else { + if len(c.Args()) != 1 { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } - - return err + log.Warn(`You are using a deprecated syntax of the "jfrog rt use" command. Use "jfrog config use" instead.`) + return coreCommonCommands.Use(c.Args()[0]) } func configCmd(c *cli.Context) error { @@ -1148,6 +1128,12 @@ func configCmd(c *cli.Context) error { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } + log.Warn(`You are using a deprecated syntax of the "jfrog rt config" commands. Use "jfrog config" instead. + In the new command, if "--url" flag is used, replaced it by "--artifactory-url". + For example: + Old syntax: "jfrog rt config --url=" + New syntax: "jfrog config --artifactory-url="`) + var serverId string configCommandConfiguration, err := createConfigCommandConfiguration(c) if err != nil { @@ -1155,13 +1141,13 @@ func configCmd(c *cli.Context) error { } if len(c.Args()) == 2 { if c.Args()[0] == "import" { - return commands.Import(c.Args()[1]) + return coreCommonCommands.Import(c.Args()[1]) } serverId = c.Args()[1] - if err := validateServerId(serverId); err != nil { + if err := config.ValidateServerId(serverId); err != nil { return err } - artDetails, err := config.GetArtifactorySpecificConfig(serverId, true, false) + artDetails, err := coreConfig.GetSpecificConfig(serverId, true, false) if err != nil { return err } @@ -1175,22 +1161,22 @@ func configCmd(c *cli.Context) error { return nil } } - return commands.DeleteConfig(serverId) + return coreCommonCommands.DeleteConfig(serverId) } if c.Args()[0] == "export" { - return commands.Export(serverId) + return coreCommonCommands.Export(serverId) } } if len(c.Args()) > 0 { if c.Args()[0] == "show" { - return commands.ShowConfig(serverId) + return coreCommonCommands.ShowConfig(serverId) } if c.Args()[0] == "clear" { - commands.ClearConfig(configCommandConfiguration.Interactive) + coreCommonCommands.ClearConfig(configCommandConfiguration.Interactive) return nil } serverId = c.Args()[0] - err = validateServerId(serverId) + err = config.ValidateServerId(serverId) if err != nil { return err } @@ -1199,7 +1185,9 @@ func configCmd(c *cli.Context) error { if err != nil { return err } - configCmd := commands.NewConfigCommand().SetDetails(configCommandConfiguration.ArtDetails).SetInteractive(configCommandConfiguration.Interactive). + configCommandConfiguration.ServerDetails.ArtifactoryUrl = configCommandConfiguration.ServerDetails.Url + configCommandConfiguration.ServerDetails.Url = "" + configCmd := coreCommonCommands.NewConfigCommand().SetDetails(configCommandConfiguration.ServerDetails).SetInteractive(configCommandConfiguration.Interactive). SetServerId(serverId).SetEncPassword(configCommandConfiguration.EncPassword).SetUseBasicAuthOnly(configCommandConfiguration.BasicAuthOnly) return configCmd.Config() } @@ -1330,7 +1318,7 @@ func dockerPromoteCmd(c *cli.Context) error { params.TargetTag = c.String("target-tag") params.Copy = c.Bool("copy") dockerPromoteCommand := container.NewDockerPromoteCommand() - dockerPromoteCommand.SetParams(params).SetRtDetails(artDetails) + dockerPromoteCommand.SetParams(params).SetServerDetails(artDetails) return commands.Exec(dockerPromoteCommand) } @@ -1356,7 +1344,7 @@ func containerPushCmd(c *cli.Context, containerManagerType containerutils.Contai if err != nil { return err } - dockerPushCommand.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(targetRepo).SetSkipLogin(skipLogin).SetRtDetails(artDetails).SetImageTag(imageTag) + dockerPushCommand.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(targetRepo).SetSkipLogin(skipLogin).SetServerDetails(artDetails).SetImageTag(imageTag) return commands.Exec(dockerPushCommand) } @@ -1377,7 +1365,7 @@ func containerPullCmd(c *cli.Context, containerManagerType containerutils.Contai return err } dockerPullCommand := container.NewPullCommand(containerManagerType) - dockerPullCommand.SetImageTag(imageTag).SetRepo(sourceRepo).SetSkipLogin(skipLogin).SetRtDetails(artDetails).SetBuildConfiguration(buildConfiguration) + dockerPullCommand.SetImageTag(imageTag).SetRepo(sourceRepo).SetSkipLogin(skipLogin).SetServerDetails(artDetails).SetBuildConfiguration(buildConfiguration) return commands.Exec(dockerPullCommand) } @@ -1403,7 +1391,7 @@ func BuildDockerCreateCmd(c *cli.Context) error { if err := buildDockerCreateCommand.SetImageNameWithDigest(imageNameWithDigestFile); err != nil { return err } - buildDockerCreateCommand.SetRepo(sourceRepo).SetRtDetails(artDetails).SetBuildConfiguration(buildConfiguration) + buildDockerCreateCommand.SetRepo(sourceRepo).SetServerDetails(artDetails).SetBuildConfiguration(buildConfiguration) return commands.Exec(buildDockerCreateCommand) } @@ -1442,7 +1430,7 @@ func nugetCmd(c *cli.Context) error { } nugetCmd := dotnet.NewNugetCommand() - nugetCmd.SetRtDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). + nugetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). SetBasicCommand(filteredNugetArgs[0]).SetUseNugetV2(useNugetV2) // 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 @@ -1476,7 +1464,7 @@ func nugetLegacyCmd(c *cli.Context) error { SetBuildConfiguration(buildConfiguration). SetSolutionPath(c.String(cliutils.SolutionRoot)). SetUseNugetV2(c.Bool(cliutils.LegacyNugetV2)). - SetRtDetails(rtDetails) + SetServerDetails(rtDetails) return commands.Exec(nugetCmd) } @@ -1530,7 +1518,7 @@ func dotnetCmd(c *cli.Context) error { // Run command. dotnetCmd := dotnet.NewDotnetCoreCliCommand() - dotnetCmd.SetRtDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). + dotnetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). SetBasicCommand(filteredDotnetArgs[0]).SetUseNugetV2(useNugetV2) // 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 @@ -1540,7 +1528,7 @@ func dotnetCmd(c *cli.Context) error { return commands.Exec(dotnetCmd) } -func getNugetAndDotnetConfigFields(configFilePath string) (rtDetails *config.ArtifactoryDetails, targetRepo string, useNugetV2 bool, err error) { +func getNugetAndDotnetConfigFields(configFilePath string) (rtDetails *coreConfig.ServerDetails, targetRepo string, useNugetV2 bool, err error) { vConfig, err := utils.ReadConfigFile(configFilePath, utils.YAML) if err != nil { return nil, "", false, errors.New(fmt.Sprintf("Error occurred while attempting to read nuget-configuration file: %s", err.Error())) @@ -1549,7 +1537,7 @@ func getNugetAndDotnetConfigFields(configFilePath string) (rtDetails *config.Art if err != nil { return nil, "", false, err } - rtDetails, err = projectConfig.RtDetails() + rtDetails, err = projectConfig.ServerDetails() if err != nil { return nil, "", false, err } @@ -1580,7 +1568,7 @@ func npmLegacyInstallCmd(c *cli.Context) error { if err != nil { return err } - npmCmd.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetNpmArgs(npmInstallArgs).SetRtDetails(rtDetails) + npmCmd.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetNpmArgs(npmInstallArgs).SetServerDetails(rtDetails) return commands.Exec(npmCmd) } @@ -1628,7 +1616,7 @@ func npmLegacyCiCmd(c *cli.Context) error { if err != nil { return err } - npmCmd.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetRtDetails(rtDetails) + npmCmd.SetThreads(threads).SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetServerDetails(rtDetails) return commands.Exec(npmCmd) } @@ -1675,7 +1663,7 @@ func npmLegacyPublishCmd(c *cli.Context) error { if err != nil { return err } - npmPublicCmd.SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetNpmArgs(npmPublicArgs).SetRtDetails(rtDetails) + npmPublicCmd.SetBuildConfiguration(buildConfiguration).SetRepo(c.Args().Get(0)).SetNpmArgs(npmPublicArgs).SetServerDetails(rtDetails) return commands.Exec(npmPublicCmd) } @@ -1703,7 +1691,7 @@ func goPublishCmd(c *cli.Context) error { return err } goPublishCmd := golang.NewGoPublishCommand() - goPublishCmd.SetBuildConfiguration(buildConfiguration).SetVersion(version).SetDependencies(c.String("deps")).SetPublishPackage(c.BoolT("self")).SetTargetRepo(targetRepo).SetRtDetails(details) + goPublishCmd.SetBuildConfiguration(buildConfiguration).SetVersion(version).SetDependencies(c.String("deps")).SetPublishPackage(c.BoolT("self")).SetTargetRepo(targetRepo).SetServerDetails(details) err = commands.Exec(goPublishCmd) result := goPublishCmd.Result() @@ -1837,7 +1825,7 @@ func goLegacyCmd(c *cli.Context) error { return err } resolverRepo := &utils.RepositoryConfig{} - resolverRepo.SetTargetRepo(targetRepo).SetRtDetails(details) + resolverRepo.SetTargetRepo(targetRepo).SetServerDetails(details) goCmd := golang.NewGoCommand().SetBuildConfiguration(buildConfiguration). SetGoArg(goArg).SetNoRegistry(c.Bool("no-registry")). SetPublishDeps(publishDeps).SetResolverParams(resolverRepo) @@ -1881,7 +1869,7 @@ func goRecursivePublishCmd(c *cli.Context) error { return err } goRecursivePublishCmd := golang.NewGoRecursivePublishCommand() - goRecursivePublishCmd.SetRtDetails(details).SetTargetRepo(targetRepo) + goRecursivePublishCmd.SetServerDetails(details).SetTargetRepo(targetRepo) return commands.Exec(goRecursivePublishCmd) } @@ -1944,7 +1932,7 @@ func pingCmd(c *cli.Context) error { return err } pingCmd := generic.NewPingCommand() - pingCmd.SetRtDetails(artDetails) + pingCmd.SetServerDetails(artDetails) err = commands.Exec(pingCmd) resString := clientutils.IndentJson(pingCmd.Response()) if err != nil { @@ -1991,7 +1979,7 @@ func downloadCmd(c *cli.Context) error { return err } downloadCommand := generic.NewDownloadCommand() - downloadCommand.SetConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(downloadSpec).SetRtDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(c.Bool("detailed-summary")) + downloadCommand.SetConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(downloadSpec).SetServerDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(c.Bool("detailed-summary")) if downloadCommand.ShouldPrompt() && !coreutils.AskYesNo("Sync-deletes may delete some files in your local file system. Are you sure you want to continue?\n"+ "You can avoid this confirmation message by adding --quiet to the command.", false) { @@ -2041,7 +2029,7 @@ func uploadCmd(c *cli.Context) error { if err != nil { return err } - uploadCmd.SetUploadConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(uploadSpec).SetRtDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(c.Bool("detailed-summary")) + uploadCmd.SetUploadConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(uploadSpec).SetServerDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(c.Bool("detailed-summary")) if uploadCmd.ShouldPrompt() && !coreutils.AskYesNo("Sync-deletes may delete some artifacts in Artifactory. Are you sure you want to continue?\n"+ "You can avoid this confirmation message by adding --quiet to the command.", false) { @@ -2104,7 +2092,7 @@ func moveCmd(c *cli.Context) error { if err != nil { return err } - moveCmd.SetThreads(threads).SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails).SetSpec(moveSpec) + moveCmd.SetThreads(threads).SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails).SetSpec(moveSpec) err = commands.Exec(moveCmd) result := moveCmd.Result() err = cliutils.PrintSummaryReport(result.SuccessCount(), result.FailCount(), nil, "", err) @@ -2144,7 +2132,7 @@ func copyCmd(c *cli.Context) error { if err != nil { return err } - copyCommand.SetThreads(threads).SetSpec(copySpec).SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails) + copyCommand.SetThreads(threads).SetSpec(copySpec).SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails) err = commands.Exec(copyCommand) result := copyCommand.Result() err = cliutils.PrintSummaryReport(result.SuccessCount(), result.FailCount(), nil, "", err) @@ -2185,7 +2173,7 @@ func deleteCmd(c *cli.Context) error { if err != nil { return err } - deleteCommand.SetThreads(threads).SetQuiet(cliutils.GetQuietValue(c)).SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails).SetSpec(deleteSpec) + deleteCommand.SetThreads(threads).SetQuiet(cliutils.GetQuietValue(c)).SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails).SetSpec(deleteSpec) err = commands.Exec(deleteCommand) result := deleteCommand.Result() err = cliutils.PrintSummaryReport(result.SuccessCount(), result.FailCount(), nil, "", err) @@ -2220,7 +2208,7 @@ func searchCmd(c *cli.Context) error { return err } searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artDetails).SetSpec(searchSpec) + searchCmd.SetServerDetails(artDetails).SetSpec(searchSpec) err = commands.Exec(searchCmd) if err != nil { return err @@ -2279,7 +2267,7 @@ func preparePropsCmd(c *cli.Context) (*generic.PropsCommand, error) { } cmd := command.SetProps(props) - cmd.SetThreads(threads).SetSpec(propsSpec).SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails) + cmd.SetThreads(threads).SetSpec(propsSpec).SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails) return cmd, nil } @@ -2324,7 +2312,7 @@ func buildPublishCmd(c *cli.Context) error { if err != nil { return err } - buildPublishCmd := buildinfo.NewBuildPublishCommand().SetRtDetails(rtDetails).SetBuildConfiguration(buildConfiguration).SetConfig(buildInfoConfiguration) + buildPublishCmd := buildinfo.NewBuildPublishCommand().SetServerDetails(rtDetails).SetBuildConfiguration(buildConfiguration).SetConfig(buildInfoConfiguration) return commands.Exec(buildPublishCmd) } @@ -2342,7 +2330,7 @@ func buildAppendCmd(c *cli.Context) error { if err != nil { return err } - buildAppendCmd := buildinfo.NewBuildAppendCommand().SetRtDetails(rtDetails).SetBuildConfiguration(buildConfiguration).SetBuildNameToAppend(buildNameToAppend).SetBuildNumberToAppend(buildNumberToAppend) + buildAppendCmd := buildinfo.NewBuildAppendCommand().SetServerDetails(rtDetails).SetBuildConfiguration(buildConfiguration).SetBuildNameToAppend(buildNameToAppend).SetBuildNumberToAppend(buildNumberToAppend) return commands.Exec(buildAppendCmd) } @@ -2425,7 +2413,7 @@ func buildScanCmd(c *cli.Context) error { if err != nil { return err } - buildScanCmd := buildinfo.NewBuildScanCommand().SetRtDetails(rtDetails).SetFailBuild(c.BoolT("fail")).SetBuildConfiguration(buildConfiguration) + buildScanCmd := buildinfo.NewBuildScanCommand().SetServerDetails(rtDetails).SetFailBuild(c.BoolT("fail")).SetBuildConfiguration(buildConfiguration) err = commands.Exec(buildScanCmd) return checkBuildScanError(err) @@ -2468,7 +2456,7 @@ func buildPromoteCmd(c *cli.Context) error { if err != nil { return err } - buildPromotionCmd := buildinfo.NewBuildPromotionCommand().SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails).SetPromotionParams(configuration) + buildPromotionCmd := buildinfo.NewBuildPromotionCommand().SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails).SetPromotionParams(configuration) return commands.Exec(buildPromotionCmd) } @@ -2485,7 +2473,7 @@ func buildDistributeCmd(c *cli.Context) error { if err != nil { return err } - buildDistributeCmd := buildinfo.NewBuildDistributeCommnad().SetDryRun(c.Bool("dry-run")).SetRtDetails(rtDetails).SetBuildDistributionParams(configuration) + buildDistributeCmd := buildinfo.NewBuildDistributeCommnad().SetDryRun(c.Bool("dry-run")).SetServerDetails(rtDetails).SetBuildDistributionParams(configuration) return commands.Exec(buildDistributeCmd) } @@ -2503,7 +2491,7 @@ func buildDiscardCmd(c *cli.Context) error { if err != nil { return err } - buildDiscardCmd.SetRtDetails(rtDetails).SetDiscardBuildsParams(configuration) + buildDiscardCmd.SetServerDetails(rtDetails).SetDiscardBuildsParams(configuration) return commands.Exec(buildDiscardCmd) } @@ -2536,7 +2524,7 @@ func releaseBundleCreateCmd(c *cli.Context) error { if err != nil { return err } - releaseBundleCreateCmd.SetRtDetails(rtDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run")) + releaseBundleCreateCmd.SetServerDetails(rtDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run")) return commands.Exec(releaseBundleCreateCmd) } @@ -2569,7 +2557,7 @@ func releaseBundleUpdateCmd(c *cli.Context) error { if err != nil { return err } - releaseBundleUpdateCmd.SetRtDetails(rtDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run")) + releaseBundleUpdateCmd.SetServerDetails(rtDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run")) return commands.Exec(releaseBundleUpdateCmd) } @@ -2587,7 +2575,7 @@ func releaseBundleSignCmd(c *cli.Context) error { if err != nil { return err } - releaseBundleSignCmd.SetRtDetails(rtDetails).SetReleaseBundleSignParams(params) + releaseBundleSignCmd.SetServerDetails(rtDetails).SetReleaseBundleSignParams(params) return commands.Exec(releaseBundleSignCmd) } @@ -2622,7 +2610,7 @@ func releaseBundleDistributeCmd(c *cli.Context) error { if err != nil { return err } - releaseBundleDistributeCmd.SetRtDetails(rtDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")).SetSync(c.Bool("sync")).SetMaxWaitMinutes(maxWaitMinutes) + releaseBundleDistributeCmd.SetServerDetails(rtDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")).SetSync(c.Bool("sync")).SetMaxWaitMinutes(maxWaitMinutes) return commands.Exec(releaseBundleDistributeCmd) } @@ -2652,7 +2640,7 @@ func releaseBundleDeleteCmd(c *cli.Context) error { if err != nil { return err } - distributeBundleCmd.SetQuiet(cliutils.GetQuietValue(c)).SetRtDetails(rtDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")) + distributeBundleCmd.SetQuiet(cliutils.GetQuietValue(c)).SetServerDetails(rtDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")) return commands.Exec(distributeBundleCmd) } @@ -2667,7 +2655,7 @@ func gitLfsCleanCmd(c *cli.Context) error { if err != nil { return err } - gitLfsCmd.SetConfiguration(configuration).SetRtDetails(rtDetails).SetDryRun(c.Bool("dry-run")) + gitLfsCmd.SetConfiguration(configuration).SetServerDetails(rtDetails).SetDryRun(c.Bool("dry-run")) return commands.Exec(gitLfsCmd) } @@ -2677,11 +2665,11 @@ func curlCmd(c *cli.Context) error { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } curlCommand := curl.NewCurlCommand().SetArguments(cliutils.ExtractCommand(c)) - rtDetails, err := curlCommand.GetArtifactoryDetails() + rtDetails, err := curlCommand.GetServerDetails() if err != nil { return err } - curlCommand.SetRtDetails(rtDetails) + curlCommand.SetServerDetails(rtDetails) return commands.Exec(curlCommand) } @@ -2702,14 +2690,14 @@ func pipInstallCmd(c *cli.Context) error { } // Set arg values. - rtDetails, err := pipConfig.RtDetails() + rtDetails, err := pipConfig.ServerDetails() if err != nil { return err } // Run command. pipCmd := pip.NewPipInstallCommand() - pipCmd.SetRtDetails(rtDetails).SetRepo(pipConfig.TargetRepo()).SetArgs(cliutils.ExtractCommand(c)) + pipCmd.SetServerDetails(rtDetails).SetRepo(pipConfig.TargetRepo()).SetArgs(cliutils.ExtractCommand(c)) return commands.Exec(pipCmd) } @@ -2736,7 +2724,7 @@ func repoCreateCmd(c *cli.Context) error { // Run command. repoCreateCmd := repository.NewRepoCreateCommand() - repoCreateCmd.SetTemplatePath(c.Args().Get(0)).SetRtDetails(rtDetails).SetVars(c.String("vars")) + repoCreateCmd.SetTemplatePath(c.Args().Get(0)).SetServerDetails(rtDetails).SetVars(c.String("vars")) return commands.Exec(repoCreateCmd) } @@ -2752,7 +2740,7 @@ func repoUpdateCmd(c *cli.Context) error { // Run command. repoUpdateCmd := repository.NewRepoUpdateCommand() - repoUpdateCmd.SetTemplatePath(c.Args().Get(0)).SetRtDetails(rtDetails).SetVars(c.String("vars")) + repoUpdateCmd.SetTemplatePath(c.Args().Get(0)).SetServerDetails(rtDetails).SetVars(c.String("vars")) return commands.Exec(repoUpdateCmd) } @@ -2767,7 +2755,7 @@ func repoDeleteCmd(c *cli.Context) error { } repoDeleteCmd := repository.NewRepoDeleteCommand() - repoDeleteCmd.SetRepoPattern(c.Args().Get(0)).SetRtDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) + repoDeleteCmd.SetRepoPattern(c.Args().Get(0)).SetServerDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) return commands.Exec(repoDeleteCmd) } @@ -2789,7 +2777,7 @@ func replicationCreateCmd(c *cli.Context) error { return err } replicationCreateCmd := replication.NewReplicationCreateCommand() - replicationCreateCmd.SetTemplatePath(c.Args().Get(0)).SetRtDetails(rtDetails).SetVars(c.String("vars")) + replicationCreateCmd.SetTemplatePath(c.Args().Get(0)).SetServerDetails(rtDetails).SetVars(c.String("vars")) return commands.Exec(replicationCreateCmd) } @@ -2802,7 +2790,7 @@ func replicationDeleteCmd(c *cli.Context) error { return err } replicationDeleteCmd := replication.NewReplicationDeleteCommand() - replicationDeleteCmd.SetRepoKey(c.Args().Get(0)).SetRtDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) + replicationDeleteCmd.SetRepoKey(c.Args().Get(0)).SetServerDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) return commands.Exec(replicationDeleteCmd) } @@ -2829,7 +2817,7 @@ func permissionTargetCreateCmd(c *cli.Context) error { // Run command. permissionTargetCreateCmd := permissiontarget.NewPermissionTargetCreateCommand() - permissionTargetCreateCmd.SetTemplatePath(c.Args().Get(0)).SetRtDetails(rtDetails).SetVars(c.String("vars")) + permissionTargetCreateCmd.SetTemplatePath(c.Args().Get(0)).SetServerDetails(rtDetails).SetVars(c.String("vars")) return commands.Exec(permissionTargetCreateCmd) } @@ -2845,7 +2833,7 @@ func permissionTargetUpdateCmd(c *cli.Context) error { // Run command. permissionTargetUpdateCmd := permissiontarget.NewPermissionTargetUpdateCommand() - permissionTargetUpdateCmd.SetTemplatePath(c.Args().Get(0)).SetRtDetails(rtDetails).SetVars(c.String("vars")) + permissionTargetUpdateCmd.SetTemplatePath(c.Args().Get(0)).SetServerDetails(rtDetails).SetVars(c.String("vars")) return commands.Exec(permissionTargetUpdateCmd) } @@ -2860,7 +2848,7 @@ func permissionTargetDeleteCmd(c *cli.Context) error { } permissionTargetDeleteCmd := permissiontarget.NewPermissionTargetDeleteCommand() - permissionTargetDeleteCmd.SetPermissionTargetName(c.Args().Get(0)).SetRtDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) + permissionTargetDeleteCmd.SetPermissionTargetName(c.Args().Get(0)).SetServerDetails(rtDetails).SetQuiet(cliutils.GetQuietValue(c)) return commands.Exec(permissionTargetDeleteCmd) } @@ -2891,7 +2879,7 @@ func usersCreateCmd(c *cli.Context) error { usersGroups = strings.Split(c.String("user-groups"), ",") } // Run command. - usersCreateCmd.SetRtDetails(rtDetails).SetUsers(usersList).SetUsersGroups(usersGroups).SetReplaceIfExists(c.Bool("replace")) + usersCreateCmd.SetServerDetails(rtDetails).SetUsers(usersList).SetUsersGroups(usersGroups).SetReplaceIfExists(c.Bool("replace")) return commands.Exec(usersCreateCmd) } @@ -2931,7 +2919,7 @@ func usersDeleteCmd(c *cli.Context) error { } // Run command. - usersDeleteCmd.SetRtDetails(rtDetails).SetUsers(usersNamesList) + usersDeleteCmd.SetServerDetails(rtDetails).SetUsers(usersNamesList) return commands.Exec(usersDeleteCmd) } @@ -2968,7 +2956,7 @@ func groupCreateCmd(c *cli.Context) error { // Run command. groupCreateCmd := usersmanagement.NewGroupCreateCommand() - groupCreateCmd.SetName(c.Args().Get(0)).SetRtDetails(rtDetails).SetReplaceIfExists(c.Bool("replace")) + groupCreateCmd.SetName(c.Args().Get(0)).SetServerDetails(rtDetails).SetReplaceIfExists(c.Bool("replace")) return commands.Exec(groupCreateCmd) } @@ -2984,7 +2972,7 @@ func groupAddUsersCmd(c *cli.Context) error { // Run command. groupAddUsersCmd := usersmanagement.NewGroupUpdateCommand() - groupAddUsersCmd.SetName(c.Args().Get(0)).SetUsers(strings.Split(c.Args().Get(1), ",")).SetRtDetails(rtDetails) + groupAddUsersCmd.SetName(c.Args().Get(0)).SetUsers(strings.Split(c.Args().Get(1), ",")).SetServerDetails(rtDetails) return commands.Exec(groupAddUsersCmd) } @@ -3005,7 +2993,7 @@ func groupDeleteCmd(c *cli.Context) error { // Run command. groupDeleteCmd := usersmanagement.NewGroupDeleteCommand() - groupDeleteCmd.SetName(c.Args().Get(0)).SetRtDetails(rtDetails) + groupDeleteCmd.SetName(c.Args().Get(0)).SetServerDetails(rtDetails) return commands.Exec(groupDeleteCmd) } @@ -3031,7 +3019,7 @@ func accessTokenCreateCmd(c *cli.Context) error { return err } accessTokenCreateCmd := generic.NewAccessTokenCreateCommand() - accessTokenCreateCmd.SetUserName(userName).SetRtDetails(rtDetails).SetRefreshable(c.Bool("refreshable")).SetExpiry(expiry).SetGroups(c.String("groups")).SetAudience(c.String("audience")).SetGrantAdmin(c.Bool("grant-admin")) + accessTokenCreateCmd.SetUserName(userName).SetServerDetails(rtDetails).SetRefreshable(c.Bool("refreshable")).SetExpiry(expiry).SetGroups(c.String("groups")).SetAudience(c.String("audience")).SetGrantAdmin(c.Bool("grant-admin")) err = commands.Exec(accessTokenCreateCmd) if err != nil { return err @@ -3052,47 +3040,22 @@ func validateBuildConfiguration(c *cli.Context, buildConfiguration *utils.BuildC return nil } -func offerConfig(c *cli.Context) (*config.ArtifactoryDetails, error) { - var exists bool - exists, err := config.IsArtifactoryConfExists() - if err != nil || exists { +func offerConfig(c *cli.Context) (*coreConfig.ServerDetails, error) { + confirmed, err := cliutils.ShouldOfferConfig() + if !confirmed || err != nil { return nil, err } - - var ci bool - if ci, err = clientutils.GetBoolEnvValue(coreutils.CI, false); err != nil { - return nil, err - } - var offerConfig bool - if offerConfig, err = clientutils.GetBoolEnvValue(cliutils.OfferConfig, !ci); err != nil { - return nil, err - } - if !offerConfig { - config.SaveArtifactoryConf(make([]*config.ArtifactoryDetails, 0)) - return nil, nil - } - - msg := fmt.Sprintf("To avoid this message in the future, set the %s environment variable to false.\n"+ - "The CLI commands require the Artifactory URL and authentication details\n"+ - "Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n"+ - "You can also configure these parameters later using the 'jfrog rt c' command.\n"+ - "Configure now?", cliutils.OfferConfig) - confirmed := coreutils.AskYesNo(msg, false) - if !confirmed { - config.SaveArtifactoryConf(make([]*config.ArtifactoryDetails, 0)) - return nil, nil - } - details := createArtifactoryDetailsFromOptions(c) - configCmd := commands.NewConfigCommand().SetDefaultDetails(details).SetInteractive(true).SetEncPassword(true) + details := createArtifactoryDetailsFromFlags(c) + configCmd := coreCommonCommands.NewConfigCommand().SetDefaultDetails(details).SetInteractive(true).SetEncPassword(true) err = configCmd.Config() if err != nil { return nil, err } - return configCmd.RtDetails() + return configCmd.ServerDetails() } -func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableTokens bool) (*config.ArtifactoryDetails, error) { +func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableTokens bool) (*coreConfig.ServerDetails, error) { createdDetails, err := offerConfig(c) if err != nil { return nil, err @@ -3101,7 +3064,7 @@ func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableT return createdDetails, err } - details := createArtifactoryDetailsFromOptions(c) + details := createArtifactoryDetailsFromFlags(c) // If urls or credentials were passed as options, use options as they are. // For security reasons, we'd like to avoid using part of the connection details from command options and the rest from the config. // Either use command options only or config only. @@ -3110,7 +3073,7 @@ func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableT } // Else, use details from config for requested serverId, or for default server if empty. - confDetails, err := commands.GetConfig(details.ServerId, excludeRefreshableTokens) + confDetails, err := coreCommonCommands.GetConfig(details.ServerId, excludeRefreshableTokens) if err != nil { return nil, err } @@ -3122,7 +3085,7 @@ func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableT // Create initial access token if needed. if !excludeRefreshableTokens { - err = config.CreateInitialRefreshableTokensIfNeeded(confDetails) + err = coreConfig.CreateInitialRefreshableTokensIfNeeded(confDetails) if err != nil { return nil, err } @@ -3131,31 +3094,14 @@ func createArtifactoryDetailsWithConfigOffer(c *cli.Context, excludeRefreshableT return confDetails, nil } -func createArtifactoryDetailsFromOptions(c *cli.Context) (details *config.ArtifactoryDetails) { - details = new(config.ArtifactoryDetails) - details.Url = c.String("url") - details.DistributionUrl = c.String("dist-url") - details.ApiKey = c.String("apikey") - details.User = c.String("user") - details.Password = c.String("password") - details.SshKeyPath = c.String("ssh-key-path") - details.SshPassphrase = c.String("ssh-passphrase") - details.AccessToken = c.String("access-token") - details.ClientCertPath = c.String("client-cert-path") - details.ClientCertKeyPath = c.String("client-cert-key-path") - details.ServerId = c.String("server-id") - details.InsecureTls = c.Bool("insecure-tls") - if details.ApiKey != "" && details.User != "" && details.Password == "" { - // The API Key is deprecated, use password option instead. - details.Password = details.ApiKey - details.ApiKey = "" - } - details.Url = clientutils.AddTrailingSlashIfNeeded(details.Url) - details.DistributionUrl = clientutils.AddTrailingSlashIfNeeded(details.DistributionUrl) +func createArtifactoryDetailsFromFlags(c *cli.Context) (details *coreConfig.ServerDetails) { + details = cliutils.CreateServerDetailsFromFlags(c) + details.ArtifactoryUrl = details.Url + details.Url = "" return } -func credentialsChanged(details *config.ArtifactoryDetails) bool { +func credentialsChanged(details *coreConfig.ServerDetails) bool { return details.Url != "" || details.DistributionUrl != "" || details.User != "" || details.Password != "" || details.ApiKey != "" || details.SshKeyPath != "" || details.SshPassphrase != "" || details.AccessToken != "" || details.ClientCertKeyPath != "" || details.ClientCertPath != "" @@ -3574,21 +3520,22 @@ func createBuildConfigurationWithModule(c *cli.Context) (buildConfigConfiguratio return } -func createConfigCommandConfiguration(c *cli.Context) (configCommandConfiguration *commands.ConfigCommandConfiguration, err error) { - configCommandConfiguration = new(commands.ConfigCommandConfiguration) - configCommandConfiguration.ArtDetails = createArtifactoryDetailsFromOptions(c) +// Deprecated +func createConfigCommandConfiguration(c *cli.Context) (configCommandConfiguration *coreCommonCommands.ConfigCommandConfiguration, err error) { + configCommandConfiguration = new(coreCommonCommands.ConfigCommandConfiguration) + configCommandConfiguration.ServerDetails = createArtifactoryDetailsFromFlags(c) configCommandConfiguration.EncPassword = c.BoolT("enc-password") configCommandConfiguration.Interactive = cliutils.GetInteractiveValue(c) configCommandConfiguration.BasicAuthOnly = c.Bool("basic-auth-only") return } -func validateConfigFlags(configCommandConfiguration *commands.ConfigCommandConfiguration) error { - if !configCommandConfiguration.Interactive && configCommandConfiguration.ArtDetails.Url == "" { +func validateConfigFlags(configCommandConfiguration *coreCommonCommands.ConfigCommandConfiguration) error { + if !configCommandConfiguration.Interactive && configCommandConfiguration.ServerDetails.ArtifactoryUrl == "" { return errors.New("the --url option is mandatory when the --interactive option is set to false or the CI environment variable is set to true.") } // Validate the option is not used along an access token - if configCommandConfiguration.BasicAuthOnly && configCommandConfiguration.ArtDetails.AccessToken != "" { + if configCommandConfiguration.BasicAuthOnly && configCommandConfiguration.ServerDetails.AccessToken != "" { return errors.New("the --basic-auth-only option is only supported when username and password/API key are provided") } return nil diff --git a/artifactory_test.go b/artifactory_test.go index 865c9477d..642af522f 100644 --- a/artifactory_test.go +++ b/artifactory_test.go @@ -56,7 +56,7 @@ var artifactoryCli *tests.JfrogCli // JFrog CLI for config command only (doesn't pass the --ssh-passphrase flag) var configArtifactoryCli *tests.JfrogCli -var artifactoryDetails *config.ArtifactoryDetails +var serverDetails *config.ServerDetails var artAuth auth.ServiceDetails var artHttpDetails httputils.HttpClientDetails @@ -70,25 +70,25 @@ func InitArtifactoryTests() { } func authenticate() string { - artifactoryDetails = &config.ArtifactoryDetails{Url: clientutils.AddTrailingSlashIfNeeded(*tests.RtUrl), SshKeyPath: *tests.RtSshKeyPath, SshPassphrase: *tests.RtSshPassphrase} + serverDetails = &config.ServerDetails{ArtifactoryUrl: clientutils.AddTrailingSlashIfNeeded(*tests.RtUrl), SshKeyPath: *tests.RtSshKeyPath, SshPassphrase: *tests.RtSshPassphrase} cred := "--url=" + *tests.RtUrl - if !fileutils.IsSshUrl(artifactoryDetails.Url) { + if !fileutils.IsSshUrl(serverDetails.ArtifactoryUrl) { if *tests.RtApiKey != "" { - artifactoryDetails.ApiKey = *tests.RtApiKey + serverDetails.ApiKey = *tests.RtApiKey } else if *tests.RtAccessToken != "" { - artifactoryDetails.AccessToken = *tests.RtAccessToken + serverDetails.AccessToken = *tests.RtAccessToken } else { - artifactoryDetails.User = *tests.RtUser - artifactoryDetails.Password = *tests.RtPassword + serverDetails.User = *tests.RtUser + serverDetails.Password = *tests.RtPassword } } cred += getArtifactoryTestCredentials() var err error - if artAuth, err = artifactoryDetails.CreateArtAuthConfig(); err != nil { + if artAuth, err = serverDetails.CreateArtAuthConfig(); err != nil { coreutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Artifactory: " + err.Error())) } - artifactoryDetails.Url = artAuth.GetUrl() - artifactoryDetails.SshUrl = artAuth.GetSshUrl() + serverDetails.ArtifactoryUrl = artAuth.GetUrl() + serverDetails.SshUrl = artAuth.GetSshUrl() artHttpDetails = artAuth.CreateHttpClientDetails() return cred } @@ -103,7 +103,7 @@ func createConfigJfrogCLI(cred string) *tests.JfrogCli { } func getArtifactoryTestCredentials() string { - if fileutils.IsSshUrl(artifactoryDetails.Url) { + if fileutils.IsSshUrl(serverDetails.ArtifactoryUrl) { return getSshCredentials() } if *tests.RtApiKey != "" { @@ -182,7 +182,7 @@ func TestArtifactoryUploadPathWithSpecialCharsAsNoRegex(t *testing.T) { func TestArtifactoryEmptyBuild(t *testing.T) { initArtifactoryTest(t) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) buildNumber := "5" // Try to upload with non existent pattern @@ -197,7 +197,7 @@ func TestArtifactoryEmptyBuild(t *testing.T) { err = artifactoryCli.Exec("build-publish", tests.RtBuildName1, buildNumber) assert.NoError(t, err) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -493,7 +493,7 @@ func verifyUsersExistInArtifactory(csvFilePath string, t *testing.T) { break } user, password := record[0], record[1] - err = tests.NewJfrogCli(execMain, "jfrog rt", "--url="+artifactoryDetails.Url+" --user="+user+" --password="+password).Exec("ping") + err = tests.NewJfrogCli(execMain, "jfrog rt", "--url="+serverDetails.ArtifactoryUrl+" --user="+user+" --password="+password).Exec("ping") assert.NoError(t, err) } @@ -930,7 +930,7 @@ func TestArtifactorySelfSignedCert(t *testing.T) { defer fileutils.RemoveTempDir(tempDirPath) os.Setenv(coreutils.HomeDir, tempDirPath) os.Setenv(tests.HttpsProxyEnvVar, "1024") - go cliproxy.StartLocalReverseHttpProxy(artifactoryDetails.Url, false) + go cliproxy.StartLocalReverseHttpProxy(serverDetails.ArtifactoryUrl, false) // The two certificate files are created by the reverse proxy on startup in the current directory. defer os.Remove(certificate.KEY_FILE) @@ -941,13 +941,13 @@ func TestArtifactorySelfSignedCert(t *testing.T) { fileSpec := spec.NewBuilder().Pattern(tests.RtRepo1 + "/*.zip").Recursive(true).BuildSpec() assert.NoError(t, err) - parsedUrl, err := url.Parse(artifactoryDetails.Url) - artifactoryDetails.Url = "https://127.0.0.1:" + cliproxy.GetProxyHttpsPort() + parsedUrl.RequestURI() + parsedUrl, err := url.Parse(serverDetails.ArtifactoryUrl) + serverDetails.ArtifactoryUrl = "https://127.0.0.1:" + cliproxy.GetProxyHttpsPort() + parsedUrl.RequestURI() // The server is using self-signed certificates // Without loading the certificates (or skipping verification) we expect all actions to fail due to error: "x509: certificate signed by unknown authority" searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(fileSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) reader, err := searchCmd.Search() if reader != nil { assert.NoError(t, reader.Close()) @@ -956,16 +956,16 @@ func TestArtifactorySelfSignedCert(t *testing.T) { assert.True(t, isUrlErr, "Expected a connection failure, since reverse proxy didn't load self-signed-certs. Connection however is successful", err) // Set insecureTls to true and run again. We expect the command to succeed. - artifactoryDetails.InsecureTls = true + serverDetails.InsecureTls = true searchCmd = generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(fileSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) reader, err = searchCmd.Search() assert.NoError(t, err) assert.NoError(t, reader.Close()) // Set insecureTls back to false. // Copy the server certificates to the CLI security dir and run again. We expect the command to succeed. - artifactoryDetails.InsecureTls = false + serverDetails.InsecureTls = false certsPath, err := coreutils.GetJfrogCertsDir() assert.NoError(t, err) err = fileutils.CopyFile(certsPath, certificate.KEY_FILE) @@ -973,12 +973,12 @@ func TestArtifactorySelfSignedCert(t *testing.T) { err = fileutils.CopyFile(certsPath, certificate.CERT_FILE) assert.NoError(t, err) searchCmd = generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(fileSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) reader, err = searchCmd.Search() assert.NoError(t, err) assert.NoError(t, reader.Close()) - artifactoryDetails.Url = artAuth.GetUrl() + serverDetails.ArtifactoryUrl = artAuth.GetUrl() cleanArtifactoryTest() } @@ -991,7 +991,7 @@ func TestArtifactoryClientCert(t *testing.T) { defer fileutils.RemoveTempDir(tempDirPath) os.Setenv(coreutils.HomeDir, tempDirPath) os.Setenv(tests.HttpsProxyEnvVar, "1025") - go cliproxy.StartLocalReverseHttpProxy(artifactoryDetails.Url, true) + go cliproxy.StartLocalReverseHttpProxy(serverDetails.ArtifactoryUrl, true) // The two certificate files are created by the reverse proxy on startup in the current directory. defer os.Remove(certificate.KEY_FILE) @@ -1002,14 +1002,14 @@ func TestArtifactoryClientCert(t *testing.T) { fileSpec := spec.NewBuilder().Pattern(tests.RtRepo1 + "/*.zip").Recursive(true).BuildSpec() assert.NoError(t, err) - parsedUrl, err := url.Parse(artifactoryDetails.Url) - artifactoryDetails.Url = "https://127.0.0.1:" + cliproxy.GetProxyHttpsPort() + parsedUrl.RequestURI() - artifactoryDetails.InsecureTls = true + parsedUrl, err := url.Parse(serverDetails.ArtifactoryUrl) + serverDetails.ArtifactoryUrl = "https://127.0.0.1:" + cliproxy.GetProxyHttpsPort() + parsedUrl.RequestURI() + serverDetails.InsecureTls = true // The server is requiring client certificates // Without loading a valid client certificate, we expect all actions to fail due to error: "tls: bad certificate" searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(fileSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) reader, err := searchCmd.Search() if reader != nil { assert.NoError(t, reader.Close()) @@ -1018,21 +1018,21 @@ func TestArtifactoryClientCert(t *testing.T) { assert.True(t, isUrlErr, "Expected a connection failure, since client did not provide a client certificate. Connection however is successful") // Inject client certificates, we expect the search to succeed - artifactoryDetails.ClientCertPath = certificate.CERT_FILE - artifactoryDetails.ClientCertKeyPath = certificate.KEY_FILE + serverDetails.ClientCertPath = certificate.CERT_FILE + serverDetails.ClientCertKeyPath = certificate.KEY_FILE searchCmd = generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(fileSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) reader, err = searchCmd.Search() if reader != nil { assert.NoError(t, reader.Close()) } assert.NoError(t, err) - artifactoryDetails.Url = artAuth.GetUrl() - artifactoryDetails.InsecureTls = false - artifactoryDetails.ClientCertPath = "" - artifactoryDetails.ClientCertKeyPath = "" + serverDetails.ArtifactoryUrl = artAuth.GetUrl() + serverDetails.InsecureTls = false + serverDetails.ClientCertPath = "" + serverDetails.ClientCertKeyPath = "" cleanArtifactoryTest() } @@ -1079,7 +1079,7 @@ func getExternalIP() (string, error) { // We decide which var to set by the rtUrl scheme. func TestArtifactoryProxy(t *testing.T) { initArtifactoryTest(t) - rtUrl, err := url.Parse(artifactoryDetails.Url) + rtUrl, err := url.Parse(serverDetails.ArtifactoryUrl) assert.NoError(t, err) var proxyTestArgs []string var httpProxyEnv string @@ -1128,7 +1128,7 @@ func testArtifactoryProxy(t *testing.T, isHttps bool) { authenticate() proxyRtUrl := prepareArtifactoryUrlForProxyTest(t) spec := spec.NewBuilder().Pattern(tests.RtRepo1 + "/*.zip").Recursive(true).BuildSpec() - artifactoryDetails.Url = proxyRtUrl + serverDetails.ArtifactoryUrl = proxyRtUrl checkForErrDueToMissingProxy(spec, t) var port string if isHttps { @@ -1142,17 +1142,17 @@ func testArtifactoryProxy(t *testing.T, isHttps bool) { err := checkIfServerIsUp(port, "http", false) assert.NoError(t, err) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(spec) + searchCmd.SetServerDetails(serverDetails).SetSpec(spec) reader, err := searchCmd.Search() assert.NoError(t, err) if reader != nil { assert.NoError(t, reader.Close()) } - artifactoryDetails.Url = artAuth.GetUrl() + serverDetails.ArtifactoryUrl = artAuth.GetUrl() } func prepareArtifactoryUrlForProxyTest(t *testing.T) string { - rtUrl, err := url.Parse(artifactoryDetails.Url) + rtUrl, err := url.Parse(serverDetails.ArtifactoryUrl) assert.NoError(t, err) rtHost, port, err := net.SplitHostPort(rtUrl.Host) if rtHost == "localhost" || rtHost == "127.0.0.1" { @@ -1165,7 +1165,7 @@ func prepareArtifactoryUrlForProxyTest(t *testing.T) string { func checkForErrDueToMissingProxy(spec *spec.SpecFiles, t *testing.T) { searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(spec) + searchCmd.SetServerDetails(serverDetails).SetSpec(spec) reader, err := searchCmd.Search() if reader != nil { assert.NoError(t, reader.Close()) @@ -1852,7 +1852,7 @@ func testArtifactoryDeleteFoldersNoSpec(t *testing.T, contentOnly bool) { } else { expectedStatusCode = http.StatusNotFound } - resp, body, _, err := client.SendGet(artifactoryDetails.Url+"api/storage/"+tests.RtRepo1+"/test_resources", true, artHttpDetails) + resp, body, _, err := client.SendGet(serverDetails.ArtifactoryUrl+"api/storage/"+tests.RtRepo1+"/test_resources", true, artHttpDetails) assert.NoError(t, err) assert.Equal(t, expectedStatusCode, resp.StatusCode, "test_resources shouldn't be deleted: "+tests.RtRepo1+"/test_resources/ "+string(body)) @@ -1997,7 +1997,7 @@ func TestArtifactoryDeletePrefixFiles(t *testing.T) { // Prepare search command searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).Recursive(true) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) searchCmd.SetSpec(searchSpecBuilder.BuildSpec()) // Upload files @@ -2038,7 +2038,7 @@ func TestArtifactoryDeleteByProps(t *testing.T) { // Prepare search command searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).Recursive(true) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) searchCmd.SetSpec(searchSpecBuilder.BuildSpec()) // Delete all artifacts with D=5 but without c=3 @@ -2377,7 +2377,7 @@ func testChecksumDownload(t *testing.T, outFileName string) { func TestArtifactoryDownloadByPatternAndBuildUsingSpec(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpec) assert.NoError(t, err) // Upload files with buildName and buildNumber @@ -2401,14 +2401,14 @@ func TestArtifactoryDownloadByPatternAndBuildUsingSpec(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryGenericBuildnameAndNumberFromEnv(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpec) assert.NoError(t, err) // Upload files with buildName and buildNumber @@ -2439,14 +2439,14 @@ func TestArtifactoryGenericBuildnameAndNumberFromEnv(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryDownloadByBuildNoPatternUsingSpec(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpecNoPattern) assert.NoError(t, err) // Upload files with buildName and buildNumber @@ -2470,7 +2470,7 @@ func TestArtifactoryDownloadByBuildNoPatternUsingSpec(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -2478,7 +2478,7 @@ func prepareDownloadByBuildWithDependenciesTests(t *testing.T) { // Init initArtifactoryTest(t) buildNumber := "1337" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) // Upload files with buildName and buildNumber specFileA, err := tests.CreateSpec(tests.SplitUploadSpecA) @@ -2529,7 +2529,7 @@ func TestArtifactoryDownloadByBuildWithDependenciesSpecNoPattern(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -2558,7 +2558,7 @@ func TestArtifactoryDownloadByBuildWithDependencies(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -2567,7 +2567,7 @@ func TestArtifactoryDownloadByBuildWithDependencies(t *testing.T) { func TestArtifactoryDownloadArtifactDoesntExistInBuild(t *testing.T) { initArtifactoryTest(t) buildNumber := "10" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpecNoBuildNumber) assert.NoError(t, err) // Upload a file @@ -2584,7 +2584,7 @@ func TestArtifactoryDownloadArtifactDoesntExistInBuild(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -2593,8 +2593,8 @@ func TestArtifactoryDownloadArtifactDoesntExistInBuild(t *testing.T) { func TestArtifactoryDownloadByShaAndBuild(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB, buildNumberC := "10", "11", "12" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpecNoBuildNumber) assert.NoError(t, err) @@ -2616,8 +2616,8 @@ func TestArtifactoryDownloadByShaAndBuild(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) cleanArtifactoryTest() } @@ -2626,8 +2626,8 @@ func TestArtifactoryDownloadByShaAndBuild(t *testing.T) { func TestArtifactoryDownloadByShaAndBuildName(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB, buildNumberC := "10", "11", "12" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpecNoBuildNumber) assert.NoError(t, err) @@ -2649,15 +2649,15 @@ func TestArtifactoryDownloadByShaAndBuildName(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryDownloadByBuildUsingSimpleDownload(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) // Upload files with buildName and buildNumber specFileA, err := tests.CreateSpec(tests.SplitUploadSpecA) @@ -2681,14 +2681,14 @@ func TestArtifactoryDownloadByBuildUsingSimpleDownload(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryDownloadByBuildNoPatternUsingSimpleDownload(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) // Upload files with buildName and buildNumber specFileA, err := tests.CreateSpec(tests.SplitUploadSpecA) @@ -2712,7 +2712,7 @@ func TestArtifactoryDownloadByBuildNoPatternUsingSimpleDownload(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -3003,8 +3003,8 @@ func validateSortLimitWithSymLink(localLinkPath, localFilePath string, t *testin func TestArtifactoryDownloadByShaAndBuildNameWithSort(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB, buildNumberC := "10", "11", "12" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) specFile, err := tests.CreateSpec(tests.BuildDownloadSpecNoBuildNumberWithSort) assert.NoError(t, err) // Upload 3 similar files to 2 different builds @@ -3025,15 +3025,15 @@ func TestArtifactoryDownloadByShaAndBuildNameWithSort(t *testing.T) { assert.NoError(t, err) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryCopyByBuildUsingSpec(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.CopyByBuildSpec) assert.NoError(t, err) // Upload files with buildName and buildNumber: a* uploaded with build number "10", b* uploaded with build number "11" @@ -3057,14 +3057,14 @@ func TestArtifactoryCopyByBuildUsingSpec(t *testing.T) { verifyExistInArtifactory(tests.GetBuildCopyExpected(), cpMvDlByBuildAssertSpec, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryCopyByBuildPatternAllUsingSpec(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.CopyByBuildPatternAllSpec) assert.NoError(t, err) // Upload files with buildName and buildNumber: a* uploaded with build number "10", b* uploaded with build number "11" @@ -3088,7 +3088,7 @@ func TestArtifactoryCopyByBuildPatternAllUsingSpec(t *testing.T) { verifyExistInArtifactory(tests.GetBuildCopyExpected(), cpMvDlByBuildAssertSpec, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -3122,7 +3122,7 @@ func TestArtifactorySortByCreated(t *testing.T) { // Prepare search command searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).SortBy([]string{"created"}).SortOrder("asc").Limit(3) searchCmd.SetSpec(searchSpecBuilder.BuildSpec()) reader, err := searchCmd.Search() @@ -3190,7 +3190,7 @@ func TestArtifactoryOffset(t *testing.T) { func TestArtifactoryCopyByBuildOverridingByInlineFlag(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.CopyByBuildSpec) assert.NoError(t, err) @@ -3216,14 +3216,14 @@ func TestArtifactoryCopyByBuildOverridingByInlineFlag(t *testing.T) { verifyExistInArtifactory(tests.GetBuildCopyExpected(), cpMvDlByBuildAssertSpec, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryMoveByBuildUsingFlags(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.CopyByBuildSpec) assert.NoError(t, err) @@ -3249,7 +3249,7 @@ func TestArtifactoryMoveByBuildUsingFlags(t *testing.T) { verifyExistInArtifactory(tests.GetBuildMoveExpected(), cpMvDlByBuildAssertSpec, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -3360,7 +3360,7 @@ func TestArtifactoryMoveExclusionsBySpec(t *testing.T) { func TestArtifactoryDeleteByLatestBuild(t *testing.T) { initArtifactoryTest(t) buildNumberA, buildNumberB := "10", "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) specFile, err := tests.CreateSpec(tests.CopyByBuildSpec) assert.NoError(t, err) @@ -3386,7 +3386,7 @@ func TestArtifactoryDeleteByLatestBuild(t *testing.T) { verifyExistInArtifactory(tests.GetBuildDeleteExpected(), cpMvDlByBuildAssertSpec, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -3470,7 +3470,7 @@ func TestArtifactoryBuildDiscard(t *testing.T) { assert.Zero(t, jsonResponse, "Incorrect operation of build-discard by max-days.") //Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -3509,7 +3509,7 @@ func TestArtifactorySearchIncludeDir(t *testing.T) { // Prepare search command searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).Recursive(true) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) searchCmd.SetSpec(searchSpecBuilder.IncludeDirs(false).BuildSpec()) reader, err := searchCmd.Search() assert.NoError(t, err) @@ -3569,7 +3569,7 @@ func TestArtifactorySearchProps(t *testing.T) { // Prepare search command searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).Recursive(true) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) // Search artifacts with c=3 searchCmd.SetSpec(searchSpecBuilder.Props("c=3").BuildSpec()) @@ -3721,7 +3721,7 @@ func TestArtifactoryDeleteExcludeProps(t *testing.T) { // Prepare search command searchSpecBuilder := spec.NewBuilder().Pattern(tests.RtRepo1).Recursive(true) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails) + searchCmd.SetServerDetails(serverDetails) // Delete all artifacts without c=1 but keep dirs that has at least one artifact with c=1 props artifactoryCli.Exec("delete", tests.RtRepo1+"/*", "--exclude-props=c=1") @@ -3746,7 +3746,7 @@ func TestArtifactoryDeleteExcludeProps(t *testing.T) { } func getAllBuildsByBuildName(client *httpclient.HttpClient, buildName string, t *testing.T, expectedHttpStatusCode int) buildsApiResponseStruct { - resp, body, _, _ := client.SendGet(artifactoryDetails.Url+"api/build/"+buildName, true, artHttpDetails) + resp, body, _, _ := client.SendGet(serverDetails.ArtifactoryUrl+"api/build/"+buildName, true, artHttpDetails) assert.Equal(t, expectedHttpStatusCode, resp.StatusCode, "Failed retrieving build information from artifactory.") buildsApiResponse := &buildsApiResponseStruct{} @@ -3830,7 +3830,7 @@ func execListRepoRest() ([]string, error) { } // Send get request - resp, body, _, err := client.SendGet(artifactoryDetails.Url+"api/repositories", true, artHttpDetails) + resp, body, _, err := client.SendGet(serverDetails.ArtifactoryUrl+"api/repositories", true, artHttpDetails) if err != nil { return nil, err } @@ -3868,7 +3868,7 @@ func execListBuildNamesRest() ([]string, error) { } // Send get request - resp, body, _, err := client.SendGet(artifactoryDetails.Url+"api/build", true, artHttpDetails) + resp, body, _, err := client.SendGet(serverDetails.ArtifactoryUrl+"api/build", true, artHttpDetails) if err != nil { return nil, err } @@ -3913,7 +3913,7 @@ func execCreateRepoRest(repoConfig, repoName string) { log.Error(err) os.Exit(1) } - resp, body, err := client.SendPut(artifactoryDetails.Url+"api/repositories/"+repoName, content, artHttpDetails) + resp, body, err := client.SendPut(serverDetails.ArtifactoryUrl+"api/repositories/"+repoName, content, artHttpDetails) if err != nil { log.Error(err) os.Exit(1) @@ -3934,7 +3934,7 @@ func createRequiredRepos() { func cleanUpOldBuilds() { tests.CleanUpOldItems(tests.GetBuildNames(), execListBuildNamesRest, func(buildName string) { - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) log.Info("Build", buildName, "deleted.") }) } @@ -3981,13 +3981,13 @@ func cleanArtifactory() { os.Exit(1) } deleteSpec, _ := spec.CreateSpecFromFile(deleteSpecFile, nil) - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) } func searchInArtifactory(specFile string, t *testing.T) ([]utils.SearchResult, error) { searchSpec, _ := spec.CreateSpecFromFile(specFile, nil) searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(searchSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec) reader, err := searchCmd.Search() assert.NoError(t, err) var resultItems []utils.SearchResult @@ -4020,7 +4020,7 @@ func verifyDoesntExistInArtifactory(specFile string, t *testing.T) { func verifyExistInArtifactoryByProps(expected []string, pattern, props string, t *testing.T) { searchSpec := spec.NewBuilder().Pattern(pattern).Props(props).Recursive(true).BuildSpec() searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(searchSpec) + searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec) reader, err := searchCmd.Search() assert.NoError(t, err) var resultItems []utils.SearchResult @@ -4041,7 +4041,7 @@ func isRepoExist(repoName string) bool { log.Error(err) os.Exit(1) } - resp, _, _, err := client.SendGet(artifactoryDetails.Url+tests.RepoDetailsUrl+repoName, true, artHttpDetails) + resp, _, _, err := client.SendGet(serverDetails.ArtifactoryUrl+tests.RepoDetailsUrl+repoName, true, artHttpDetails) if err != nil { log.Error(err) os.Exit(1) @@ -4217,7 +4217,7 @@ func validateJcenterRemoteDetails(t *testing.T, downloadPath, expectedRemotePath func TestVcsProps(t *testing.T) { initArtifactoryTest(t) - defer inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) testDir := initVcsTestDir(t) artifactoryCli.Exec("upload", filepath.Join(testDir, "*"), tests.RtRepo1, "--flat=false", "--build-name="+tests.RtBuildName1, "--build-number=2020") resultItems := searchItemsInArtifactory(t, tests.SearchRepo1ByInSuffix) @@ -4287,7 +4287,7 @@ func TestArtifactoryReplicationCreate(t *testing.T) { assert.NoError(t, err) // Validate create replication - servicesManager, err := utils.CreateServiceManager(artifactoryDetails, false) + servicesManager, err := utils.CreateServiceManager(serverDetails, false) assert.NoError(t, err) result, err := servicesManager.GetReplication(tests.RtRepo1) assert.NoError(t, err) @@ -4448,7 +4448,7 @@ func TestRefreshableTokens(t *testing.T) { } func setRefreshTokenInConfig(t *testing.T, serverId, token string) error { - details, err := config.GetAllArtifactoryConfigs() + details, err := config.GetAllServersConfigs() if err != nil { assert.NoError(t, err) return err @@ -4458,12 +4458,12 @@ func setRefreshTokenInConfig(t *testing.T, serverId, token string) error { server.SetRefreshToken(token) } } - assert.NoError(t, config.SaveArtifactoryConf(details)) + assert.NoError(t, config.SaveServersConf(details)) return nil } func setPasswordInConfig(t *testing.T, serverId, password string) error { - details, err := config.GetAllArtifactoryConfigs() + details, err := config.GetAllServersConfigs() if err != nil { assert.NoError(t, err) return err @@ -4473,12 +4473,12 @@ func setPasswordInConfig(t *testing.T, serverId, password string) error { server.SetPassword(password) } } - assert.NoError(t, config.SaveArtifactoryConf(details)) + assert.NoError(t, config.SaveServersConf(details)) return nil } func getTokensFromConfig(t *testing.T, serverId string) (accessToken, refreshToken string, err error) { - details, err := config.GetArtifactorySpecificConfig(serverId, false, false) + details, err := config.GetSpecificConfig(serverId, false, false) if err != nil { assert.NoError(t, err) return "", "", err diff --git a/bintray/cli.go b/bintray/cli.go index 121391a6d..05df5e150 100644 --- a/bintray/cli.go +++ b/bintray/cli.go @@ -54,7 +54,7 @@ func GetCommands() []cli.Command { Name: "config", Flags: getConfigFlags(), Aliases: []string{"c"}, - Usage: configdocs.Description, + Description: configdocs.Description, HelpName: corecommon.CreateUsage("bt config", configdocs.Description, configdocs.Usage), ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), @@ -66,7 +66,7 @@ func GetCommands() []cli.Command { Name: "upload", Flags: getUploadFlags(), Aliases: []string{"u"}, - Usage: uploaddocs.Description, + Description: uploaddocs.Description, HelpName: corecommon.CreateUsage("bt upload", uploaddocs.Description, uploaddocs.Usage), UsageText: uploaddocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -79,7 +79,7 @@ func GetCommands() []cli.Command { Name: "download-file", Flags: getDownloadFileFlags(), Aliases: []string{"dlf"}, - Usage: downloadfile.Description, + Description: downloadfile.Description, HelpName: corecommon.CreateUsage("bt download-file", downloadfile.Description, downloadfile.Usage), UsageText: downloadfile.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -92,7 +92,7 @@ func GetCommands() []cli.Command { Name: "download-ver", Flags: getDownloadVersionFlags(), Aliases: []string{"dlv"}, - Usage: downloadver.Description, + Description: downloadver.Description, HelpName: corecommon.CreateUsage("bt download-ver", downloadver.Description, downloadver.Usage), UsageText: downloadver.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -105,7 +105,7 @@ func GetCommands() []cli.Command { Name: "package-show", Flags: getFlags(), Aliases: []string{"ps"}, - Usage: packageshow.Description, + Description: packageshow.Description, HelpName: corecommon.CreateUsage("bt package-show", packageshow.Description, packageshow.Usage), UsageText: packageshow.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -118,7 +118,7 @@ func GetCommands() []cli.Command { Name: "package-create", Flags: getCreateAndUpdatePackageFlags(), Aliases: []string{"pc"}, - Usage: packagecreate.Description, + Description: packagecreate.Description, HelpName: corecommon.CreateUsage("bt package-create", packagecreate.Description, packagecreate.Usage), UsageText: packagecreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -131,7 +131,7 @@ func GetCommands() []cli.Command { Name: "package-update", Flags: getCreateAndUpdatePackageFlags(), Aliases: []string{"pu"}, - Usage: packageupdate.Description, + Description: packageupdate.Description, HelpName: corecommon.CreateUsage("bt package-update", packageupdate.Description, packageupdate.Usage), UsageText: packageupdate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -144,7 +144,7 @@ func GetCommands() []cli.Command { Name: "package-delete", Flags: getDeletePackageAndVersionFlags(), Aliases: []string{"pd"}, - Usage: packagedelete.Description, + Description: packagedelete.Description, HelpName: corecommon.CreateUsage("bt package-delete", packagedelete.Description, packagedelete.Usage), UsageText: packagedelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -157,7 +157,7 @@ func GetCommands() []cli.Command { Name: "version-show", Flags: getFlags(), Aliases: []string{"vs"}, - Usage: versionshow.Description, + Description: versionshow.Description, HelpName: corecommon.CreateUsage("bt version-show", versionshow.Description, versionshow.Usage), UsageText: versionshow.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -170,7 +170,7 @@ func GetCommands() []cli.Command { Name: "version-create", Flags: getCreateAndUpdateVersionFlags(), Aliases: []string{"vc"}, - Usage: versioncreate.Description, + Description: versioncreate.Description, HelpName: corecommon.CreateUsage("bt version-create", versioncreate.Description, versioncreate.Usage), UsageText: versioncreate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -183,7 +183,7 @@ func GetCommands() []cli.Command { Name: "version-update", Flags: getCreateAndUpdateVersionFlags(), Aliases: []string{"vu"}, - Usage: versionupdate.Description, + Description: versionupdate.Description, HelpName: corecommon.CreateUsage("bt version-update", versionupdate.Description, versionupdate.Usage), UsageText: versionupdate.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -196,7 +196,7 @@ func GetCommands() []cli.Command { Name: "version-delete", Flags: getDeletePackageAndVersionFlags(), Aliases: []string{"vd"}, - Usage: versiondelete.Description, + Description: versiondelete.Description, HelpName: corecommon.CreateUsage("bt version-delete", versiondelete.Description, versiondelete.Usage), UsageText: versiondelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -209,7 +209,7 @@ func GetCommands() []cli.Command { Name: "version-publish", Flags: getFlags(), Aliases: []string{"vp"}, - Usage: versionpublish.Description, + Description: versionpublish.Description, HelpName: corecommon.CreateUsage("bt version-publish", versionpublish.Description, versionpublish.Usage), UsageText: versionpublish.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -222,7 +222,7 @@ func GetCommands() []cli.Command { Name: "entitlements", Flags: getEntitlementsFlags(), Aliases: []string{"ent"}, - Usage: entitlementsdocs.Description, + Description: entitlementsdocs.Description, HelpName: corecommon.CreateUsage("bt entitlements", entitlementsdocs.Description, entitlementsdocs.Usage), UsageText: entitlementsdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -235,7 +235,7 @@ func GetCommands() []cli.Command { Name: "access-keys", Flags: getAccessKeysFlags(), Aliases: []string{"acc-keys"}, - Usage: accesskeysdoc.Description, + Description: accesskeysdoc.Description, HelpName: corecommon.CreateUsage("bt access-keys", accesskeysdoc.Description, accesskeysdoc.Usage), UsageText: accesskeysdoc.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -248,7 +248,7 @@ func GetCommands() []cli.Command { Name: "url-sign", Flags: getUrlSigningFlags(), Aliases: []string{"us"}, - Usage: urlsign.Description, + Description: urlsign.Description, HelpName: corecommon.CreateUsage("bt url-sign", urlsign.Description, urlsign.Usage), UsageText: urlsign.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -261,7 +261,7 @@ func GetCommands() []cli.Command { Name: "gpg-sign-file", Flags: getGpgSigningFlags(), Aliases: []string{"gsf"}, - Usage: gpgsignfile.Description, + Description: gpgsignfile.Description, HelpName: corecommon.CreateUsage("bt gpg-sign-file", gpgsignfile.Description, gpgsignfile.Usage), UsageText: gpgsignfile.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -274,7 +274,7 @@ func GetCommands() []cli.Command { Name: "gpg-sign-ver", Flags: getGpgSigningFlags(), Aliases: []string{"gsv"}, - Usage: gpgsignver.Description, + Description: gpgsignver.Description, HelpName: corecommon.CreateUsage("bt gpg-sign-ver", gpgsignver.Description, gpgsignver.Usage), UsageText: gpgsignver.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -287,7 +287,7 @@ func GetCommands() []cli.Command { Name: "logs", Flags: getFlags(), Aliases: []string{"l"}, - Usage: logsdocs.Description, + Description: logsdocs.Description, HelpName: corecommon.CreateUsage("bt logs", logsdocs.Description, logsdocs.Usage), UsageText: logsdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -300,7 +300,7 @@ func GetCommands() []cli.Command { Name: "stream", Flags: getStreamFlags(), Aliases: []string{"st"}, - Usage: streamdocs.Description, + Description: streamdocs.Description, HelpName: corecommon.CreateUsage("bt stream", streamdocs.Description, streamdocs.Usage), UsageText: streamdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -313,7 +313,7 @@ func GetCommands() []cli.Command { Name: "maven-central-sync", Flags: getMavenCentralSyncFlags(), Aliases: []string{"mcs"}, - Usage: msdocs.Description, + Description: msdocs.Description, HelpName: corecommon.CreateUsage("bt maven-central-sync", msdocs.Description, msdocs.Usage), UsageText: msdocs.Arguments, ArgsUsage: common.CreateEnvVars(), diff --git a/buildinfo_test.go b/buildinfo_test.go index 0fea0dc97..8a250dae5 100644 --- a/buildinfo_test.go +++ b/buildinfo_test.go @@ -30,7 +30,7 @@ const ModuleNameJFrogTest = "jfrog-test" func TestBuildAddDependenciesFromHomeDir(t *testing.T) { initArtifactoryTest(t) // Clean old build tests if exists - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) fileName := "cliTestFile.txt" testFileRelPath, testFileAbs := createFileInHomeDir(t, fileName) @@ -60,7 +60,7 @@ func TestBuildPromote(t *testing.T) { // Promote build to Repo1 using build name and build number as args. assert.NoError(t, artifactoryCli.Exec("build-promote", tests.RtBuildName1, buildNumberA, tests.RtRepo1, fmt.Sprintf("--props=%s=%s;%s=%s", key1, value1, key2, value2))) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumberA) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumberA) if err != nil { assert.NoError(t, err) return @@ -81,7 +81,7 @@ func TestBuildPromote(t *testing.T) { defer os.Unsetenv(coreutils.BuildNumber) assert.NoError(t, artifactoryCli.Exec("build-promote", tests.RtRepo2, fmt.Sprintf("--props=%s=%s;%s=%s", key1, value1, key2, value2))) - publishedBuildInfo, found, err = tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumberA) + publishedBuildInfo, found, err = tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumberA) if err != nil { assert.NoError(t, err) return @@ -146,7 +146,7 @@ func validateArtifactsProperties(resultItems []rtutils.ResultItem, t *testing.T, func TestBuildAddDependenciesDryRun(t *testing.T) { initArtifactoryTest(t) // Clean old build tests if exists - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) err := utils.RemoveBuildDir(tests.RtBuildName1, "1") assert.NoError(t, err) @@ -166,7 +166,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) { files, _ := ioutil.ReadDir(buildDir) assert.Zero(t, len(files), "'rt bad' command with dry-run failed. The dry-run option has no effect.") - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) os.Chdir(wd) cleanArtifactoryTest() } @@ -175,7 +175,7 @@ func TestBuildPublishDryRun(t *testing.T) { initArtifactoryTest(t) buildNumber := "11" // Clean old build tests if exists. - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, buildNumber)) // Upload files with build name & number. @@ -190,7 +190,7 @@ func TestBuildPublishDryRun(t *testing.T) { // Verify build dir is not empty. assert.NotEmpty(t, getFilesFromBuildDir(t, tests.RtBuildName1, buildNumber)) // Verify build was not published. - _, found, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumber) + _, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) if err != nil { assert.NoError(t, err) return @@ -205,7 +205,7 @@ func TestBuildPublishDryRun(t *testing.T) { // Verify build dir is empty assert.Empty(t, getFilesFromBuildDir(t, tests.RtBuildName1, buildNumber)) // Verify build was published - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) if err != nil { assert.NoError(t, err) return @@ -217,7 +217,7 @@ func TestBuildPublishDryRun(t *testing.T) { buildInfo := publishedBuildInfo.BuildInfo validateBuildInfo(buildInfo, t, 0, 9, tests.RtBuildName1) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -236,8 +236,8 @@ func TestBuildAppend(t *testing.T) { buildNumber2 := "13" // Clean old builds tests if exists - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) // Publish build RtBuildName1/buildNumber1 err := artifactoryCli.WithoutCredentials().Exec("bce", tests.RtBuildName1, buildNumber1) @@ -265,7 +265,7 @@ func TestBuildAppend(t *testing.T) { assert.NoError(t, err) // Check published build info - buildInfo, _, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName2, buildNumber2) + buildInfo, _, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName2, buildNumber2) assert.NoError(t, err) assert.NotNil(t, buildInfo) assert.Len(t, buildInfo.BuildInfo.Modules, 1) @@ -273,15 +273,15 @@ func TestBuildAppend(t *testing.T) { assert.Equal(t, tests.RtBuildName1+"/"+buildNumber1, module.Id) // Clean builds - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName2, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName2, artHttpDetails) cleanArtifactoryTest() } func TestBuildAddDependencies(t *testing.T) { initArtifactoryTest(t) // Clean old build tests if exists - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) allFiles := []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"} var badTests = []buildAddDepsBuildInfoTestParams{ @@ -316,7 +316,7 @@ func TestBuildAddDependencies(t *testing.T) { validateBuildAddDepsBuildInfo(t, badTest) utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber) } - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -332,7 +332,7 @@ func TestArtifactoryPublishAndGetBuildInfoSpecialChars(t *testing.T) { func testArtifactoryPublishWithoutBuildUrl(t *testing.T, buildName, buildNumber string) { initArtifactoryTest(t) - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) bi, err := uploadFilesAndGetBuildInfo(t, buildName, buildNumber, "") if err != nil { @@ -345,7 +345,7 @@ func testArtifactoryPublishWithoutBuildUrl(t *testing.T, buildName, buildNumber assert.Empty(t, bi.BuildUrl) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) cleanArtifactoryTest() } @@ -356,7 +356,7 @@ func TestArtifactoryPublishBuildInfoBuildUrl(t *testing.T) { buildUrl := "http://example.ci.com" os.Setenv(cliutils.BuildUrl, "http://override-me.ci.com") defer os.Unsetenv(cliutils.BuildUrl) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) bi, err := uploadFilesAndGetBuildInfo(t, tests.RtBuildName1, buildNumber, buildUrl) if err != nil { @@ -366,7 +366,7 @@ func TestArtifactoryPublishBuildInfoBuildUrl(t *testing.T) { assert.Equal(t, buildUrl, bi.BuildUrl) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -375,7 +375,7 @@ func TestArtifactoryPublishBuildInfoBuildUrlFromEnv(t *testing.T) { initArtifactoryTest(t) buildNumber := "11" buildUrl := "http://example-env.ci.com" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) os.Setenv(cliutils.BuildUrl, buildUrl) defer os.Unsetenv(cliutils.BuildUrl) @@ -388,7 +388,7 @@ func TestArtifactoryPublishBuildInfoBuildUrlFromEnv(t *testing.T) { assert.Equal(t, buildUrl, bi.BuildUrl) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -396,9 +396,9 @@ func TestGetNonExistingBuildInfo(t *testing.T) { initArtifactoryTest(t) buildName := "jfrog-cli-rt-tests-non-existing-build-info" buildNumber := "10" - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) - _, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + _, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -406,14 +406,14 @@ func TestGetNonExistingBuildInfo(t *testing.T) { assert.False(t, found, "build info was expected not to be found") // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) cleanArtifactoryTest() } func TestArtifactoryCleanBuildInfo(t *testing.T) { initArtifactoryTest(t) buildNumber := "11" - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) // Upload files with buildName and buildNumber specFile, err := tests.CreateSpec(tests.SplitUploadSpecA) @@ -438,7 +438,7 @@ func TestArtifactoryCleanBuildInfo(t *testing.T) { tests.VerifyExistLocally(tests.GetCleanBuild(), paths, t) // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -453,7 +453,7 @@ func TestArtifactoryBuildCollectEnv(t *testing.T) { // Publish build info assert.NoError(t, artifactoryCli.Exec("bp", tests.RtBuildName1, buildNumber, "--env-exclude=*password*;*psw*;*secret*;*key*;*token*;DONT_COLLECT")) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) if err != nil { assert.NoError(t, err) return @@ -478,7 +478,7 @@ func TestArtifactoryBuildCollectEnv(t *testing.T) { assert.Contains(t, buildInfo.Properties, "buildInfo.env.COLLECT") // Cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() } @@ -523,11 +523,11 @@ func testBuildAddGit(t *testing.T, useEnvBuildNameAndNumber bool) { t.Fatal(err) } // Clear previous build if exists and publish build-info. - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) assert.NoError(t, artifactoryCli.Exec("build-publish", tests.RtBuildName1, buildNumber)) // Fetch the published build-info for validation. - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.RtBuildName1, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) if err != nil { assert.NoError(t, err) return @@ -553,7 +553,7 @@ func testBuildAddGit(t *testing.T, useEnvBuildNameAndNumber bool) { func cleanBuildAddGitTest(t *testing.T, baseDir, originalFolder, oldHomeDir, dotGitPath string) { coretests.RenamePath(dotGitPath, filepath.Join(baseDir, originalFolder), t) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.RtBuildName1, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) os.Setenv(coreutils.HomeDir, oldHomeDir) cleanArtifactoryTest() } @@ -600,7 +600,7 @@ func uploadFilesAndGetBuildInfo(t *testing.T, buildName, buildNumber, buildUrl s verifyExistInArtifactoryByProps(tests.GetSimpleUploadExpectedRepo1(), tests.RtRepo1+"/*", props, t) // Get build info. - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return buildinfo.BuildInfo{}, err @@ -661,7 +661,7 @@ func TestModuleName(t *testing.T) { exeCommand.execFunc(t, exeCommand.args...) } assert.NoError(t, artifactoryCli.Exec("bp", buildName, test.buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, test.buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, test.buildNumber) if err != nil { assert.NoError(t, err) return @@ -675,7 +675,7 @@ func TestModuleName(t *testing.T) { }) } - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) cleanArtifactoryTest() } @@ -701,7 +701,7 @@ func collectDepsAndPublishBuild(badTest buildAddDepsBuildInfoTestParams, useEnvB } func validateBuildAddDepsBuildInfo(t *testing.T, buildInfoTestParams buildAddDepsBuildInfoTestParams) { - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildInfoTestParams.buildName, buildInfoTestParams.buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildInfoTestParams.buildName, buildInfoTestParams.buildNumber) if err != nil { assert.NoError(t, err) return diff --git a/completion/cli.go b/completion/cli.go index 867f52826..eddf02369 100644 --- a/completion/cli.go +++ b/completion/cli.go @@ -13,7 +13,7 @@ func GetCommands() []cli.Command { return []cli.Command{ { Name: "bash", - Usage: bash_docs.Description, + Description: bash_docs.Description, HelpName: corecommon.CreateUsage("completion bash", bash_docs.Description, bash_docs.Usage), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(*cli.Context) { @@ -22,7 +22,7 @@ func GetCommands() []cli.Command { }, { Name: "zsh", - Usage: zsh_docs.Description, + Description: zsh_docs.Description, HelpName: corecommon.CreateUsage("completion zsh", zsh_docs.Description, zsh_docs.Usage), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(*cli.Context) { diff --git a/config/cli.go b/config/cli.go new file mode 100644 index 000000000..529d4f55b --- /dev/null +++ b/config/cli.go @@ -0,0 +1,182 @@ +package config + +import ( + "errors" + "fmt" + "strings" + + "github.com/codegangsta/cli" + "github.com/jfrog/jfrog-cli-core/common/commands" + corecommon "github.com/jfrog/jfrog-cli-core/docs/common" + "github.com/jfrog/jfrog-cli-core/utils/coreutils" + "github.com/jfrog/jfrog-cli/docs/config/delete" + "github.com/jfrog/jfrog-cli/docs/config/use" + + "github.com/jfrog/jfrog-cli/docs/config/exportcmd" + "github.com/jfrog/jfrog-cli/docs/config/importcmd" + "github.com/jfrog/jfrog-cli/docs/config/show" + "github.com/jfrog/jfrog-cli/utils/cliutils" +) + +func GetCommands() []cli.Command { + return []cli.Command{ + { + Name: "show", + Aliases: []string{"s"}, + Description: show.Description, + HelpName: corecommon.CreateUsage("c show", show.Description, show.Usage), + BashComplete: corecommon.CreateBashCompletionFunc(commands.GetAllServerIds()...), + Action: func(c *cli.Context) error { + return showCmd(c) + }, + }, + { + Name: "delete", + Aliases: []string{"del"}, + Description: delete.Description, + Flags: cliutils.GetCommandFlags(cliutils.DeleteConfig), + HelpName: corecommon.CreateUsage("c del", delete.Description, delete.Usage), + BashComplete: corecommon.CreateBashCompletionFunc(commands.GetAllServerIds()...), + Action: func(c *cli.Context) error { + return deleteCmd(c) + }, + }, + { + Name: "import", + Aliases: []string{"im"}, + Description: importcmd.Description, + HelpName: corecommon.CreateUsage("c import", importcmd.Description, importcmd.Usage), + BashComplete: corecommon.CreateBashCompletionFunc(), + Action: func(c *cli.Context) error { + return importCmd(c) + }, + }, + { + Name: "export", + Aliases: []string{"ex"}, + Description: exportcmd.Description, + HelpName: corecommon.CreateUsage("c export", exportcmd.Description, exportcmd.Usage), + BashComplete: corecommon.CreateBashCompletionFunc(commands.GetAllServerIds()...), + Action: func(c *cli.Context) error { + return exportCmd(c) + }, + }, + { + Name: "use", + Description: use.Description, + HelpName: corecommon.CreateUsage("c use", use.Description, use.Usage), + BashComplete: corecommon.CreateBashCompletionFunc(commands.GetAllServerIds()...), + Action: func(c *cli.Context) error { + return useCmd(c) + }, + }, + } +} + +func ConfigCmd(c *cli.Context) error { + if len(c.Args()) > 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + + configCommandConfiguration, err := createConfigCommandConfiguration(c) + if err != nil { + return err + } + + var serverId string + if len(c.Args()) > 0 { + serverId = c.Args()[0] + if err := ValidateServerId(serverId); err != nil { + return err + } + } + err = validateConfigFlags(configCommandConfiguration) + if err != nil { + return err + } + configCmd := commands.NewConfigCommand().SetDetails(configCommandConfiguration.ServerDetails).SetInteractive(configCommandConfiguration.Interactive). + SetServerId(serverId).SetEncPassword(configCommandConfiguration.EncPassword).SetUseBasicAuthOnly(configCommandConfiguration.BasicAuthOnly) + return configCmd.Config() +} + +func showCmd(c *cli.Context) error { + if len(c.Args()) > 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + var serverId string + if c.NArg() == 1 { + serverId = c.Args()[0] + } + return commands.ShowConfig(serverId) +} + +func deleteCmd(c *cli.Context) error { + if len(c.Args()) > 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + quiet := cliutils.GetQuietValue(c) + + // Clear all configurations + if c.NArg() == 0 { + commands.ClearConfig(!quiet) + return nil + } + + // Delete single configuration + serverId := c.Args()[0] + if !quiet && !coreutils.AskYesNo("Are you sure you want to delete \""+serverId+"\" configuration?", false) { + return nil + } + return commands.DeleteConfig(serverId) +} + +func importCmd(c *cli.Context) error { + if len(c.Args()) != 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + return commands.Import(c.Args()[0]) +} + +func exportCmd(c *cli.Context) error { + if len(c.Args()) != 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + return commands.Export(c.Args()[0]) +} + +func useCmd(c *cli.Context) error { + if len(c.Args()) != 1 { + return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) + } + return commands.Use(c.Args()[0]) +} + +func createConfigCommandConfiguration(c *cli.Context) (configCommandConfiguration *commands.ConfigCommandConfiguration, err error) { + configCommandConfiguration = new(commands.ConfigCommandConfiguration) + configCommandConfiguration.ServerDetails = cliutils.CreateServerDetailsFromFlags(c) + configCommandConfiguration.EncPassword = c.BoolT("enc-password") + configCommandConfiguration.Interactive = cliutils.GetInteractiveValue(c) + configCommandConfiguration.BasicAuthOnly = c.Bool("basic-auth-only") + return +} + +func ValidateServerId(serverId string) error { + reservedIds := []string{"delete", "use", "show", "clear"} + for _, reservedId := range reservedIds { + if serverId == reservedId { + return errors.New(fmt.Sprintf("Server can't have one of the following ID's: %s\n %s", strings.Join(reservedIds, ", "), cliutils.GetDocumentationMessage())) + } + } + return nil +} + +func validateConfigFlags(configCommandConfiguration *commands.ConfigCommandConfiguration) error { + if !configCommandConfiguration.Interactive && configCommandConfiguration.ServerDetails.ArtifactoryUrl == "" { + return errors.New("the --artifactory-url option is mandatory when the --interactive option is set to false or the CI environment variable is set to true.") + } + // Validate the option is not used along an access token + if configCommandConfiguration.BasicAuthOnly && configCommandConfiguration.ServerDetails.AccessToken != "" { + return errors.New("the --basic-auth-only option is only supported when username and password/API key are provided") + } + return nil +} diff --git a/distribution_test.go b/distribution_test.go index 1454eb548..9faa660ae 100644 --- a/distribution_test.go +++ b/distribution_test.go @@ -22,7 +22,7 @@ import ( const bundleVersion = "10" var ( - distributionDetails *config.ArtifactoryDetails + distributionDetails *config.ServerDetails distAuth auth.ServiceDetails distHttpDetails httputils.HttpClientDetails // JFrog CLI for Distribution commands @@ -41,7 +41,7 @@ func CleanDistributionTests() { } func authenticateDistribution() string { - distributionDetails = &config.ArtifactoryDetails{DistributionUrl: *tests.RtDistributionUrl} + distributionDetails = &config.ServerDetails{DistributionUrl: *tests.RtDistributionUrl} cred := "--dist-url=" + *tests.RtDistributionUrl if *tests.RtAccessToken != "" { distributionDetails.AccessToken = *tests.RtDistributionAccessToken @@ -79,7 +79,7 @@ func initDistributionTest(t *testing.T) { func cleanDistributionTest(t *testing.T) { distributionCli.Exec("rbdel", tests.BundleName, bundleVersion, "--site=*", "--delete-from-dist", "--quiet") inttestutils.WaitForDeletion(t, tests.BundleName, bundleVersion, distHttpDetails) - inttestutils.CleanDistributionRepositories(t, artifactoryDetails) + inttestutils.CleanDistributionRepositories(t, serverDetails) tests.CleanFileSystem() } diff --git a/docker_test.go b/docker_test.go index 8ddcf714f..cfe68773c 100644 --- a/docker_test.go +++ b/docker_test.go @@ -26,7 +26,7 @@ const ( func InitDockerTests() { initArtifactoryCli() cleanUpOldBuilds() - inttestutils.CleanUpOldImages(artifactoryDetails, artHttpDetails) + inttestutils.CleanUpOldImages(serverDetails, artHttpDetails) cleanUpOldRepositories() tests.AddTimestampToGlobalVars() createRequiredRepos() @@ -87,7 +87,7 @@ func runPushTest(containerManager container.ContainerManagerType, imageName, mod imagePath := path.Join(repo, imageName, "1") + "/" validateContainerBuild(tests.DockerBuildName, buildNumber, imagePath, module, 7, 5, 7, t) - inttestutils.ContainerTestCleanup(t, artifactoryDetails, artHttpDetails, imageName, tests.DockerBuildName, repo) + inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, imageName, tests.DockerBuildName, repo) } func TestContainerPushBuildNameNumberFromEnv(t *testing.T) { @@ -107,7 +107,7 @@ func TestContainerPushBuildNameNumberFromEnv(t *testing.T) { imagePath := path.Join(*tests.DockerLocalRepo, tests.DockerImageName, "1") + "/" validateContainerBuild(tests.DockerBuildName, buildNumber, imagePath, tests.DockerImageName+":1", 7, 5, 7, t) - inttestutils.ContainerTestCleanup(t, artifactoryDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, *tests.DockerLocalRepo) + inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, *tests.DockerLocalRepo) } } @@ -134,7 +134,7 @@ func TestContainerPull(t *testing.T) { artifactoryCli.Exec("build-publish", tests.DockerBuildName, buildNumber) validateContainerBuild(tests.DockerBuildName, buildNumber, imagePath, ModuleNameJFrogTest, 0, 7, 7, t) - inttestutils.ContainerTestCleanup(t, artifactoryDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, repo) + inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, repo) } } } @@ -168,7 +168,7 @@ func TestContainerFatManifestPull(t *testing.T) { assert.NoError(t, artifactoryCli.Exec("build-publish", tests.DockerBuildName, buildNumber)) // Validate - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.DockerBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.DockerBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -180,7 +180,7 @@ func TestContainerFatManifestPull(t *testing.T) { buildInfo := publishedBuildInfo.BuildInfo validateBuildInfo(buildInfo, t, 6, 0, imageName+":2.2") - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.DockerBuildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.DockerBuildName, artHttpDetails) inttestutils.DeleteTestContainerImage(t, imageTag, containerManager) } } @@ -207,13 +207,13 @@ func TestDockerPromote(t *testing.T) { assert.NoError(t, err) verifyExistInArtifactory(tests.GetDockerDeployedManifest(), searchSpec, t) - inttestutils.ContainerTestCleanup(t, artifactoryDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, *tests.DockerLocalRepo) + inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, tests.DockerImageName, tests.DockerBuildName, *tests.DockerLocalRepo) inttestutils.DeleteTestContainerImage(t, imageTag, container.DockerClient) } func validateContainerBuild(buildName, buildNumber, imagePath, module string, expectedArtifacts, expectedDependencies, expectedItemsInArtifactory int, t *testing.T) { validateContainerImage(t, imagePath, expectedItemsInArtifactory) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -229,7 +229,7 @@ func validateContainerBuild(buildName, buildNumber, imagePath, module string, ex func validateContainerImage(t *testing.T, imagePath string, expectedItemsInArtifactory int) { specFile := spec.NewBuilder().Pattern(imagePath + "*").BuildSpec() searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(specFile) + searchCmd.SetServerDetails(serverDetails).SetSpec(specFile) reader, err := searchCmd.Search() assert.NoError(t, err) length, err := reader.Length() @@ -252,7 +252,7 @@ func TestKanikoBuildCollect(t *testing.T) { assert.NoError(t, artifactoryCli.Exec("build-publish", tests.DockerBuildName, buildNumber)) // Validate. - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.DockerBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.DockerBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -265,7 +265,7 @@ func TestKanikoBuildCollect(t *testing.T) { validateBuildInfo(buildInfo, t, 0, 3, imageTag) // Cleanup. - inttestutils.ContainerTestCleanup(t, artifactoryDetails, artHttpDetails, imageName, tests.DockerBuildName, repo) + inttestutils.ContainerTestCleanup(t, serverDetails, artHttpDetails, imageName, tests.DockerBuildName, repo) inttestutils.DeleteTestContainerImage(t, kanikoImage, container.DockerClient) assert.NoError(t, os.RemoveAll(tests.Out)) } diff --git a/docs/config/create/help.go b/docs/config/create/help.go new file mode 100644 index 000000000..0ec8dd30f --- /dev/null +++ b/docs/config/create/help.go @@ -0,0 +1,8 @@ +package create + +const Description string = `Creates a server configuration.` + +var Usage = []string{"jfrog rt c "} + +const Arguments string = ` server ID + A unique ID for the new server configuration.` diff --git a/docs/config/delete/help.go b/docs/config/delete/help.go new file mode 100644 index 000000000..c08939778 --- /dev/null +++ b/docs/config/delete/help.go @@ -0,0 +1,9 @@ +package delete + +const Description string = `Deletes the stored configuration. In case this argument is followed by a configured server ID, then only this server's configurations is deleted.` + +var Usage = []string{"jfrog rt c del", + "jfrog rt c del "} + +const Arguments string = ` server ID + A unique ID for an existing JFrog configuration.` diff --git a/docs/config/exportcmd/help.go b/docs/config/exportcmd/help.go new file mode 100644 index 000000000..f3cdbe648 --- /dev/null +++ b/docs/config/exportcmd/help.go @@ -0,0 +1,8 @@ +package exportcmd + +const Description string = `Creates a server configuration token. The generated token can be imported by the "jfrog rt c import " command.` + +var Usage = []string{"jfrog rt c export "} + +const Arguments string = ` server ID + A unique ID for the new server configuration.` diff --git a/docs/config/importcmd/help.go b/docs/config/importcmd/help.go new file mode 100644 index 000000000..56adf78c4 --- /dev/null +++ b/docs/config/importcmd/help.go @@ -0,0 +1,8 @@ +package importcmd + +const Description string = `Imports a server configuration from a server token. A server token is generated by the "jfrog rt c export " command.` + +var Usage = []string{"jfrog rt c import "} + +const Arguments string = ` server token + Token generated by the "jfrog rt c export " command.` diff --git a/docs/config/show/help.go b/docs/config/show/help.go new file mode 100644 index 000000000..fd0b17fcf --- /dev/null +++ b/docs/config/show/help.go @@ -0,0 +1,8 @@ +package show + +const Description string = `Shows the stored configuration. In case this argument is followed by a configured server ID, then only this server's configurations is shown.` + +var Usage = []string{"jfrog rt c show "} + +const Arguments string = ` server ID + A unique ID for the new server configuration.` diff --git a/docs/config/use/help.go b/docs/config/use/help.go new file mode 100644 index 000000000..9b5950adb --- /dev/null +++ b/docs/config/use/help.go @@ -0,0 +1,8 @@ +package use + +const Description = "Set the active server by its ID." + +var Usage = []string{"jfrog rt use "} + +const Arguments string = ` server ID + The configured server ID which will be used by default.` diff --git a/go_test.go b/go_test.go index 1cc4d0045..cf400ebf7 100644 --- a/go_test.go +++ b/go_test.go @@ -57,7 +57,7 @@ func TestGoBuildInfo(t *testing.T) { } module := "github.com/jfrog/dependency" - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.GoBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GoBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -105,7 +105,7 @@ func TestGoBuildInfo(t *testing.T) { return } - publishedBuildInfo, found, err = tests.GetBuildInfo(artifactoryDetails, tests.GoBuildName, buildNumber) + publishedBuildInfo, found, err = tests.GetBuildInfo(serverDetails, tests.GoBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -129,7 +129,7 @@ func TestGoBuildInfo(t *testing.T) { validateArtifactsProperties(resultItems, t, propsMap) assert.NoError(t, os.Chdir(wd)) - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.GoBuildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.GoBuildName, artHttpDetails) cleanGoTest(t) } @@ -215,7 +215,7 @@ func TestGoGetSpecificVersion(t *testing.T) { return } - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.GoBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GoBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -245,7 +245,7 @@ func runGo(module, buildName, buildNumber string, t *testing.T, args ...string) assert.NoError(t, err) return } - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -270,7 +270,7 @@ func runGo(module, buildName, buildNumber string, t *testing.T, args ...string) validateBuildInfo(buildInfo, t, 8, 0, module) } - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) } func prepareGoProject(configDestDir string, t *testing.T, copyDirs bool) { @@ -462,7 +462,7 @@ func cleanGoTest(t *testing.T) { cleanGoCache(t) assert.NoError(t, os.Unsetenv("GONOSUMDB")) deleteSpec := spec.NewBuilder().Pattern(tests.GoRepo).BuildSpec() - _, _, err := tests.DeleteFiles(deleteSpec, artifactoryDetails) + _, _, err := tests.DeleteFiles(deleteSpec, serverDetails) assert.NoError(t, err) cleanBuildToolsTest() } diff --git a/gradle_test.go b/gradle_test.go index aac98bc68..2398b655f 100644 --- a/gradle_test.go +++ b/gradle_test.go @@ -24,7 +24,7 @@ const ( func cleanGradleTest() { os.Unsetenv(coreutils.HomeDir) deleteSpec := spec.NewBuilder().Pattern(tests.GradleRepo).BuildSpec() - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) tests.CleanFileSystem() } @@ -39,7 +39,7 @@ func TestGradleBuildWithServerID(t *testing.T) { buildNumber := "1" runAndValidateGradle(buildGradlePath, configFilePath, buildName, buildNumber, t) assert.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -73,7 +73,7 @@ func TestNativeGradleBuildWithServerID(t *testing.T) { verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+tests.GradleBuildName+";build.number="+buildNumber, t) assert.NoError(t, artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.GradleBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GradleBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -98,7 +98,7 @@ func TestGradleBuildWithServerIDWithUsesPlugin(t *testing.T) { runAndValidateGradle(buildGradlePath, configFilePath, tests.GradleBuildName, buildNumber, t) assert.NoError(t, artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.GradleBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GradleBuildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -132,7 +132,7 @@ func TestGradleBuildWithCredentials(t *testing.T) { runAndValidateGradle(buildGradlePath, configFilePath, tests.GradleBuildName, buildNumber, t) assert.NoError(t, artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.GradleBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GradleBuildName, buildNumber) if err != nil { assert.NoError(t, err) return diff --git a/inttestutils/distribution.go b/inttestutils/distribution.go index 9f1697ebd..129f9e266 100644 --- a/inttestutils/distribution.go +++ b/inttestutils/distribution.go @@ -274,7 +274,7 @@ func ListAllBundlesNames(distHttpDetails httputils.HttpClientDetails) ([]string, } // Clean up 'cli-tests-dist1-' and 'cli-tests-dist2-' after running a distribution test -func CleanDistributionRepositories(t *testing.T, distributionDetails *config.ArtifactoryDetails) { +func CleanDistributionRepositories(t *testing.T, distributionDetails *config.ServerDetails) { deleteSpec := spec.NewBuilder().Pattern(tests.DistRepo1).BuildSpec() tests.DeleteFiles(deleteSpec, distributionDetails) deleteSpec = spec.NewBuilder().Pattern(tests.DistRepo1).BuildSpec() diff --git a/inttestutils/docker.go b/inttestutils/docker.go index cce8f434e..cb6b44066 100644 --- a/inttestutils/docker.go +++ b/inttestutils/docker.go @@ -122,24 +122,24 @@ func DeleteTestContainerImage(t *testing.T, imageTag string, containerManagerTyp assert.NoError(t, gofrogcmd.RunCmd(imageBuilder)) } -func ContainerTestCleanup(t *testing.T, artifactoryDetails *config.ArtifactoryDetails, artHttpDetails httputils.HttpClientDetails, imageName, buildName, repo string) { +func ContainerTestCleanup(t *testing.T, serverDetails *config.ServerDetails, artHttpDetails httputils.HttpClientDetails, imageName, buildName, repo string) { // Remove build from Artifactory - DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + DeleteBuild(serverDetails.Url, buildName, artHttpDetails) // Remove image from Artifactory deleteSpec := spec.NewBuilder().Pattern(path.Join(repo, imageName)).BuildSpec() - successCount, failCount, err := tests.DeleteFiles(deleteSpec, artifactoryDetails) + successCount, failCount, err := tests.DeleteFiles(deleteSpec, serverDetails) assert.Greater(t, successCount, 0) assert.Equal(t, failCount, 0) assert.NoError(t, err) } -func getAllImagesNames(artifactoryDetails *config.ArtifactoryDetails) ([]string, error) { +func getAllImagesNames(serverDetails *config.ServerDetails) ([]string, error) { var imageNames []string prefix := *tests.DockerLocalRepo + "/" specFile := spec.NewBuilder().Pattern(prefix + tests.DockerImageName + "*").IncludeDirs(true).BuildSpec() searchCmd := generic.NewSearchCommand() - searchCmd.SetRtDetails(artifactoryDetails).SetSpec(specFile) + searchCmd.SetServerDetails(serverDetails).SetSpec(specFile) reader, err := searchCmd.Search() if err != nil { return nil, err @@ -151,11 +151,11 @@ func getAllImagesNames(artifactoryDetails *config.ArtifactoryDetails) ([]string, return imageNames, err } -func CleanUpOldImages(artifactoryDetails *config.ArtifactoryDetails, artHttpDetails httputils.HttpClientDetails) { - getActualItems := func() ([]string, error) { return getAllImagesNames(artifactoryDetails) } +func CleanUpOldImages(serverDetails *config.ServerDetails, artHttpDetails httputils.HttpClientDetails) { + getActualItems := func() ([]string, error) { return getAllImagesNames(serverDetails) } deleteItem := func(imageName string) { deleteSpec := spec.NewBuilder().Pattern(path.Join(*tests.DockerLocalRepo, imageName)).BuildSpec() - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) log.Info("Image", imageName, "deleted.") } tests.CleanUpOldItems([]string{tests.DockerImageName}, getActualItems, deleteItem) diff --git a/main.go b/main.go index bab8a2030..89eb4fa39 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,15 @@ package main import ( + "os" + "github.com/jfrog/jfrog-cli-core/utils/coreutils" "github.com/jfrog/jfrog-cli-core/utils/log" + "github.com/jfrog/jfrog-cli/config" "github.com/jfrog/jfrog-cli/docs/common" + "github.com/jfrog/jfrog-cli/docs/config/create" "github.com/jfrog/jfrog-cli/plugins" "github.com/jfrog/jfrog-cli/plugins/utils" - "os" "github.com/codegangsta/cli" "github.com/jfrog/jfrog-cli/artifactory" @@ -45,7 +48,7 @@ AUTHOR(S): {{range .Authors}}{{ . }}{{end}} {{end}}{{if .Commands}} COMMANDS: - {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} {{end}}{{end}}{{if .VisibleFlags}} GLOBAL OPTIONS: {{range .VisibleFlags}}{{.}} @@ -56,14 +59,16 @@ Environment Variables: ` const subcommandHelpTemplate = `NAME: - {{.HelpName}} - {{.Usage}} + {{.HelpName}} - {{.Description}} USAGE: - {{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}}[arguments...] + {{if .Usage}}{{.Usage}}{{ "\n\t" }}{{end}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}}[arguments...] COMMANDS: - {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} - {{end}}{{if .VisibleFlags}} + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}} + {{end}}{{if .VisibleFlags}}{{if .ArgsUsage}} +Arguments: +{{.ArgsUsage}}{{ "\n" }}{{end}} OPTIONS: {{range .VisibleFlags}}{{.}} {{end}} @@ -103,34 +108,44 @@ func getCommands() []cli.Command { cliNameSpaces := []cli.Command{ { Name: cliutils.CmdArtifactory, - Usage: "Artifactory commands", + Description: "Artifactory commands", Subcommands: artifactory.GetCommands(), }, { Name: cliutils.CmdBintray, - Usage: "Bintray commands", + Description: "Bintray commands", Subcommands: bintray.GetCommands(), }, { Name: cliutils.CmdMissionControl, - Usage: "Mission Control commands", + Description: "Mission Control commands", Subcommands: missioncontrol.GetCommands(), }, { Name: cliutils.CmdXray, - Usage: "Xray commands", + Description: "Xray commands", Subcommands: xray.GetCommands(), }, { Name: cliutils.CmdCompletion, - Usage: "Generate autocomplete scripts", + Description: "Generate autocomplete scripts", Subcommands: completion.GetCommands(), }, { Name: cliutils.CmdPlugin, - Usage: "Plugins commands", + Description: "Plugins commands", Subcommands: plugins.GetCommands(), }, + { + Name: cliutils.CmdConfig, + ShortName: "c", + Description: "Config commands", + Usage: "jfrog config ", + Flags: cliutils.GetCommandFlags(cliutils.Config), + ArgsUsage: create.Arguments, + Action: config.ConfigCmd, + Subcommands: config.GetCommands(), + }, } return append(cliNameSpaces, utils.GetPlugins()...) } diff --git a/maven_test.go b/maven_test.go index 4de690672..6591b64e5 100644 --- a/maven_test.go +++ b/maven_test.go @@ -25,9 +25,9 @@ var localRepoDir string func cleanMavenTest() { os.Unsetenv(coreutils.HomeDir) deleteSpec := spec.NewBuilder().Pattern(tests.MvnRepo1).BuildSpec() - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) deleteSpec = spec.NewBuilder().Pattern(tests.MvnRepo2).BuildSpec() - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) tests.CleanFileSystem() } @@ -101,7 +101,7 @@ func TestInsecureTlsMavenBuild(t *testing.T) { initMavenTest(t, true) // Establish a reverse proxy without any certificates os.Setenv(tests.HttpsProxyEnvVar, mavenTestsProxyPort) - go cliproxy.StartLocalReverseHttpProxy(artifactoryDetails.Url, false) + go cliproxy.StartLocalReverseHttpProxy(serverDetails.ArtifactoryUrl, false) // The two certificate files are created by the reverse proxy on startup in the current directory. os.Remove(certificate.KEY_FILE) os.Remove(certificate.CERT_FILE) @@ -109,7 +109,7 @@ func TestInsecureTlsMavenBuild(t *testing.T) { assert.NoError(t, checkIfServerIsUp(cliproxy.GetProxyHttpsPort(), "https", false)) // Save the original Artifactory url, and change the url to proxy url oldRtUrl := tests.RtUrl - parsedUrl, err := url.Parse(artifactoryDetails.Url) + parsedUrl, err := url.Parse(serverDetails.ArtifactoryUrl) proxyUrl := "https://127.0.0.1:" + cliproxy.GetProxyHttpsPort() + parsedUrl.RequestURI() tests.RtUrl = &proxyUrl diff --git a/missioncontrol/cli.go b/missioncontrol/cli.go index f668f2143..e379ba8da 100644 --- a/missioncontrol/cli.go +++ b/missioncontrol/cli.go @@ -1,14 +1,14 @@ package missioncontrol import ( - "fmt" + "strconv" + "github.com/codegangsta/cli" + coreCommonCommands "github.com/jfrog/jfrog-cli-core/common/commands" corecommon "github.com/jfrog/jfrog-cli-core/docs/common" "github.com/jfrog/jfrog-cli-core/missioncontrol/commands" "github.com/jfrog/jfrog-cli-core/utils/config" - "github.com/jfrog/jfrog-cli-core/utils/coreutils" "github.com/jfrog/jfrog-cli/docs/common" - configdocs "github.com/jfrog/jfrog-cli/docs/missioncontrol/config" "github.com/jfrog/jfrog-cli/docs/missioncontrol/jpdadd" "github.com/jfrog/jfrog-cli/docs/missioncontrol/jpddelete" "github.com/jfrog/jfrog-cli/docs/missioncontrol/licenseacquire" @@ -18,28 +18,14 @@ import ( clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "strconv" ) func GetCommands() []cli.Command { return []cli.Command{ - { - Name: "config", - Flags: cliutils.GetCommandFlags(cliutils.McConfig), - Usage: configdocs.Description, - HelpName: corecommon.CreateUsage("mc config", configdocs.Description, configdocs.Usage), - UsageText: configdocs.Arguments, - ArgsUsage: common.CreateEnvVars(), - Aliases: []string{"c"}, - BashComplete: corecommon.CreateBashCompletionFunc(), - Action: func(c *cli.Context) error { - return configure(c) - }, - }, { Name: "license-acquire", Flags: cliutils.GetCommandFlags(cliutils.LicenseAcquire), - Usage: licenseacquire.Description, + Description: licenseacquire.Description, HelpName: corecommon.CreateUsage("mc license-acquire", licenseacquire.Description, licenseacquire.Usage), UsageText: licenseacquire.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -52,7 +38,7 @@ func GetCommands() []cli.Command { { Name: "license-deploy", Flags: cliutils.GetCommandFlags(cliutils.LicenseDeploy), - Usage: licensedeploy.Description, + Description: licensedeploy.Description, HelpName: corecommon.CreateUsage("mc license-deploy", licensedeploy.Description, licensedeploy.Usage), UsageText: licensedeploy.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -65,7 +51,7 @@ func GetCommands() []cli.Command { { Name: "license-release", Flags: cliutils.GetCommandFlags(cliutils.LicenseRelease), - Usage: licenserelease.Description, + Description: licenserelease.Description, HelpName: corecommon.CreateUsage("mc license-release", licenserelease.Description, licenserelease.Usage), UsageText: licenserelease.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -78,7 +64,7 @@ func GetCommands() []cli.Command { { Name: "jpd-add", Flags: cliutils.GetCommandFlags(cliutils.JpdAdd), - Usage: jpdadd.Description, + Description: jpdadd.Description, HelpName: corecommon.CreateUsage("mc jpd-add", jpdadd.Description, jpdadd.Usage), UsageText: jpdadd.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -91,7 +77,7 @@ func GetCommands() []cli.Command { { Name: "jpd-delete", Flags: cliutils.GetCommandFlags(cliutils.JpdDelete), - Usage: jpddelete.Description, + Description: jpddelete.Description, HelpName: corecommon.CreateUsage("mc jpd-delete", jpddelete.Description, jpddelete.Usage), UsageText: jpddelete.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -119,7 +105,7 @@ func jpdDelete(c *cli.Context) error { if len(c.Args()) != 1 { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } - mcDetails, err := createMissionControlDetails(c, true) + mcDetails, err := createMissionControlDetails(c) if err != nil { return err } @@ -131,7 +117,7 @@ func licenseAcquire(c *cli.Context) error { if size != 2 { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } - mcDetails, err := createMissionControlDetails(c, true) + mcDetails, err := createMissionControlDetails(c) if err != nil { return err } @@ -156,73 +142,36 @@ func licenseRelease(c *cli.Context) error { if size != 2 { return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) } - mcDetails, err := createMissionControlDetails(c, true) + mcDetails, err := createMissionControlDetails(c) if err != nil { return err } return commands.LicenseRelease(c.Args()[0], c.Args()[1], mcDetails) } -func offerConfig(c *cli.Context) (*config.MissionControlDetails, error) { - exists, err := config.IsMissionControlConfExists() - if err != nil || exists { +func offerConfig(c *cli.Context) (*config.ServerDetails, error) { + confirmed, err := cliutils.ShouldOfferConfig() + if !confirmed || err != nil { return nil, err } - val, err := clientutils.GetBoolEnvValue(cliutils.OfferConfig, true) + details := createMCDetailsFromFlags(c) + configCmd := coreCommonCommands.NewConfigCommand().SetDefaultDetails(details).SetInteractive(true) + err = configCmd.Config() if err != nil { return nil, err } - if !val { - _ = config.SaveMissionControlConf(new(config.MissionControlDetails)) - return nil, nil - } - msg := fmt.Sprintf("To avoid this message in the future, set the %s environment variable to false.\n"+ - "The CLI commands require the Mission Control URL and authentication details\n"+ - "Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n"+ - "You can also configure these parameters later using the 'jfrog mc c' command.\n"+ - "Configure now?", cliutils.OfferConfig) - confirmed := coreutils.AskYesNo(msg, false) - if !confirmed { - _ = config.SaveMissionControlConf(new(config.MissionControlDetails)) - return nil, nil - } - details, err := createMissionControlDetails(c, false) - if err != nil { - return nil, err - } - return commands.Config(nil, details, true) -} -func configure(c *cli.Context) error { - if len(c.Args()) > 1 { - return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c) - } - if len(c.Args()) == 1 { - switch c.Args()[0] { - case "show": - return commands.ShowConfig() - case "clear": - return commands.ClearConfig() - default: - return cliutils.PrintHelpAndReturnError("Unknown argument '"+c.Args()[0]+"'. Available arguments are 'show' and 'clear'.", c) - } - } - flags, err := createConfigFlags(c) - if err != nil { - return err - } - _, err = commands.Config(flags.MissionControlDetails, nil, flags.Interactive) - return err + return configCmd.ServerDetails() } func createLicenseDeployFlags(c *cli.Context) (flags *commands.LicenseDeployFlags, err error) { flags = new(commands.LicenseDeployFlags) - flags.MissionControlDetails, err = createMissionControlDetails(c, true) + flags.ServerDetails, err = createMissionControlDetails(c) if err != nil { return } flags.LicenseCount = cliutils.DefaultLicenseCount - if c.String("license-count") != "" { + if c.IsSet("license-count") { flags.LicenseCount, err = strconv.Atoi(c.String("license-count")) if err != nil { return nil, cliutils.PrintHelpAndReturnError("The '--license-count' option must have a numeric value. ", c) @@ -234,22 +183,9 @@ func createLicenseDeployFlags(c *cli.Context) (flags *commands.LicenseDeployFlag return } -func createConfigFlags(c *cli.Context) (flags *commands.ConfigFlags, err error) { - flags = new(commands.ConfigFlags) - flags.Interactive = cliutils.GetInteractiveValue(c) - flags.MissionControlDetails, err = createMissionControlDetails(c, false) - if err != nil { - return - } - if !flags.Interactive && (flags.MissionControlDetails.Url == "" || flags.MissionControlDetails.AccessToken == "") { - return nil, cliutils.PrintHelpAndReturnError("the --url and --access-token options are mandatory when the --interactive option is set to false or the CI environment variable is set to true.", c) - } - return -} - func createJpdAddFlags(c *cli.Context) (flags *commands.JpdAddFlags, err error) { flags = new(commands.JpdAddFlags) - flags.MissionControlDetails, err = createMissionControlDetails(c, true) + flags.ServerDetails, err = createMissionControlDetails(c) if err != nil { return } @@ -260,34 +196,40 @@ func createJpdAddFlags(c *cli.Context) (flags *commands.JpdAddFlags, err error) return } -func createMissionControlDetails(c *cli.Context, includeConfig bool) (*config.MissionControlDetails, error) { - if includeConfig { - details, err := offerConfig(c) - if err != nil { - return nil, err - } - if details != nil { - return details, nil - } +func createMissionControlDetails(c *cli.Context) (*config.ServerDetails, error) { + createdDetails, err := offerConfig(c) + if err != nil { + return nil, err + } + if createdDetails != nil { + return createdDetails, nil } - details := new(config.MissionControlDetails) - details.Url = c.String("url") - details.AccessToken = c.String("access-token") - if includeConfig { - if details.Url == "" || details.AccessToken == "" { - confDetails, err := commands.GetConfig() - if err != nil { - return nil, err - } - if details.Url == "" { - details.Url = confDetails.Url - } - if details.AccessToken == "" { - details.SetAccessToken(confDetails.AccessToken) - } - } + details := createMCDetailsFromFlags(c) + // If urls or credentials were passed as options, use options as they are. + // For security reasons, we'd like to avoid using part of the connection details from command options and the rest from the config. + // Either use command options only or config only. + if credentialsChanged(details) { + return details, nil + } + + // Else, use details from config for requested serverId, or for default server if empty. + confDetails, err := coreCommonCommands.GetConfig(details.ServerId, true) + if err != nil { + return nil, err } - details.Url = clientutils.AddTrailingSlashIfNeeded(details.Url) - return details, nil + + confDetails.Url = clientutils.AddTrailingSlashIfNeeded(confDetails.MissionControlUrl) + return confDetails, nil +} + +func createMCDetailsFromFlags(c *cli.Context) (details *config.ServerDetails) { + details = cliutils.CreateServerDetailsFromFlags(c) + details.MissionControlUrl = details.Url + details.Url = "" + return +} + +func credentialsChanged(details *config.ServerDetails) bool { + return details.MissionControlUrl != "" || details.User != "" || details.Password != "" || details.AccessToken != "" } diff --git a/npm_test.go b/npm_test.go index d374af5a6..3803e699f 100644 --- a/npm_test.go +++ b/npm_test.go @@ -38,7 +38,7 @@ const npmFlagName = "npm" func cleanNpmTest() { os.Unsetenv(coreutils.HomeDir) deleteSpec := spec.NewBuilder().Pattern(tests.NpmRepo).BuildSpec() - tests.DeleteFiles(deleteSpec, artifactoryDetails) + tests.DeleteFiles(deleteSpec, serverDetails) tests.CleanFileSystem() } @@ -106,7 +106,7 @@ func runTestNpm(t *testing.T, native bool) { err = os.Chdir(wd) assert.NoError(t, err) cleanNpmTest() - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.NpmBuildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.NpmBuildName, artHttpDetails) } func readModuleId(t *testing.T, wd string) string { @@ -217,7 +217,7 @@ func validateNpmInstall(t *testing.T, npmTestParams npmTestParams) { if !strings.Contains(npmTestParams.npmArgs, "-only=prod") && !strings.Contains(npmTestParams.npmArgs, "-production") { expectedDependencies = append(expectedDependencies, expectedDependency{id: "json:9.0.6", scopes: []string{"development"}}) } - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.NpmBuildName, npmTestParams.buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.NpmBuildName, npmTestParams.buildNumber) if err != nil { assert.NoError(t, err) return @@ -252,7 +252,7 @@ func validateNpmInstall(t *testing.T, npmTestParams npmTestParams) { } func validateNpmPackInstall(t *testing.T, npmTestParams npmTestParams) { - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.NpmBuildName, npmTestParams.buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.NpmBuildName, npmTestParams.buildNumber) if err != nil { assert.NoError(t, err) return @@ -291,7 +291,7 @@ func validateNpmScopedPublish(t *testing.T, npmTestParams npmTestParams) { } func validateNpmCommonPublish(t *testing.T, npmTestParams npmTestParams) { - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.NpmBuildName, npmTestParams.buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.NpmBuildName, npmTestParams.buildNumber) if err != nil { assert.NoError(t, err) return diff --git a/nuget_test.go b/nuget_test.go index 6cace8275..8fd97c493 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -144,7 +144,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe inttestutils.ValidateGeneratedBuildInfoModule(t, buildName, buildNumber, expectedModule, buildinfo.Nuget) assert.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, buildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) if err != nil { assert.NoError(t, err) return @@ -162,7 +162,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe assert.NoError(t, os.Chdir(wd)) // cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, buildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) } func runNuGet(t *testing.T, args ...string) error { @@ -208,7 +208,7 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR defer fileutils.RemoveTempDir(tempDirPath) params := &dotnet.DotnetCommand{} - params.SetRtDetails(&config.ArtifactoryDetails{Url: baseRtUrl, User: "user", Password: "password"}). + params.SetServerDetails(&config.ServerDetails{Url: baseRtUrl, User: "user", Password: "password"}). SetUseNugetAddSource(testSuite.useNugetAddSource).SetUseNugetV2(testSuite.useNugetV2) // Prepare the config file with NuGet authentication configFile, err := params.InitNewConfig(tempDirPath) diff --git a/pip_test.go b/pip_test.go index 55ec784d8..e5ce139b3 100644 --- a/pip_test.go +++ b/pip_test.go @@ -67,7 +67,7 @@ func TestPipInstall(t *testing.T) { testPipCmd(t, test.name, createPipProject(t, test.outputFolder, test.project), strconv.Itoa(buildNumber), test.moduleId, test.expectedDependencies, test.args) if test.cleanAfterExecution { // cleanup - inttestutils.DeleteBuild(artifactoryDetails.Url, tests.PipBuildName, artHttpDetails) + inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.PipBuildName, artHttpDetails) cleanPipTest(t, test.name) } }) @@ -95,7 +95,7 @@ func testPipCmd(t *testing.T, outputFolder, projectPath, buildNumber, module str inttestutils.ValidateGeneratedBuildInfoModule(t, tests.PipBuildName, buildNumber, []string{module}, buildinfo.Pip) assert.NoError(t, artifactoryCli.Exec("bp", tests.PipBuildName, buildNumber)) - publishedBuildInfo, found, err := tests.GetBuildInfo(artifactoryDetails, tests.PipBuildName, buildNumber) + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.PipBuildName, buildNumber) if err != nil { assert.NoError(t, err) return diff --git a/plugins/cli.go b/plugins/cli.go index fe4bd7b6f..ef56c93c5 100644 --- a/plugins/cli.go +++ b/plugins/cli.go @@ -14,7 +14,7 @@ func GetCommands() []cli.Command { { Name: "install", Aliases: []string{"i"}, - Usage: installdocs.Description, + Description: installdocs.Description, HelpName: corecommon.CreateUsage("plugin install", installdocs.Description, installdocs.Usage), UsageText: installdocs.Arguments, ArgsUsage: common.CreateEnvVars(), @@ -26,7 +26,7 @@ func GetCommands() []cli.Command { { Name: "uninstall", Aliases: []string{"ui"}, - Usage: uninstalldocs.Description, + Description: uninstalldocs.Description, HelpName: corecommon.CreateUsage("plugin uninstall", uninstalldocs.Description, uninstalldocs.Usage), UsageText: uninstalldocs.Arguments, ArgsUsage: common.CreateEnvVars(), diff --git a/utils/cliutils/cli_consts.go b/utils/cliutils/cli_consts.go index ede30694c..778960018 100644 --- a/utils/cliutils/cli_consts.go +++ b/utils/cliutils/cli_consts.go @@ -12,6 +12,7 @@ const ( CmdXray = "xr" CmdCompletion = "completion" CmdPlugin = "plugin" + CmdConfig = "conf" // Download DownloadMinSplitKb = 5120 diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 590a8ffcf..30c3ce2df 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -10,7 +10,8 @@ import ( const ( // Artifactory's Commands Keys - Config = "config" + RtConfig = "rt-config" + DeleteConfig = "delete-config" Upload = "upload" Download = "download" Move = "move" @@ -76,6 +77,9 @@ const ( // XRay's Commands Keys OfflineUpdate = "offline-update" + // Config commands keys + Config = "config" + // *** Artifactory Commands' flags *** // Base flags url = "url" @@ -378,6 +382,13 @@ const ( // Unique license-deploy flags licenseCount = "license-count" + + // *** Config Commands' flags *** + configPrefix = "config-" + configPlatformUrl = configPrefix + url + configRtUrl = "artifactory-url" + configXrUrl = "xray-url" + configMcUrl = "mission-control-url" ) var flagsMap = map[string]cli.Flag{ @@ -1138,13 +1149,37 @@ var flagsMap = map[string]cli.Flag{ Name: imageFile, Usage: "[Mandatory] Path to a file which includes one line in the following format: @sha256:.` `", }, + // Config commands Flags + configPlatformUrl: cli.StringFlag{ + Name: url, + Usage: "[Optional] JFrog platform URL.` `", + }, + configRtUrl: cli.StringFlag{ + Name: configRtUrl, + Usage: "[Optional] Artifactory URL.` `", + }, + configXrUrl: cli.StringFlag{ + Name: configXrUrl, + Usage: "[Optional] Xray URL.` `", + }, + configMcUrl: cli.StringFlag{ + Name: configMcUrl, + Usage: "[Optional] Mission Control URL.` `", + }, } var commandFlags = map[string][]string{ Config: { + interactive, encPassword, configPlatformUrl, configRtUrl, distUrl, configXrUrl, configMcUrl, user, password, apikey, accessToken, sshKeyPath, clientCertPath, + clientCertKeyPath, basicAuthOnly, insecureTls, + }, + RtConfig: { interactive, encPassword, url, distUrl, user, password, apikey, accessToken, sshKeyPath, clientCertPath, clientCertKeyPath, basicAuthOnly, insecureTls, }, + DeleteConfig: { + deleteQuiet, + }, Upload: { url, user, password, apikey, accessToken, sshPassPhrase, sshKeyPath, serverId, clientCertPath, targetProps, clientCertKeyPath, spec, specVars, buildName, buildNumber, module, uploadExcludePatterns, uploadExclusions, deb, diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index 30e62db20..5131f521c 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -1,10 +1,12 @@ package cliutils import ( + "fmt" "os" "strings" "github.com/codegangsta/cli" + "github.com/jfrog/jfrog-cli-core/utils/config" "github.com/jfrog/jfrog-cli-core/utils/coreutils" "github.com/jfrog/jfrog-cli/utils/summary" serviceutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" @@ -193,3 +195,60 @@ func getOrDefaultEnv(arg, envKey string) string { } return os.Getenv(envKey) } + +func ShouldOfferConfig() (bool, error) { + exists, err := config.IsServerConfExists() + if err != nil || exists { + return false, err + } + + var ci bool + if ci, err = clientutils.GetBoolEnvValue(coreutils.CI, false); err != nil { + return false, err + } + var offerConfig bool + if offerConfig, err = clientutils.GetBoolEnvValue(OfferConfig, !ci); err != nil { + return false, err + } + if !offerConfig { + config.SaveServersConf(make([]*config.ServerDetails, 0)) + return false, nil + } + + msg := fmt.Sprintf("To avoid this message in the future, set the %s environment variable to false.\n"+ + "The CLI commands require the URL and authentication details\n"+ + "Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n"+ + "You can also configure these parameters later using the 'jfrog rt c' command.\n"+ + "Configure now?", OfferConfig) + confirmed := coreutils.AskYesNo(msg, false) + if !confirmed { + config.SaveServersConf(make([]*config.ServerDetails, 0)) + return false, nil + } + return true, nil +} + +func CreateServerDetailsFromFlags(c *cli.Context) (details *config.ServerDetails) { + details = new(config.ServerDetails) + details.Url = clientutils.AddTrailingSlashIfNeeded(c.String(url)) + details.ArtifactoryUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configRtUrl)) + details.DistributionUrl = clientutils.AddTrailingSlashIfNeeded(c.String(distUrl)) + details.XrayUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configXrUrl)) + details.MissionControlUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configMcUrl)) + details.ApiKey = c.String(apikey) + details.User = c.String(user) + details.Password = c.String(password) + details.SshKeyPath = c.String(sshKeyPath) + details.SshPassphrase = c.String(sshPassPhrase) + details.AccessToken = c.String(accessToken) + details.ClientCertPath = c.String(clientCertPath) + details.ClientCertKeyPath = c.String(clientCertKeyPath) + details.ServerId = c.String(serverId) + details.InsecureTls = c.Bool(insecureTls) + if details.ApiKey != "" && details.User != "" && details.Password == "" { + // The API Key is deprecated, use password option instead. + details.Password = details.ApiKey + details.ApiKey = "" + } + return +} diff --git a/utils/tests/utils.go b/utils/tests/utils.go index 16ef2f94c..1a38575a9 100644 --- a/utils/tests/utils.go +++ b/utils/tests/utils.go @@ -290,9 +290,9 @@ func (m *gitManager) execGit(args ...string) (string, string, error) { return strings.TrimSpace(stdout.String()), strings.TrimSpace(stderr.String()), err } -func DeleteFiles(deleteSpec *spec.SpecFiles, artifactoryDetails *config.ArtifactoryDetails) (successCount, failCount int, err error) { +func DeleteFiles(deleteSpec *spec.SpecFiles, serverDetails *config.ServerDetails) (successCount, failCount int, err error) { deleteCommand := generic.NewDeleteCommand() - deleteCommand.SetThreads(3).SetSpec(deleteSpec).SetRtDetails(artifactoryDetails).SetDryRun(false) + deleteCommand.SetThreads(3).SetSpec(deleteSpec).SetServerDetails(serverDetails).SetDryRun(false) reader, err := deleteCommand.GetPathsToDelete() if err != nil { return 0, 0, err @@ -302,7 +302,7 @@ func DeleteFiles(deleteSpec *spec.SpecFiles, artifactoryDetails *config.Artifact } // This function makes no assertion, caller is responsible to assert as needed. -func GetBuildInfo(artDetails *config.ArtifactoryDetails, buildName, buildNumber string) (pbi *buildinfo.PublishedBuildInfo, found bool, err error) { +func GetBuildInfo(artDetails *config.ServerDetails, buildName, buildNumber string) (pbi *buildinfo.PublishedBuildInfo, found bool, err error) { servicesManager, err := artUtils.CreateServiceManager(artDetails, false) if err != nil { return nil, false, err diff --git a/xray/cli.go b/xray/cli.go index 171a5e1dd..395091a4c 100644 --- a/xray/cli.go +++ b/xray/cli.go @@ -18,7 +18,7 @@ func GetCommands() []cli.Command { return []cli.Command{ { Name: "offline-update", - Usage: offlineupdate.Description, + Description: offlineupdate.Description, HelpName: corecommon.CreateUsage("xr offline-update", offlineupdate.Description, offlineupdate.Usage), ArgsUsage: common.CreateEnvVars(), Flags: cliutils.GetCommandFlags(cliutils.OfflineUpdate),