Skip to content

Commit

Permalink
Fix GitHub login counter (#704)
Browse files Browse the repository at this point in the history
* chore: update wording, pat are generated via github ui only
* fix: github login counter

Signed-off-by: João Vanzuita <joao@kubeshop.io>
  • Loading branch information
João Paulo Vanzuita authored Nov 10, 2022
1 parent 30a9b64 commit 486cb08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cmd/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions internal/handlers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/reports/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 486cb08

Please sign in to comment.