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

Method viewToken

cli/tokens.go:290–330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

288}
289
290func (r *RootCmd) viewToken() *serpent.Command {
291 formatter := cliui.NewOutputFormatter(
292 cliui.TableFormat([]tokenListRow{}, []string{"id", "name", "scopes", "allow list", "last used", "expires at", "created at", "owner"}),
293 cliui.JSONFormat(),
294 )
295
296 cmd := &serpent.Command{
297 Use: "view <name|id>",
298 Short: "Display detailed information about a token",
299 Middleware: serpent.Chain(
300 serpent.RequireNArgs(1),
301 ),
302 Handler: func(inv *serpent.Invocation) error {
303 client, err := r.InitClient(inv)
304 if err != nil {
305 return err
306 }
307
308 tokenName := inv.Args[0]
309 token, err := client.APIKeyByName(inv.Context(), codersdk.Me, tokenName)
310 if err != nil {
311 maybeID := strings.Split(tokenName, "-")[0]
312 token, err = client.APIKeyByID(inv.Context(), codersdk.Me, maybeID)
313 if err != nil {
314 return xerrors.Errorf("fetch api key by name or id: %w", err)
315 }
316 }
317
318 row := tokenListRowFromKey(*token, "")
319 out, err := formatter.Format(inv.Context(), []tokenListRow{row})
320 if err != nil {
321 return err
322 }
323 _, err = fmt.Fprintln(inv.Stdout, out)
324 return err
325 },
326 }
327
328 formatter.AttachOptions(&cmd.Options)
329 return cmd
330}
331
332func (r *RootCmd) removeToken() *serpent.Command {
333 var deleteToken bool

Callers 1

tokensMethod · 0.95

Calls 11

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
tokenListRowFromKeyFunction · 0.85
APIKeyByNameMethod · 0.80
APIKeyByIDMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected