| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -458,3 +458,24 @@ Edit group push rules:: | |||
| 458 | 458 | Delete group push rules:: | |
| 459 | 459 | ||
| 460 | 460 | 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'}) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,7 @@ | |||
| 59 | 59 | from .reviewers import * | |
| 60 | 60 | from .runners import * | |
| 61 | 61 | from .secure_files import * | |
| 62 | + from .service_accounts import * | ||
| 62 | 63 | from .settings import * | |
| 63 | 64 | from .sidekiq import * | |
| 64 | 65 | from .snippets import * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ | |||
| 46 | 46 | from .projects import GroupProjectManager, SharedProjectManager # noqa: F401 | |
| 47 | 47 | from .push_rules import GroupPushRulesManager | |
| 48 | 48 | from .runners import GroupRunnerManager # noqa: F401 | |
| 49 | + from .service_accounts import GroupServiceAccountManager # noqa: F401 | ||
| 49 | 50 | from .statistics import GroupIssuesStatisticsManager # noqa: F401 | |
| 50 | 51 | from .variables import GroupVariableManager # noqa: F401 | |
| 51 | 52 | from .wikis import GroupWikiManager # noqa: F401 | |
@@ -102,6 +103,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 102 | 103 | variables: GroupVariableManager | |
| 103 | 104 | wikis: GroupWikiManager | |
| 104 | 105 | saml_group_links: "GroupSAMLGroupLinkManager" | |
| 106 | + service_accounts: "GroupServiceAccountManager" | ||
| 105 | 107 | ||
| 106 | 108 | @cli.register_custom_action("Group", ("project_id",)) | |
| 107 | 109 | @exc.on_http_error(exc.GitlabTransferProjectError) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + from gitlab.base import RESTManager, RESTObject | ||
| 2 | + from gitlab.mixins import CreateMixin | ||
| 3 | + from gitlab.types import RequiredOptional | ||
| 4 | + | ||
| 5 | + __all__ = ["GroupServiceAccount", "GroupServiceAccountManager"] | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + class GroupServiceAccount(RESTObject): | ||
| 9 | + pass | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + class GroupServiceAccountManager(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 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,3 +308,12 @@ def test_group_saml_group_links(group): | |||
| 308 | 308 | group.saml_group_links.create( | |
| 309 | 309 | {"saml_group_name": "saml-group-1", "access_level": 10} | |
| 310 | 310 | ) | |
| 311 | + | ||
| 312 | + | ||
| 313 | + @pytest.mark.gitlab_premium | ||
| 314 | + def test_group_service_account(group): | ||
| 315 | + service_account = group.service_accounts.create( | ||
| 316 | + {"name": "gitlab-service-account", "username": "gitlab-service-account"} | ||
| 317 | + ) | ||
| 318 | + assert service_account.name == "gitlab-service-account" | ||
| 319 | + assert service_account.username == "gitlab-service-account" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,11 @@ | |||
| 83 | 83 | "max_file_size": 100, | |
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | + service_account_content = { | ||
| 87 | + "name": "gitlab-service-account", | ||
| 88 | + "username": "gitlab-service-account", | ||
| 89 | + } | ||
| 90 | + | ||
| 86 | 91 | ||
| 87 | 92 | @pytest.fixture | |
| 88 | 93 | def resp_groups(): | |
@@ -325,6 +330,19 @@ def resp_restore_group(created_content): | |||
| 325 | 330 | yield rsps | |
| 326 | 331 | ||
| 327 | 332 | ||
| 333 | + @pytest.fixture | ||
| 334 | + def resp_create_group_service_account(): | ||
| 335 | + with responses.RequestsMock() as rsps: | ||
| 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 | + yield rsps | ||
| 344 | + | ||
| 345 | + | ||
| 328 | 346 | def test_get_group(gl, resp_groups): | |
| 329 | 347 | data = gl.groups.get(1) | |
| 330 | 348 | assert isinstance(data, gitlab.v4.objects.Group) | |
@@ -466,3 +484,11 @@ def test_delete_saml_group_link(group, resp_delete_saml_group_link): | |||
| 466 | 484 | ||
| 467 | 485 | def test_group_restore(group, resp_restore_group): | |
| 468 | 486 | group.restore() | |
| 487 | + | ||
| 488 | + | ||
| 489 | + def test_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 | + assert service_account.name == "gitlab-service-account" | ||
| 494 | + assert service_account.username == "gitlab-service-account" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments