()
| 40 | } |
| 41 | |
| 42 | func (r *RootCmd) regenerateProxyToken() *serpent.Command { |
| 43 | formatter := newUpdateProxyResponseFormatter() |
| 44 | cmd := &serpent.Command{ |
| 45 | Use: "regenerate-token <name|id>", |
| 46 | Short: "Regenerate a workspace proxy authentication token. " + |
| 47 | "This will invalidate the existing authentication token.", |
| 48 | Middleware: serpent.Chain( |
| 49 | serpent.RequireNArgs(1), |
| 50 | ), |
| 51 | Handler: func(inv *serpent.Invocation) error { |
| 52 | ctx := inv.Context() |
| 53 | client, err := r.InitClient(inv) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | formatter.primaryAccessURL = client.URL.String() |
| 58 | // This is cheeky, but you can also use a uuid string in |
| 59 | // 'DeleteWorkspaceProxyByName' and it will work. |
| 60 | proxy, err := client.WorkspaceProxyByName(ctx, inv.Args[0]) |
| 61 | if err != nil { |
| 62 | return xerrors.Errorf("fetch workspace proxy %q: %w", inv.Args[0], err) |
| 63 | } |
| 64 | |
| 65 | // Only regenerate the token |
| 66 | updated, err := client.PatchWorkspaceProxy(ctx, codersdk.PatchWorkspaceProxy{ |
| 67 | ID: proxy.ID, |
| 68 | Name: proxy.Name, |
| 69 | DisplayName: proxy.DisplayName, |
| 70 | Icon: proxy.IconURL, |
| 71 | RegenerateToken: true, |
| 72 | }) |
| 73 | if err != nil { |
| 74 | return xerrors.Errorf("update workspace proxy %q: %w", inv.Args[0], err) |
| 75 | } |
| 76 | |
| 77 | output, err := formatter.Format(ctx, updated) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | _, err = fmt.Fprintln(inv.Stdout, output) |
| 82 | return err |
| 83 | }, |
| 84 | } |
| 85 | formatter.AttachOptions(&cmd.Options) |
| 86 | |
| 87 | return cmd |
| 88 | } |
| 89 | |
| 90 | func (r *RootCmd) patchProxy() *serpent.Command { |
| 91 | var ( |
no test coverage detected