@@ -33,8 +33,8 @@ import (
33
33
"github.com/codefresh-io/cli-v2/pkg/store"
34
34
"github.com/codefresh-io/cli-v2/pkg/util"
35
35
36
- "github.com/argoproj-labs/argocd-autopilot/pkg/git"
37
- autoPilotUtil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
36
+ apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git"
37
+ aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
38
38
"github.com/manifoldco/promptui"
39
39
"github.com/spf13/cobra"
40
40
"github.com/spf13/pflag"
@@ -115,7 +115,7 @@ func askUserIfToInstallDemoResources(cmd *cobra.Command, sampleInstall *bool) er
115
115
return nil
116
116
}
117
117
118
- func ensureRepo (cmd * cobra.Command , runtimeName string , cloneOpts * git .CloneOptions , fromAPI bool ) error {
118
+ func ensureRepo (cmd * cobra.Command , runtimeName string , cloneOpts * apgit .CloneOptions , fromAPI bool ) error {
119
119
ctx := cmd .Context ()
120
120
if cloneOpts .Repo != "" {
121
121
return nil
@@ -151,7 +151,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
151
151
repoPrompt := promptui.Prompt {
152
152
Label : "Repository URL" ,
153
153
Validate : func (value string ) error {
154
- host , orgRepo , _ , _ , _ , _ , _ := autoPilotUtil .ParseGitUrl (value )
154
+ host , orgRepo , _ , _ , _ , _ , _ := aputil .ParseGitUrl (value )
155
155
if host != "" && orgRepo != "" {
156
156
return nil
157
157
}
@@ -279,57 +279,50 @@ func getIngressClassFromUserSelect(ingressClassNames []string) (string, error) {
279
279
return result , nil
280
280
}
281
281
282
- func inferProviderFromRepo (opts * git.CloneOptions ) {
283
- if opts .Provider != "" {
284
- return
285
- }
286
-
287
- if strings .Contains (opts .Repo , "github.com" ) {
288
- opts .Provider = "github"
289
- }
290
- if strings .Contains (opts .Repo , "gitlab.com" ) {
291
- opts .Provider = "gitlab"
292
- }
293
- }
294
-
295
- func ensureGitToken (cmd * cobra.Command , cloneOpts * git.CloneOptions , verify bool ) error {
296
- errMessage := "Value stored in environment variable GIT_TOKEN is invalid; enter a valid runtime token"
282
+ // ensureGitToken gets the runtime token from the user (if !silent), and verifys it witht he provider (if available)
283
+ func ensureGitToken (cmd * cobra.Command , gitProvider cfgit.Provider , cloneOpts * apgit.CloneOptions ) error {
284
+ ctx := cmd .Context ()
285
+ errMessage := "Value stored in environment variable GIT_TOKEN is invalid; enter a valid runtime token: %w"
297
286
if cloneOpts .Auth .Password == "" && ! store .Get ().Silent {
298
287
err := getGitTokenFromUserInput (cmd )
299
- errMessage = "Invalid runtime token; enter a valid token"
288
+ errMessage = "Invalid runtime token; enter a valid token: %w "
300
289
if err != nil {
301
290
return err
302
291
}
303
292
}
304
293
305
- if verify {
306
- err := cfgit .VerifyToken (cmd . Context (), cloneOpts . Provider , cloneOpts .Auth .Password , cfgit . RuntimeToken )
294
+ if gitProvider != nil {
295
+ err := gitProvider .VerifyToken (ctx , cfgit . RuntimeToken , cloneOpts .Auth .Password )
307
296
if err != nil {
308
297
// in case when we get invalid value from env variable TOKEN we clean
309
298
cloneOpts .Auth .Password = ""
310
- return fmt .Errorf (errMessage )
299
+ return fmt .Errorf (errMessage , err )
311
300
}
312
- }
313
-
314
- if cloneOpts .Auth .Password == "" {
301
+ } else if cloneOpts .Auth .Password == "" {
315
302
return fmt .Errorf ("must provide a git token using --git-token" )
316
303
}
317
304
318
305
return nil
319
306
}
320
307
321
- func ensureGitPAT (cmd * cobra.Command , opts * RuntimeInstallOptions ) error {
308
+ // ensureGitPAT verifys the user's Personal Access Token (if it is different from the Runtime Token)
309
+ func ensureGitPAT (ctx context.Context , opts * RuntimeInstallOptions ) error {
322
310
if opts .GitIntegrationRegistrationOpts .Token == "" {
323
311
opts .GitIntegrationRegistrationOpts .Token = opts .InsCloneOpts .Auth .Password
324
- currentUser , err := cfConfig .NewClient ().Users ().GetCurrent (cmd . Context () )
312
+ currentUser , err := cfConfig .NewClient ().Users ().GetCurrent (ctx )
325
313
if err != nil {
326
314
return fmt .Errorf ("failed to retrieve username from platform: %w" , err )
327
315
}
328
316
329
- log .G (cmd .Context ()).Infof ("Personal git token was not provided. Using runtime git token to register user: \" %s\" . You may replace your personal git token at any time from the UI in the user settings" , currentUser .Name )
317
+ log .G (ctx ).Infof ("Personal git token was not provided. Using runtime git token to register user: \" %s\" . You may replace your personal git token at any time from the UI in the user settings" , currentUser .Name )
318
+ return nil
319
+ }
320
+
321
+ if opts .gitProvider != nil {
322
+ return opts .gitProvider .VerifyToken (ctx , cfgit .PersonalToken , opts .InsCloneOpts .Auth .Password )
330
323
}
331
324
332
- return cfgit . VerifyToken ( cmd . Context (), opts . InsCloneOpts . Provider , opts . GitIntegrationRegistrationOpts . Token , cfgit . PersonalToken )
325
+ return nil
333
326
}
334
327
335
328
func getGitTokenFromUserInput (cmd * cobra.Command ) error {
0 commit comments