From 486cb084a7dab8163993cf709674a9434f640919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Vanzuita?= Date: Thu, 10 Nov 2022 10:47:29 -0300 Subject: [PATCH] Fix GitHub login counter (#704) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update wording, pat are generated via github ui only * fix: github login counter Signed-off-by: João Vanzuita --- cmd/local/local.go | 5 ++++- internal/handlers/github.go | 9 +++++---- internal/reports/section.go | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/local/local.go b/cmd/local/local.go index 8671b220c..7dc4722f2 100644 --- a/cmd/local/local.go +++ b/cmd/local/local.go @@ -59,13 +59,16 @@ func NewCommand() *cobra.Command { // todo: get it from GH token , use it for console localCmd.Flags().StringVar(&adminEmail, "admin-email", "", "the email address for the administrator as well as for lets-encrypt certificate emails") - localCmd.Flags().StringVar(&metaphorBranch, "metaphor-branch", "main", "metaphro application branch") + localCmd.Flags().StringVar(&metaphorBranch, "metaphor-branch", "main", "metaphor application branch") localCmd.Flags().StringVar(&gitOpsBranch, "gitops-branch", "main", "version/branch used on git clone - former: version-gitops flag") localCmd.Flags().StringVar(&gitOpsRepo, "gitops-repo", "gitops", "") localCmd.Flags().BoolVar(&enableConsole, "enable-console", true, "If hand-off screen will be presented on a browser UI") localCmd.AddCommand(NewCommandConnect()) + // on error, doesnt show helper/usage + localCmd.SilenceUsage = true + return localCmd } diff --git a/internal/handlers/github.go b/internal/handlers/github.go index 6b8d16d99..a01df8d91 100644 --- a/internal/handlers/github.go +++ b/internal/handlers/github.go @@ -84,8 +84,8 @@ func (handler GitHubHandler) AuthenticateUser() (string, error) { // todo: improve the logic for the counter var gitHubAccessToken string - var attempts = 10 - var attemptsControl = attempts + 90 + var attempts = 18 // 18 * 5 = 90 seconds + var secondsControl = 95 // 95 to start with 95-5=90 for i := 0; i < attempts; i++ { gitHubAccessToken, err = handler.service.CheckUserCodeConfirmation(gitHubDeviceFlow.DeviceCode) if err != nil { @@ -97,11 +97,12 @@ func (handler GitHubHandler) AuthenticateUser() (string, error) { return gitHubAccessToken, nil } - fmt.Printf("\rwaiting for authorization (%d seconds)", (attemptsControl)-5) - attemptsControl -= 5 + secondsControl -= 5 + fmt.Printf("\rwaiting for authorization (%d seconds)", secondsControl) // todo: handle github interval https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#response-parameters time.Sleep(5 * time.Second) } + fmt.Println("") // will avoid writing the next print in the same line return gitHubAccessToken, nil } diff --git a/internal/reports/section.go b/internal/reports/section.go index b594dc579..619271112 100644 --- a/internal/reports/section.go +++ b/internal/reports/section.go @@ -278,12 +278,12 @@ func LocalHandoffScreen(dryRun bool, silentMode bool) { func GitHubAuthToken(userCode, verificationUri string) string { var gitHubTokenReport bytes.Buffer gitHubTokenReport.WriteString(strings.Repeat("-", 69)) - gitHubTokenReport.WriteString("\nNo KUBEFIRST_GITHUB_AUTH_TOKEN env variable found!\nUse the code below to get a temporary GitHub Personal Access Token and continue\n") + gitHubTokenReport.WriteString("\nNo KUBEFIRST_GITHUB_AUTH_TOKEN env variable found!\nUse the code below to get a temporary GitHub Access Token and continue\n") gitHubTokenReport.WriteString(strings.Repeat("-", 69) + "\n") gitHubTokenReport.WriteString("1. copy the code: 📋 " + userCode + " 📋\n\n") gitHubTokenReport.WriteString("2. paste the code at the GitHub page: " + verificationUri + "\n") gitHubTokenReport.WriteString("3. authorize your organization") - gitHubTokenReport.WriteString("\n\nA GitHub Personal Access Token is required to provision GitHub repositories and run workflows in GitHub.\n\n") + gitHubTokenReport.WriteString("\n\nA GitHub Access Token is required to provision GitHub repositories and run workflows in GitHub.") return gitHubTokenReport.String() }