Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb187dea

Browse files
SachinKSingh28Nejc Habjan
and
Nejc Habjan
authored
feat(api): add support for gitlab service account (#2851)
Co-authored-by: Nejc Habjan <hab.nejc@siemens.com>
1 parentef8f0e1 commitb187dea

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

‎docs/gl_objects/groups.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,24 @@ Edit group push rules::
458458
Delete group push rules::
459459

460460
pr.delete()
461+
462+
Group Service Account
463+
=====================
464+
465+
Reference
466+
---------
467+
468+
* v4 API:
469+
470+
+:class:`gitlab.v4.objects.GroupServiceAccount`
471+
+:class:`gitlab.v4.objects.GroupServiceAccountManager`
472+
+:attr:`gitlab.v4.objects.Group.serviceaccounts`
473+
474+
* GitLab API: https://docs.gitlab.com/ee/api/groups.html#service-accounts
475+
476+
Examples
477+
---------
478+
479+
Create group service account (only allowed at top level group)::
480+
481+
group.serviceaccount.create({'name': 'group-service-account', 'username': 'group-service-account'})

‎gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from .reviewersimport*
6060
from .runnersimport*
6161
from .secure_filesimport*
62+
from .service_accountsimport*
6263
from .settingsimport*
6364
from .sidekiqimport*
6465
from .snippetsimport*

‎gitlab/v4/objects/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from .projectsimportGroupProjectManager,SharedProjectManager# noqa: F401
4747
from .push_rulesimportGroupPushRulesManager
4848
from .runnersimportGroupRunnerManager# noqa: F401
49+
from .service_accountsimportGroupServiceAccountManager# noqa: F401
4950
from .statisticsimportGroupIssuesStatisticsManager# noqa: F401
5051
from .variablesimportGroupVariableManager# noqa: F401
5152
from .wikisimportGroupWikiManager# noqa: F401
@@ -102,6 +103,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
102103
variables:GroupVariableManager
103104
wikis:GroupWikiManager
104105
saml_group_links:"GroupSAMLGroupLinkManager"
106+
service_accounts:"GroupServiceAccountManager"
105107

106108
@cli.register_custom_action("Group", ("project_id",))
107109
@exc.on_http_error(exc.GitlabTransferProjectError)

‎gitlab/v4/objects/service_accounts.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fromgitlab.baseimportRESTManager,RESTObject
2+
fromgitlab.mixinsimportCreateMixin
3+
fromgitlab.typesimportRequiredOptional
4+
5+
__all__= ["GroupServiceAccount","GroupServiceAccountManager"]
6+
7+
8+
classGroupServiceAccount(RESTObject):
9+
pass
10+
11+
12+
classGroupServiceAccountManager(CreateMixin,RESTManager):
13+
_path="/groups/{group_id}/service_accounts"
14+
_obj_cls=GroupServiceAccount
15+
_from_parent_attrs= {"group_id":"id"}
16+
_create_attrs=RequiredOptional(
17+
optional=("name","username"),
18+
)

‎tests/functional/api/test_groups.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,12 @@ def test_group_saml_group_links(group):
308308
group.saml_group_links.create(
309309
{"saml_group_name":"saml-group-1","access_level":10}
310310
)
311+
312+
313+
@pytest.mark.gitlab_premium
314+
deftest_group_service_account(group):
315+
service_account=group.service_accounts.create(
316+
{"name":"gitlab-service-account","username":"gitlab-service-account"}
317+
)
318+
assertservice_account.name=="gitlab-service-account"
319+
assertservice_account.username=="gitlab-service-account"

‎tests/unit/objects/test_groups.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
"max_file_size":100,
8484
}
8585

86+
service_account_content= {
87+
"name":"gitlab-service-account",
88+
"username":"gitlab-service-account",
89+
}
90+
8691

8792
@pytest.fixture
8893
defresp_groups():
@@ -325,6 +330,19 @@ def resp_restore_group(created_content):
325330
yieldrsps
326331

327332

333+
@pytest.fixture
334+
defresp_create_group_service_account():
335+
withresponses.RequestsMock()asrsps:
336+
rsps.add(
337+
method=responses.POST,
338+
url="http://localhost/api/v4/groups/1/service_accounts",
339+
json=service_account_content,
340+
content_type="application/json",
341+
status=200,
342+
)
343+
yieldrsps
344+
345+
328346
deftest_get_group(gl,resp_groups):
329347
data=gl.groups.get(1)
330348
assertisinstance(data,gitlab.v4.objects.Group)
@@ -466,3 +484,11 @@ def test_delete_saml_group_link(group, resp_delete_saml_group_link):
466484

467485
deftest_group_restore(group,resp_restore_group):
468486
group.restore()
487+
488+
489+
deftest_create_group_service_account(group,resp_create_group_service_account):
490+
service_account=group.service_accounts.create(
491+
{"name":"gitlab-service-account","username":"gitlab-service-account"}
492+
)
493+
assertservice_account.name=="gitlab-service-account"
494+
assertservice_account.username=="gitlab-service-account"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp