Skip to content

Commit be5cdcb

Browse files
committed
Improve upload archive progress bar
Signed-off-by: Michael Sverdlov <[email protected]>
1 parent e6afac1 commit be5cdcb

File tree

12 files changed

+91
-173
lines changed

12 files changed

+91
-173
lines changed

artifactory/commands/buildtoollogin/buildtoollogin.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
"github.com/jfrog/jfrog-client-go/utils/log"
1818
)
1919

20-
// BuildToolLoginCommand configures registries and authentication for various build tools (npm, Yarn, Pip, Pipenv, Poetry, Go)
20+
// PackageManagerLoginCommand configures registries and authentication for various package managers (npm, Yarn, Pip, Pipenv, Poetry, Go)
2121
// based on the specified project type.
22-
type BuildToolLoginCommand struct {
23-
// buildTool represents the type of project (e.g., NPM, Yarn).
24-
buildTool project.ProjectType
22+
type PackageManagerLoginCommand struct {
23+
// packageManager represents the type of project (e.g., NPM, Yarn).
24+
packageManager project.ProjectType
2525
// repoName is the name of the repository used for configuration.
2626
repoName string
2727
// serverDetails contains Artifactory server configuration.
@@ -30,81 +30,81 @@ type BuildToolLoginCommand struct {
3030
commandName string
3131
}
3232

33-
// NewBuildToolLoginCommand initializes a new BuildToolLoginCommand for the specified project type
33+
// NewPackageManagerLoginCommand initializes a new PackageManagerLoginCommand for the specified project type
3434
// and automatically sets a command name for the login operation.
35-
func NewBuildToolLoginCommand(buildTool project.ProjectType) *BuildToolLoginCommand {
36-
return &BuildToolLoginCommand{
37-
buildTool: buildTool,
38-
commandName: buildTool.String() + "_login",
35+
func NewPackageManagerLoginCommand(packageManager project.ProjectType) *PackageManagerLoginCommand {
36+
return &PackageManagerLoginCommand{
37+
packageManager: packageManager,
38+
commandName: packageManager.String() + "_login",
3939
}
4040
}
4141

42-
// buildToolToPackageType maps project types to corresponding Artifactory package types (e.g., npm, pypi).
43-
func buildToolToPackageType(buildTool project.ProjectType) (string, error) {
44-
switch buildTool {
42+
// packageManagerToPackageType maps project types to corresponding Artifactory package types (e.g., npm, pypi).
43+
func packageManagerToPackageType(packageManager project.ProjectType) (string, error) {
44+
switch packageManager {
4545
case project.Npm, project.Yarn:
4646
return repository.Npm, nil
4747
case project.Pip, project.Pipenv, project.Poetry:
4848
return repository.Pypi, nil
4949
case project.Go:
5050
return repository.Go, nil
5151
default:
52-
return "", errorutils.CheckErrorf("unsupported build tool: %s", buildTool)
52+
return "", errorutils.CheckErrorf("unsupported package manager: %s", packageManager)
5353
}
5454
}
5555

5656
// CommandName returns the name of the login command.
57-
func (btlc *BuildToolLoginCommand) CommandName() string {
58-
return btlc.commandName
57+
func (pmlc *PackageManagerLoginCommand) CommandName() string {
58+
return pmlc.commandName
5959
}
6060

6161
// SetServerDetails assigns the server configuration details to the command.
62-
func (btlc *BuildToolLoginCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildToolLoginCommand {
63-
btlc.serverDetails = serverDetails
64-
return btlc
62+
func (pmlc *PackageManagerLoginCommand) SetServerDetails(serverDetails *config.ServerDetails) *PackageManagerLoginCommand {
63+
pmlc.serverDetails = serverDetails
64+
return pmlc
6565
}
6666

6767
// ServerDetails returns the stored server configuration details.
68-
func (btlc *BuildToolLoginCommand) ServerDetails() (*config.ServerDetails, error) {
69-
return btlc.serverDetails, nil
68+
func (pmlc *PackageManagerLoginCommand) ServerDetails() (*config.ServerDetails, error) {
69+
return pmlc.serverDetails, nil
7070
}
7171

7272
// Run executes the configuration method corresponding to the project type specified for the command.
73-
func (btlc *BuildToolLoginCommand) Run() (err error) {
74-
if btlc.repoName == "" {
73+
func (pmlc *PackageManagerLoginCommand) Run() (err error) {
74+
if pmlc.repoName == "" {
7575
// Prompt the user to select a virtual repository that matches the project type.
76-
if err = btlc.GetRepositoryNameFromUserInteractively(); err != nil {
76+
if err = pmlc.getRepositoryNameFromUserInteractively(); err != nil {
7777
return err
7878
}
7979
}
8080

81-
// Configure the appropriate tool based on the project type.
82-
switch btlc.buildTool {
81+
// Configure the appropriate package manager based on the project type.
82+
switch pmlc.packageManager {
8383
case project.Npm:
84-
err = btlc.configureNpm()
84+
err = pmlc.configureNpm()
8585
case project.Yarn:
86-
err = btlc.configureYarn()
86+
err = pmlc.configureYarn()
8787
case project.Pip, project.Pipenv:
88-
err = btlc.configurePip()
88+
err = pmlc.configurePip()
8989
case project.Poetry:
90-
err = btlc.configurePoetry()
90+
err = pmlc.configurePoetry()
9191
case project.Go:
92-
err = btlc.configureGo()
92+
err = pmlc.configureGo()
9393
default:
94-
err = errorutils.CheckErrorf("unsupported build tool: %s", btlc.buildTool)
94+
err = errorutils.CheckErrorf("unsupported package manager: %s", pmlc.packageManager)
9595
}
9696
if err != nil {
97-
return fmt.Errorf("failed to configure %s: %w", btlc.buildTool.String(), err)
97+
return fmt.Errorf("failed to configure %s: %w", pmlc.packageManager.String(), err)
9898
}
9999

100-
log.Info(fmt.Sprintf("Successfully configured %s to use JFrog Artifactory repository '%s'.", btlc.buildTool.String(), btlc.repoName))
100+
log.Info(fmt.Sprintf("Successfully configured %s to use JFrog Artifactory repository '%s'.", pmlc.packageManager.String(), pmlc.repoName))
101101
return nil
102102
}
103103

104-
// GetRepositoryNameFromUserInteractively prompts the user to select a compatible virtual repository.
105-
func (btlc *BuildToolLoginCommand) GetRepositoryNameFromUserInteractively() error {
106-
// Map the build tool to its corresponding package type.
107-
packageType, err := buildToolToPackageType(btlc.buildTool)
104+
// getRepositoryNameFromUserInteractively prompts the user to select a compatible virtual repository.
105+
func (pmlc *PackageManagerLoginCommand) getRepositoryNameFromUserInteractively() error {
106+
// Map the package manager to its corresponding package type.
107+
packageType, err := packageManagerToPackageType(pmlc.packageManager)
108108
if err != nil {
109109
return err
110110
}
@@ -114,16 +114,16 @@ func (btlc *BuildToolLoginCommand) GetRepositoryNameFromUserInteractively() erro
114114
}
115115

116116
// Prompt for repository selection based on filter parameters.
117-
btlc.repoName, err = utils.SelectRepositoryInteractively(btlc.serverDetails, repoFilterParams)
117+
pmlc.repoName, err = utils.SelectRepositoryInteractively(pmlc.serverDetails, repoFilterParams)
118118
return err
119119
}
120120

121121
// configurePip sets the global index-url for pip and pipenv to use the Artifactory PyPI repository.
122122
// Runs the following command:
123123
//
124124
// pip config set global.index-url https://<user>:<token>@<your-artifactory-url>/artifactory/api/pypi/<repo-name>/simple
125-
func (btlc *BuildToolLoginCommand) configurePip() error {
126-
repoWithCredsUrl, err := pythoncommands.GetPypiRepoUrl(btlc.serverDetails, btlc.repoName, false)
125+
func (pmlc *PackageManagerLoginCommand) configurePip() error {
126+
repoWithCredsUrl, err := pythoncommands.GetPypiRepoUrl(pmlc.serverDetails, pmlc.repoName, false)
127127
if err != nil {
128128
return err
129129
}
@@ -135,12 +135,12 @@ func (btlc *BuildToolLoginCommand) configurePip() error {
135135
//
136136
// poetry config repositories.<repo-name> https://<your-artifactory-url>/artifactory/api/pypi/<repo-name>/simple
137137
// poetry config http-basic.<repo-name> <user> <password/token>
138-
func (btlc *BuildToolLoginCommand) configurePoetry() error {
139-
repoUrl, username, password, err := pythoncommands.GetPypiRepoUrlWithCredentials(btlc.serverDetails, btlc.repoName, false)
138+
func (pmlc *PackageManagerLoginCommand) configurePoetry() error {
139+
repoUrl, username, password, err := pythoncommands.GetPypiRepoUrlWithCredentials(pmlc.serverDetails, pmlc.repoName, false)
140140
if err != nil {
141141
return err
142142
}
143-
return pythoncommands.RunPoetryConfig(repoUrl.String(), username, password, btlc.repoName)
143+
return pythoncommands.RunPoetryConfig(repoUrl.String(), username, password, pmlc.repoName)
144144
}
145145

146146
// configureNpm configures npm to use the Artifactory repository URL and sets authentication.
@@ -155,14 +155,14 @@ func (btlc *BuildToolLoginCommand) configurePoetry() error {
155155
// For basic auth:
156156
//
157157
// npm config set //your-artifactory-url/artifactory/api/npm/<repo-name>/:_auth "<base64-encoded-username:password>"
158-
func (btlc *BuildToolLoginCommand) configureNpm() error {
159-
repoUrl := commandsutils.GetNpmRepositoryUrl(btlc.repoName, btlc.serverDetails.ArtifactoryUrl)
158+
func (pmlc *PackageManagerLoginCommand) configureNpm() error {
159+
repoUrl := commandsutils.GetNpmRepositoryUrl(pmlc.repoName, pmlc.serverDetails.ArtifactoryUrl)
160160

161161
if err := npm.ConfigSet(commandsutils.NpmConfigRegistryKey, repoUrl, "npm"); err != nil {
162162
return err
163163
}
164164

165-
authKey, authValue := commandsutils.GetNpmAuthKeyValue(btlc.serverDetails, repoUrl)
165+
authKey, authValue := commandsutils.GetNpmAuthKeyValue(pmlc.serverDetails, repoUrl)
166166
if authKey != "" && authValue != "" {
167167
return npm.ConfigSet(authKey, authValue, "npm")
168168
}
@@ -181,14 +181,14 @@ func (btlc *BuildToolLoginCommand) configureNpm() error {
181181
// For basic auth:
182182
//
183183
// yarn config set //your-artifactory-url/artifactory/api/npm/<repo-name>/:_auth "<base64-encoded-username:password>"
184-
func (btlc *BuildToolLoginCommand) configureYarn() error {
185-
repoUrl := commandsutils.GetNpmRepositoryUrl(btlc.repoName, btlc.serverDetails.ArtifactoryUrl)
184+
func (pmlc *PackageManagerLoginCommand) configureYarn() error {
185+
repoUrl := commandsutils.GetNpmRepositoryUrl(pmlc.repoName, pmlc.serverDetails.ArtifactoryUrl)
186186

187187
if err := yarn.ConfigSet(commandsutils.NpmConfigRegistryKey, repoUrl, "yarn", false); err != nil {
188188
return err
189189
}
190190

191-
authKey, authValue := commandsutils.GetNpmAuthKeyValue(btlc.serverDetails, repoUrl)
191+
authKey, authValue := commandsutils.GetNpmAuthKeyValue(pmlc.serverDetails, repoUrl)
192192
if authKey != "" && authValue != "" {
193193
return yarn.ConfigSet(authKey, authValue, "yarn", false)
194194
}
@@ -199,8 +199,8 @@ func (btlc *BuildToolLoginCommand) configureYarn() error {
199199
// Runs the following command:
200200
//
201201
// go env -w GOPROXY=https://<user>:<token>@<your-artifactory-url>/artifactory/go/<repo-name>,direct
202-
func (btlc *BuildToolLoginCommand) configureGo() error {
203-
repoWithCredsUrl, err := gocommands.GetArtifactoryRemoteRepoUrl(btlc.serverDetails, btlc.repoName, gocommands.GoProxyUrlParams{Direct: true})
202+
func (pmlc *PackageManagerLoginCommand) configureGo() error {
203+
repoWithCredsUrl, err := gocommands.GetArtifactoryRemoteRepoUrl(pmlc.serverDetails, pmlc.repoName, gocommands.GoProxyUrlParams{Direct: true})
204204
if err != nil {
205205
return err
206206
}

artifactory/commands/python/poetry.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,16 @@ func poetryUpdate() (err error) {
187187
func addRepoToPyprojectFile(filepath, poetryRepoName, repoUrl string) error {
188188
viper.SetConfigType("toml")
189189
viper.SetConfigFile(filepath)
190-
err := viper.ReadInConfig()
191-
if err != nil {
190+
if err := viper.ReadInConfig(); err != nil {
192191
return errorutils.CheckErrorf("Failed to read pyproject.toml: %s", err.Error())
193192
}
194193
viper.Set("tool.poetry.source", []map[string]string{{"name": poetryRepoName, "url": repoUrl}})
195-
err = viper.WriteConfig()
196-
if err != nil {
194+
if err := viper.WriteConfig(); err != nil {
197195
return errorutils.CheckErrorf("Failed to add tool.poetry.source to pyproject.toml: %s", err.Error())
196+
198197
}
199198
log.Info(fmt.Sprintf("Added tool.poetry.source name:%q url:%q", poetryRepoName, repoUrl))
200-
return err
199+
return nil
201200
}
202201

203202
func (pc *PoetryCommand) CommandName() string {

artifactory/commands/python/python.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string, isCu
181181
func RunConfigCommand(buildTool project.ProjectType, args []string) error {
182182
log.Debug("Running", buildTool.String(), "config command...")
183183
configCmd := gofrogcmd.NewCommand(buildTool.String(), "config", args)
184-
err := gofrogcmd.RunCmd(configCmd)
185-
if err != nil {
184+
if err := gofrogcmd.RunCmd(configCmd); err != nil {
186185
return errorutils.CheckErrorf("%s config command failed with: %q", buildTool.String(), err)
187186
}
188187
return nil

artifactory/utils/npm/config-delete.go

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/jfrog/jfrog-client-go/utils/errorutils"
88
)
99

10+
// This method runs "npm config get" command and returns the value of the specified npm configuration.
1011
func ConfigGet(npmFlags []string, confName, executablePath string) (string, error) {
1112
configGetCmdConfig := createConfigGetCmdConfig(executablePath, confName, npmFlags)
1213
output, err := gofrogcmd.RunCmdOutput(configGetCmdConfig)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/jfrog/jfrog-client-go/utils/errorutils"
66
)
77

8+
// This method runs "npm config set" command and sets the npm configuration.
89
func ConfigSet(key, value, executablePath string) error {
910
configGetCmdConfig := createConfigSetCmdConfig(executablePath, key, value)
1011
_, err := gofrogcmd.RunCmdOutput(configGetCmdConfig)

artifactory/utils/yarn/configdelete.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

artifactory/utils/yarn/configget.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
)
88

9+
// This method runs "yarn config set" command and sets the yarn configuration.
910
func ConfigGet(key, executablePath string, jsonOutput bool) (string, error) {
1011
var flags []string = nil
1112
if jsonOutput {

artifactory/utils/yarn/configset.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/jfrog/jfrog-client-go/utils/errorutils"
66
)
77

8+
// This method runs "yarn config set" command and sets the yarn configuration.
89
func ConfigSet(key, value, executablePath string, jsonInput bool) error {
910
var flags []string = nil
1011
if jsonInput {

0 commit comments

Comments
 (0)