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