MCPcopy Index your code
hub / github.com/coder/coder / regenerateProxyToken

Method regenerateProxyToken

enterprise/cli/workspaceproxy.go:42–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func (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
90func (r *RootCmd) patchProxy() *serpent.Command {
91 var (

Callers 1

workspaceProxyMethod · 0.95

Calls 9

InitClientMethod · 0.95
WorkspaceProxyByNameMethod · 0.80
PatchWorkspaceProxyMethod · 0.80
ContextMethod · 0.65
FormatMethod · 0.65
AttachOptionsMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected