MCPcopy Create free account
hub / github.com/cli/cli / handleAdditionalPermissions

Method handleAdditionalPermissions

pkg/cmd/codespace/create.go:353–419  ·  view source on GitHub ↗
(ctx context.Context, prompter SurveyPrompter, createParams *api.CreateCodespaceParams, allowPermissionsURL string)

Source from the content-addressed store, hash-verified

351}
352
353func (a *App) handleAdditionalPermissions(ctx context.Context, prompter SurveyPrompter, createParams *api.CreateCodespaceParams, allowPermissionsURL string) (*api.Codespace, error) {
354 var (
355 isInteractive = a.io.CanPrompt()
356 cs = a.io.ColorScheme()
357 )
358
359 fmt.Fprintf(a.io.ErrOut, "You must authorize or deny additional permissions requested by this codespace before continuing.\n")
360
361 if !isInteractive {
362 fmt.Fprintf(a.io.ErrOut, "%s in your browser to review and authorize additional permissions: %s\n", cs.Bold("Open this URL"), allowPermissionsURL)
363 fmt.Fprintf(a.io.ErrOut, "Alternatively, you can run %q with the %q option to continue without authorizing additional permissions.\n", a.io.ColorScheme().Bold("create"), cs.Bold("--default-permissions"))
364 return nil, cmdutil.SilentError
365 }
366
367 choices := []string{
368 "Continue in browser to review and authorize additional permissions (Recommended)",
369 "Continue without authorizing additional permissions",
370 }
371
372 permsSurvey := []*survey.Question{
373 {
374 Name: "accept",
375 Prompt: &survey.Select{
376 Message: "What would you like to do?",
377 Options: choices,
378 Default: choices[0],
379 },
380 Validate: survey.Required,
381 },
382 }
383
384 var answers struct {
385 Accept string
386 }
387
388 if err := prompter.Ask(permsSurvey, &answers); err != nil {
389 return nil, fmt.Errorf("error getting answers: %w", err)
390 }
391
392 // if the user chose to continue in the browser, open the URL
393 if answers.Accept == choices[0] {
394 if err := a.browser.Browse(allowPermissionsURL); err != nil {
395 return nil, fmt.Errorf("error opening browser: %w", err)
396 }
397
398 // Poll until the user has accepted the permissions or timeout
399 if err := a.pollForPermissions(ctx, createParams); err != nil {
400 return nil, fmt.Errorf("error polling for permissions: %w", err)
401 }
402 } else {
403 // If the user chose to create the codespace without the permissions,
404 // we can continue with the create opting out of the additional permissions
405 createParams.PermissionsOptOut = true
406 }
407
408 var codespace *api.Codespace
409 err := a.RunWithProgress("Creating codespace", func() (err error) {
410 codespace, err = a.apiClient.CreateCodespace(ctx, createParams)

Callers 2

CreateMethod · 0.95

Calls 9

pollForPermissionsMethod · 0.95
RunWithProgressMethod · 0.95
CanPromptMethod · 0.80
ColorSchemeMethod · 0.80
BoldMethod · 0.80
AskMethod · 0.65
ErrorfMethod · 0.65
BrowseMethod · 0.65
CreateCodespaceMethod · 0.65

Tested by 1