@@ -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 }
0 commit comments