GitLabgitlab-org

cli

main
ply8 git calls268 ms98 KiB5 cachedprotocol v2
122 lines3.1 KiBRaw
1package list
3import (
4 "context"
6 "github.com/MakeNowJust/heredoc/v2"
7 "github.com/spf13/cobra"
9 "gitlab.com/gitlab-org/cli/internal/api"
10 "gitlab.com/gitlab-org/cli/internal/cmdutils"
11 "gitlab.com/gitlab-org/cli/internal/commands/service-account/serviceaccountutils"
12 "gitlab.com/gitlab-org/cli/internal/glrepo"
13 "gitlab.com/gitlab-org/cli/internal/iostreams"
14 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
15 "gitlab.com/gitlab-org/cli/internal/tableprinter"
18type options struct {
19 io *iostreams.IOStreams
20 apiClient func(repoHost string) (*api.Client, error)
21 baseRepo func() (glrepo.Interface, error)
23 group string
24 outputFormat string
27func NewCmd(f cmdutils.Factory) *cobra.Command {
28 opts := &options{
29 io: f.IO(),
30 apiClient: f.ApiClient,
31 baseRepo: f.BaseRepo,
32 }
34 cmd := &cobra.Command{
35 Use: "list [flags]",
36 Short: "List service accounts.",
37 Aliases: []string{"ls"},
38 Args: cobra.NoArgs,
39 ValidArgsFunction: cobra.NoFileCompletions,
40 Long: heredoc.Doc(`
41 List the service accounts of a project or a group.
42 `),
43 Example: heredoc.Doc(`
44 # List the current project's service accounts
45 glab service-account list
47 # List the service accounts of a specific project
48 glab service-account list --repo user/my-repo
50 # List a group's service accounts
51 glab service-account list --group my-group
53 # Print the ID and username of each service account
54 glab service-account list --output json --jq '.[] | "\(.id) \(.username)"'`),
55 Annotations: map[string]string{
56 mcpannotations.Safe: "true",
57 },
58 RunE: func(cmd *cobra.Command, args []string) error {
59 if err := opts.complete(cmd); err != nil {
60 return err
61 }
63 return opts.run(cmd.Context())
64 },
65 }
67 cmdutils.EnableRepoOverride(cmd, f)
69 fl := cmd.Flags()
70 fl.StringVarP(&opts.group, "group", "g", "", "List the service accounts of a `group` instead of a project. Accepts a group ID or full path.")
72 cmdutils.EnableJSONOutput(cmd, opts.io, &opts.outputFormat)
73 cmd.MarkFlagsMutuallyExclusive("repo", "group")
75 return cmd
78func (o *options) complete(cmd *cobra.Command) error {
79 group, err := cmdutils.GroupOverride(cmd)
80 if err != nil {
81 return err
82 }
83 o.group = group
85 return nil
88func (o *options) run(ctx context.Context) error {
89 client, scope, err := serviceaccountutils.NewClient(o.baseRepo, o.apiClient, o.group)
90 if err != nil {
91 return err
92 }
94 raw, accounts, err := serviceaccountutils.List(ctx, client, scope)
95 if err != nil {
96 return cmdutils.WrapError(err, "failed to list service accounts")
97 }
99 switch o.outputFormat {
100 case "json":
101 return o.io.PrintJSON(raw)
102 default:
103 return o.printTable(accounts)
104 }
107func (o *options) printTable(accounts []serviceaccountutils.Account) error {
108 if len(accounts) == 0 {
109 o.io.LogInfo("No service accounts found.")
110 return nil
111 }
113 c := o.io.Color()
114 table := tableprinter.NewTablePrinter()
115 table.AddRow(c.Bold("ID"), c.Bold("Username"), c.Bold("Name"), c.Bold("Email"))
116 for _, a := range accounts {
117 table.AddRow(a.ID, a.Username, serviceaccountutils.OrDash(a.Name), serviceaccountutils.OrDash(a.Email))
118 }
119 o.io.LogInfof("%s", table.Render())
121 return nil
Diagnostics8 git calls · 268 ms
CallStatusSizeTime0268 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
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 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
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 · 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=4273
git.response.cache=HIT
git.response.duration_ms=4
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=4
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 · hit2 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=1857
git.response.cache=HIT
git.response.duration_ms=2
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:0200322 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=322
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=ba2caccf6c55211c6b29b98f40c2358479d91b1f
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=322
git.pkt.payload.max=295
git.sideband.band1.bytes=295
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=295
git.pack.trailer=3488e558d4708096e879feba968e084c249dbe22
Open pack map
fetchtree:0200134 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=134
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=3fcd480e5469f6448a4017371b357b24d9427f9c
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=134
git.pkt.payload.max=107
git.sideband.band1.bytes=107
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=107
git.pack.trailer=51a517112551adccec6c7e76beb43a08583ce98a
Open pack map
fetch2001.3 KiB254 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=254
git.response.bytes=1310
git.response.cache=MISS
git.response.duration_ms=254
git.fetch.wants=96e132c025ef0a84819a9b4bdde55f8fd06db246
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=1310
git.pkt.payload.max=1283
git.sideband.band1.bytes=1283
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
a5e31aae9e9d3e6e
Request
703768cc…
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