GitLabgitlab-org

cli

main
ply9 git calls247 ms99 KiB6 cachedprotocol v2
136 lines3.4 KiBRaw
1package list
3import (
4 "context"
5 "time"
7 "github.com/MakeNowJust/heredoc/v2"
8 "github.com/spf13/cobra"
10 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 "gitlab.com/gitlab-org/cli/internal/api"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/iostreams"
15 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
16 "gitlab.com/gitlab-org/cli/internal/tableprinter"
17 "gitlab.com/gitlab-org/cli/internal/text"
20type options struct {
21 io *iostreams.IOStreams
22 apiClient func(repoHost string) (*api.Client, error)
24 controllerID int64
25 page int64
26 perPage int64
27 outputFormat string
30func NewCmd(f cmdutils.Factory) *cobra.Command {
31 opts := &options{
32 io: f.IO(),
33 apiClient: f.ApiClient,
34 }
36 cmd := &cobra.Command{
37 Use: "list <controller-id> [flags]",
38 Short: `List tokens for a runner controller. (EXPERIMENTAL)`,
39 Long: heredoc.Docf(`
40 Lists tokens for the given runner controller. Token values are not shown.
41 %s`, text.ExperimentalString),
42 Args: cobra.ExactArgs(1),
43 Example: heredoc.Doc(`
44 # List all tokens for runner controller 42
45 glab runner-controller token list 42
47 # List tokens as JSON
48 glab runner-controller token list 42 --output json`),
49 Annotations: map[string]string{
50 mcpannotations.Safe: "true",
51 },
52 RunE: func(cmd *cobra.Command, args []string) error {
53 if err := opts.complete(args); err != nil {
54 return err
55 }
56 return opts.run(cmd.Context())
57 },
58 }
60 cmdutils.EnableJSONOutput(cmd, opts.io, &opts.outputFormat)
62 fl := cmd.Flags()
63 fl.Int64VarP(&opts.page, "page", "p", 1, "Page number.")
64 fl.Int64VarP(&opts.perPage, "per-page", "P", 30, "Number of items per page.")
66 return cmd
69func (o *options) complete(args []string) error {
70 id, err := cmdutils.ParseID(args[0], "runner controller ID")
71 if err != nil {
72 return err
73 }
74 o.controllerID = id
75 return nil
78func (o *options) run(ctx context.Context) error {
79 apiClient, err := o.apiClient("")
80 if err != nil {
81 return err
82 }
83 client := apiClient.Lab()
85 listOpts := &gitlab.ListRunnerControllerTokensOptions{
86 ListOptions: gitlab.ListOptions{
87 Page: o.page,
88 PerPage: o.perPage,
89 },
90 }
92 tokens, _, err := client.RunnerControllerTokens.ListRunnerControllerTokens(o.controllerID, listOpts, gitlab.WithContext(ctx))
93 if err != nil {
94 return cmdutils.WrapError(err, "failed to list runner controller tokens")
95 }
97 switch o.outputFormat {
98 case "json":
99 return o.io.PrintJSON(tokens)
100 default:
101 return o.printTable(tokens)
102 }
105func (o *options) printTable(tokens []*gitlab.RunnerControllerToken) error {
106 c := o.io.Color()
107 table := tableprinter.NewTablePrinter()
108 table.AddRow(c.Bold("ID"), c.Bold("Description"), c.Bold("Last Used At"), c.Bold("Created At"), c.Bold("Updated At"))
109 for _, t := range tokens {
110 table.AddRow(t.ID, formatDescription(t.Description), formatLastUsedAt(c, t.LastUsedAt), t.CreatedAt, t.UpdatedAt)
111 }
112 o.io.LogInfof("%s", table.Render())
113 return nil
116// tokenActiveTimeout is the duration after which a token is considered inactive.
117// https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/ci/runner_controller_token.rb#L14
118const tokenActiveTimeout = time.Hour
120func formatLastUsedAt(c *iostreams.ColorPalette, t *time.Time) string {
121 if t == nil {
122 return "-"
123 }
124 s := t.String()
125 if time.Since(*t) > tokenActiveTimeout {
126 return c.Gray(s)
127 }
128 return c.Green(s)
131func formatDescription(desc string) string {
132 if desc == "" {
133 return "-"
134 }
135 return desc
Diagnostics9 git calls · 247 ms
CallStatusSizeTime0247 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB9 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=9
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200323 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=323
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=8185a1b139a07a59fba10180a7318233adb22fc3
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=323
git.pkt.payload.max=296
git.sideband.band1.bytes=296
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=296
git.pack.trailer=ac106711ec2e15414437a5964de4b85c86703290
Open pack map
fetchtree:0200225 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=225
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=db9f9e3562c24a8cd29c65d7d104076467dfcd8b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=225
git.pkt.payload.max=198
git.sideband.band1.bytes=198
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=198
git.pack.trailer=630e9ffc4531331e26b7d1bca3358917b64c9c9b
Open pack map
fetchtree:0200135 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=135
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=029d14eaf03135c8c3c817a1f013ddfed1fa5529
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=135
git.pkt.payload.max=108
git.sideband.band1.bytes=108
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=108
git.pack.trailer=93b6541e1b10ca765fa2a15e7063b1f69c8bd5e8
Open pack map
fetch2001.5 KiB222 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=222
git.response.bytes=1487
git.response.cache=MISS
git.response.duration_ms=222
git.fetch.wants=2454c9e8e1fb66a8e1e7ab8dc7eaeeef9ac594de
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1487
git.pkt.payload.max=1460
git.sideband.band1.bytes=1460
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e28f5029af24d3
Request
217e6473…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format