()
| 32 | } |
| 33 | |
| 34 | func (r *RootCmd) provisionerKeysCreate() *serpent.Command { |
| 35 | var ( |
| 36 | orgContext = agpl.NewOrganizationContext() |
| 37 | rawTags []string |
| 38 | ) |
| 39 | |
| 40 | cmd := &serpent.Command{ |
| 41 | Use: "create <name>", |
| 42 | Short: "Create a new provisioner key", |
| 43 | Middleware: serpent.Chain( |
| 44 | serpent.RequireNArgs(1), |
| 45 | ), |
| 46 | Handler: func(inv *serpent.Invocation) error { |
| 47 | ctx := inv.Context() |
| 48 | client, err := r.InitClient(inv) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | org, err := orgContext.Selected(inv, client) |
| 54 | if err != nil { |
| 55 | return xerrors.Errorf("current organization: %w", err) |
| 56 | } |
| 57 | |
| 58 | tags, err := agpl.ParseProvisionerTags(rawTags) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | res, err := client.CreateProvisionerKey(ctx, org.ID, codersdk.CreateProvisionerKeyRequest{ |
| 64 | Name: inv.Args[0], |
| 65 | Tags: tags, |
| 66 | }) |
| 67 | if err != nil { |
| 68 | return xerrors.Errorf("create provisioner key: %w", err) |
| 69 | } |
| 70 | |
| 71 | _, _ = fmt.Fprintf( |
| 72 | inv.Stdout, |
| 73 | "Successfully created provisioner key %s! Save this authentication token, it will not be shown again.\n\n%s\n", |
| 74 | pretty.Sprint(cliui.DefaultStyles.Keyword, strings.ToLower(inv.Args[0])), |
| 75 | pretty.Sprint(cliui.DefaultStyles.Keyword, res.Key), |
| 76 | ) |
| 77 | |
| 78 | return nil |
| 79 | }, |
| 80 | } |
| 81 | |
| 82 | cmd.Options = serpent.OptionSet{ |
| 83 | { |
| 84 | Flag: "tag", |
| 85 | FlagShorthand: "t", |
| 86 | Env: "CODER_PROVISIONERD_TAGS", |
| 87 | Description: "Tags to filter provisioner jobs by.", |
| 88 | Value: serpent.StringArrayOf(&rawTags), |
| 89 | }, |
| 90 | } |
| 91 | orgContext.AttachOptions(cmd) |
no test coverage detected