X Tutup
Skip to content

feat(api): add full service account support at instance, group, and project level#3361

Open
syphernl wants to merge 1 commit intopython-gitlab:mainfrom
syphernl:feat/extend_service_accounts
Open

feat(api): add full service account support at instance, group, and project level#3361
syphernl wants to merge 1 commit intopython-gitlab:mainfrom
syphernl:feat/extend_service_accounts

Conversation

@syphernl
Copy link

@syphernl syphernl commented Mar 5, 2026

Changes

Extends service account support to cover all API levels and adds missing CRUD operations. Closes #2812. Supersedes #3109.

Instance-level service accounts (gl.service_accounts)

  • List: GET /service_accounts
  • Create: POST /service_accounts
  • Update: PATCH /service_accounts/:id (via .update() or .save())

Group-level service accounts (group.service_accounts)

  • Added update support: PATCH /groups/:id/service_accounts/:user_id
  • Added email parameter to create/update
  • Added order_by / sort list filters
  • Added personal access token sub-resource (service_account.access_tokens):
    list, create, delete, rotate — mirrors group access tokens

Project-level service accounts (project.service_accounts)

  • Full CRUD: list, create, update (PATCH), delete
  • Personal access token sub-resource (service_account.access_tokens): list, create, delete, rotate

Usage

# Instance level
sa = gl.service_accounts.create({"name": "bot", "username": "my-bot"})
sa.name = "renamed-bot"
sa.save()

# Group level
sa = group.service_accounts.create({"name": "ci-bot"})
token = sa.access_tokens.create({"name": "ci-token", "scopes": ["api"], "expires_at": "2026-01-01"})
token.rotate()
sa.delete()

# Project level
sa = project.service_accounts.create({"name": "deploy-bot"})
token = sa.access_tokens.create({"name": "deploy-bot-token", "scopes": ["read_repository"]})
project.service_accounts.delete(sa.id)

Notes

  • No GetMixin is added at any level. The API exposes list-only, not fetch-by-id.
  • Subgroup-level is covered by the group-level implementation (subgroups are groups in GitLab's data model).

Documentation and testing

@syphernl syphernl force-pushed the feat/extend_service_accounts branch 2 times, most recently from e25510b to 154f447 Compare March 5, 2026 08:07
@syphernl syphernl force-pushed the feat/extend_service_accounts branch from 154f447 to 358da71 Compare March 5, 2026 08:14
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.78%. Comparing base (1282712) to head (358da71).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3361      +/-   ##
==========================================
+ Coverage   95.75%   95.78%   +0.03%     
==========================================
  Files          98       98              
  Lines        6054     6099      +45     
==========================================
+ Hits         5797     5842      +45     
  Misses        257      257              
Flag Coverage Δ
api_func_v4 83.83% <100.00%> (+0.23%) ⬆️
cli_func_v4 78.83% <100.00%> (+0.15%) ⬆️
unit 90.26% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/client.py 98.55% <100.00%> (+<0.01%) ⬆️
gitlab/v4/objects/projects.py 98.94% <100.00%> (+<0.01%) ⬆️
gitlab/v4/objects/service_accounts.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support group-level service-accounts

1 participant

X Tutup