-
Notifications
You must be signed in to change notification settings - Fork 672
Expand file tree
/
Copy pathservice_accounts.py
More file actions
155 lines (124 loc) · 4.57 KB
/
Copy pathservice_accounts.py
File metadata and controls
155 lines (124 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""
GitLab API: https://docs.gitlab.com/api/service_accounts/
"""
from gitlab.base import RESTObject
from gitlab.mixins import (
CreateMixin,
DeleteMixin,
ListMixin,
ObjectDeleteMixin,
ObjectRotateMixin,
RotateMixin,
SaveMixin,
UpdateMethod,
UpdateMixin,
)
from gitlab.types import ArrayAttribute, RequiredOptional
__all__ = [
"ServiceAccount",
"ServiceAccountManager",
"GroupServiceAccount",
"GroupServiceAccountManager",
"GroupServiceAccountAccessToken",
"GroupServiceAccountAccessTokenManager",
"ProjectServiceAccount",
"ProjectServiceAccountManager",
"ProjectServiceAccountAccessToken",
"ProjectServiceAccountAccessTokenManager",
]
_SA_ACCOUNT_ATTRS = RequiredOptional(optional=("name", "username", "email"))
_SA_TOKEN_CREATE_ATTRS = RequiredOptional(
required=("name", "scopes"), optional=("description", "expires_at")
)
_SA_TOKEN_LIST_FILTERS = (
"created_after",
"created_before",
"expires_after",
"expires_before",
"last_used_after",
"last_used_before",
"revoked",
"search",
"sort",
"state",
)
# ---------------------------------------------------------------------------
# Instance-level service accounts
# ---------------------------------------------------------------------------
class ServiceAccount(SaveMixin, RESTObject):
pass
class ServiceAccountManager(
CreateMixin[ServiceAccount], ListMixin[ServiceAccount], UpdateMixin[ServiceAccount]
):
_path = "/service_accounts"
_obj_cls = ServiceAccount
_create_attrs = _SA_ACCOUNT_ATTRS
_update_attrs = _SA_ACCOUNT_ATTRS
_update_method = UpdateMethod.PATCH
_list_filters = ("order_by", "sort")
# ---------------------------------------------------------------------------
# Group-level service accounts
# ---------------------------------------------------------------------------
class GroupServiceAccountAccessToken(ObjectDeleteMixin, ObjectRotateMixin, RESTObject):
pass
class GroupServiceAccountAccessTokenManager(
CreateMixin[GroupServiceAccountAccessToken],
DeleteMixin[GroupServiceAccountAccessToken],
ListMixin[GroupServiceAccountAccessToken],
RotateMixin[GroupServiceAccountAccessToken],
):
_path = "/groups/{group_id}/service_accounts/{user_id}/personal_access_tokens"
_obj_cls = GroupServiceAccountAccessToken
_from_parent_attrs = {"group_id": "group_id", "user_id": "id"}
_create_attrs = _SA_TOKEN_CREATE_ATTRS
_types = {"scopes": ArrayAttribute}
_list_filters = _SA_TOKEN_LIST_FILTERS
class GroupServiceAccount(SaveMixin, ObjectDeleteMixin, RESTObject):
access_tokens: GroupServiceAccountAccessTokenManager
class GroupServiceAccountManager(
CreateMixin[GroupServiceAccount],
DeleteMixin[GroupServiceAccount],
ListMixin[GroupServiceAccount],
UpdateMixin[GroupServiceAccount],
):
_path = "/groups/{group_id}/service_accounts"
_obj_cls = GroupServiceAccount
_from_parent_attrs = {"group_id": "id"}
_create_attrs = _SA_ACCOUNT_ATTRS
_update_attrs = _SA_ACCOUNT_ATTRS
_update_method = UpdateMethod.PATCH
_list_filters = ("order_by", "sort")
# ---------------------------------------------------------------------------
# Project-level service accounts
# ---------------------------------------------------------------------------
class ProjectServiceAccountAccessToken(
ObjectDeleteMixin, ObjectRotateMixin, RESTObject
):
pass
class ProjectServiceAccountAccessTokenManager(
CreateMixin[ProjectServiceAccountAccessToken],
DeleteMixin[ProjectServiceAccountAccessToken],
ListMixin[ProjectServiceAccountAccessToken],
RotateMixin[ProjectServiceAccountAccessToken],
):
_path = "/projects/{project_id}/service_accounts/{user_id}/personal_access_tokens"
_obj_cls = ProjectServiceAccountAccessToken
_from_parent_attrs = {"project_id": "project_id", "user_id": "id"}
_create_attrs = _SA_TOKEN_CREATE_ATTRS
_types = {"scopes": ArrayAttribute}
_list_filters = _SA_TOKEN_LIST_FILTERS
class ProjectServiceAccount(SaveMixin, ObjectDeleteMixin, RESTObject):
access_tokens: ProjectServiceAccountAccessTokenManager
class ProjectServiceAccountManager(
CreateMixin[ProjectServiceAccount],
DeleteMixin[ProjectServiceAccount],
ListMixin[ProjectServiceAccount],
UpdateMixin[ProjectServiceAccount],
):
_path = "/projects/{project_id}/service_accounts"
_obj_cls = ProjectServiceAccount
_from_parent_attrs = {"project_id": "id"}
_create_attrs = _SA_ACCOUNT_ATTRS
_update_attrs = _SA_ACCOUNT_ATTRS
_update_method = UpdateMethod.PATCH
_list_filters = ("order_by", "sort")