MCPcopy Create free account
hub / github.com/github/gh-aw / promptForSystemTokenUnified

Function promptForSystemTokenUnified

pkg/cli/engine_secrets.go:343–385  ·  view source on GitHub ↗

promptForSystemTokenUnified prompts the user for a system-level GitHub token (PAT) This uses PAT-specific wording instead of "API key" since system secrets are GitHub tokens

(req SecretRequirement, config EngineSecretConfig)

Source from the content-addressed store, hash-verified

341// promptForSystemTokenUnified prompts the user for a system-level GitHub token (PAT)
342// This uses PAT-specific wording instead of "API key" since system secrets are GitHub tokens
343func promptForSystemTokenUnified(req SecretRequirement, config EngineSecretConfig) error {
344 engineSecretsLog.Printf("Prompting for system token: %s", req.Name)
345
346 fmt.Fprintln(os.Stderr, "")
347 fmt.Fprintf(os.Stderr, "%s requires a GitHub Personal Access Token (PAT).\n", req.Name)
348 fmt.Fprintln(os.Stderr, "")
349 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("When needed: "+req.WhenNeeded))
350 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Recommended scopes: "+req.Description))
351 fmt.Fprintln(os.Stderr, "")
352 fmt.Fprintln(os.Stderr, "Create a token at:")
353 fmt.Fprintln(os.Stderr, console.FormatCommandMessage(" https://github.com/settings/personal-access-tokens/new"))
354 fmt.Fprintln(os.Stderr, "")
355
356 var token string
357 form := huh.NewForm(
358 huh.NewGroup(
359 huh.NewInput().
360 Title(fmt.Sprintf("Paste your %s token:", req.Name)).
361 Description("The token will be stored securely as a repository secret").
362 EchoMode(huh.EchoModePassword).
363 Value(&token).
364 Validate(func(s string) error {
365 if len(s) < 10 {
366 return errors.New("token appears to be too short")
367 }
368 return nil
369 }),
370 ),
371 ).WithTheme(styles.HuhTheme).WithAccessible(console.IsAccessibleMode())
372
373 if err := form.RunWithContext(config.ctx()); err != nil {
374 return fmt.Errorf("failed to get %s token: %w", req.Name, err)
375 }
376
377 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(req.Name+" token received"))
378
379 // Upload to repository if we have a repo slug
380 if config.RepoSlug != "" {
381 return uploadSecretToRepo(req.Name, token, config.RepoSlug, config.Verbose)
382 }
383
384 return nil
385}
386
387// promptForGenericAPIKeyUnified prompts the user for a generic API key
388func promptForGenericAPIKeyUnified(req SecretRequirement, config EngineSecretConfig) error {

Callers 1

promptForSecretFunction · 0.85

Calls 9

FormatInfoMessageFunction · 0.92
FormatCommandMessageFunction · 0.92
IsAccessibleModeFunction · 0.92
FormatSuccessMessageFunction · 0.92
uploadSecretToRepoFunction · 0.85
ctxMethod · 0.80
PrintfMethod · 0.45
ValidateMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected