feat(service-account): Add the create, update and delete commands
Description
Second of three merge requests implementing glab service-account for #8279 (closed). Follows !4292 (merged) (parent, list, get) and adds create, update and delete, for both project and group service accounts. The token subcommands come next.
Command surface
glab service-account create [--name <name>] [--username <username>] [--email <email>]
[-g, --group <group>] [-F, --output text|json] [--jq <expr>] [-R, --repo <repo>]
glab service-account update <id | username> [--name <name>] [--username <username>] [--email <email>]
[-g, --group <group>] [-F, --output text|json] [--jq <expr>] [-R, --repo <repo>]
glab service-account delete <id | username> [-y, --yes] [-g, --group <group>] [-R, --repo <repo>]Notes for review
createsends only the flags that were given. Every field is optional in the API, and an unset one gets GitLab's default (name "Service account user", a generated username and noreply email). Same pattern asdeploy-token create.updateneeds at least one of--name,--username,--email(MarkFlagsOneRequired), and changes only those fields.deleteis a soft delete.hard_deleteis not exposed, as agreed on the issue. The prompt and the result name the resolved scope, so aGITLAB_GROUPredirect is visible before anything is deleted.--yesskips the prompt and is required when not running interactively.deletereports the account as scheduled, not deleted. GitLab removes service accounts in the background (delete_asyncinNamespaces::ServiceAccounts::BaseDeleteService), so the account can still show up inlistfor a moment. The help says so.updateanddeleteaccept a username, throughResolveID, which comes back here with its first callers. A numeric argument is always an ID and makes no lookup request.- The details table is shared.
get,createandupdateprint the same table fromserviceaccountutils.PrintDetails. It gains anUnconfirmed Emailrow, shown only while a custom email address waits for confirmation - right aftercreateorupdate --emailthat is where the new address is. - Help text covers the subgroup note on
create(an account created in a subgroup can be invited only to that subgroup and below, GitLab 18.11 or later), email confirmation oncreateandupdate, and the composite identity username limit onupdate.
Commits
-
refactor(service-account): Share the account details table
create and update print the same table as get, so it moves next to the other shared helpers. A custom email waits for confirmation, so the table also shows the pending address.
-
feat(service-account): Add service-account create
Service accounts can only be created with glab api today. Unset flags are not sent, so GitLab still picks its own name, username and email.
-
feat(service-account): Add service-account update
Renaming a service account or changing its email address needs glab api today. ResolveID comes back with this first caller, so update and delete accept a username as get does.
-
feat(service-account): Add service-account delete
Removing a service account needs glab api today. GitLab deletes it in the background, so the command reports it as scheduled, and the prompt names the scope so a GITLAB_GROUP redirect is visible first.
-
test(service-account): Cover the shared details table directly
Related Issues
Related to #8279 (closed).
Not Resolves: the token subcommands are still to come in the third merge request.
How has this been tested?
Unit tests use cmdtest.SetupCmdForTest with client-go mocks.
create: no flags sends no fields, only the given flags are sent, all flags, group scope, the unconfirmed email row,--output json, an API error, positional arguments rejected,--repowith--grouprejected, both sides of the base repository requirement, andGITLAB_GROUP.update: by ID without a lookup, by username (list, then update, in order), only the changed fields sent, all fields, group scope,--output json, no field flag, unknown username, invalid ID, an API error, and the same scope cases.delete: project and group with--yesand nohard_delete, by username,--yesrequired when not interactive, unknown username, invalid ID, an API error, and the scope cases. The prompt is driven withugh: confirming deletes, declining deletes nothing, a username is resolved before the prompt so it names the ID, and a group fromGITLAB_GROUPis named in the advisory.serviceaccountutils:ResolveIDwith a numeric ID (no API call), a username found in a group and in a project, not found, and an invalid ID.PrintDetailswith and without a pending email.
Coverage: create 93.5%, update 94.1%, delete 93.5%, get 92.7%, serviceaccountutils 80.5% (List is covered from the list package).
Against a real instance: not run end to end. I have no group or project where I can hold service accounts.
lefthook run pre-push passes in full, including comment-overlap, comment-ratio, check-generated, check-args, markdownlint, vale and lychee.
Screenshots (if appropriate):
N/A - terminal output only.