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