Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub login counter #704

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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