Skip to content

Commit e7b85e0

Browse files
committed
chore: update job_token docs and object names
Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk>
1 parent 4f5cfed commit e7b85e0

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

docs/gl_objects/job_token_scope.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ Remove a project from the project's inbound allowlist::
6767
.. warning::
6868

6969
Similar to above, the ID attributes you receive from the create and list
70-
APIs are not consistent. To safely retrieve the ID of the allowlisted project
70+
APIs are not consistent (in create() the id is returned as ``source_project_id`` whereas list() returns as ``id``). To safely retrieve the ID of the allowlisted project
7171
regardless of how the object was created, always use its ``.get_id()`` method.
7272

73+
Using ``.get_id()``::
74+
75+
resp = allowlist.create({"target_project_id": 2})
76+
allowlist_id = resp.get_id()
77+
78+
allowlists = project.allowlist.list()
79+
for allowlist in allowlists:
80+
allowlist_id == allowlist.get_id()
81+
7382
Get a project's CI/CD job token inbound groups allowlist::
7483

7584
allowlist = scope.groups_allowlist.list()

gitlab/v4/objects/job_token_scope.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
class ProjectJobTokenScope(RefreshMixin, SaveMixin, RESTObject):
2424
_id_attr = None
2525

26-
allowlist: "AllowlistedProjectManager"
27-
groups_allowlist: "AllowlistedGroupManager"
26+
allowlist: "AllowlistProjectManager"
27+
groups_allowlist: "AllowlistGroupManager"
2828

2929

3030
class ProjectJobTokenScopeManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
@@ -37,7 +37,7 @@ def get(self, **kwargs: Any) -> ProjectJobTokenScope:
3737
return cast(ProjectJobTokenScope, super().get(**kwargs))
3838

3939

40-
class AllowlistedProject(ObjectDeleteMixin, RESTObject):
40+
class AllowlistProject(ObjectDeleteMixin, RESTObject):
4141
_id_attr = "target_project_id" # note: only true for create endpoint
4242

4343
def get_id(self) -> int:
@@ -47,17 +47,17 @@ def get_id(self) -> int:
4747
try:
4848
return cast(int, getattr(self, self._id_attr))
4949
except AttributeError:
50-
return cast(int, getattr(self, "id"))
50+
return cast(int, self.id)
5151

5252

53-
class AllowlistedProjectManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
53+
class AllowlistProjectManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
5454
_path = "/projects/{project_id}/job_token_scope/allowlist"
55-
_obj_cls = AllowlistedProject
55+
_obj_cls = AllowlistProject
5656
_from_parent_attrs = {"project_id": "project_id"}
5757
_create_attrs = RequiredOptional(required=("target_project_id",))
5858

5959

60-
class AllowlistedGroup(ObjectDeleteMixin, RESTObject):
60+
class AllowlistGroup(ObjectDeleteMixin, RESTObject):
6161
_id_attr = "target_group_id" # note: only true for create endpoint
6262

6363
def get_id(self) -> int:
@@ -67,11 +67,11 @@ def get_id(self) -> int:
6767
try:
6868
return cast(int, getattr(self, self._id_attr))
6969
except AttributeError:
70-
return cast(int, getattr(self, "id"))
70+
return cast(int, self.id)
7171

7272

73-
class AllowlistedGroupManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
73+
class AllowlistGroupManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
7474
_path = "/projects/{project_id}/job_token_scope/groups_allowlist"
75-
_obj_cls = AllowlistedGroup
75+
_obj_cls = AllowlistGroup
7676
_from_parent_attrs = {"project_id": "project_id"}
7777
_create_attrs = RequiredOptional(required=("target_group_id",))

tests/unit/objects/test_job_token_scope.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from gitlab.v4.objects import ProjectJobTokenScope
99
from gitlab.v4.objects.job_token_scope import (
10-
AllowlistedGroupManager,
11-
AllowlistedProjectManager,
10+
AllowlistGroupManager,
11+
AllowlistProjectManager,
1212
)
1313

1414
job_token_scope_content = {
@@ -170,31 +170,31 @@ def test_update_job_token_scope(project, resp_patch_job_token_scope):
170170

171171
def test_get_projects_allowlist(job_token_scope, resp_get_allowlist):
172172
allowlist = job_token_scope.allowlist
173-
assert isinstance(allowlist, AllowlistedProjectManager)
173+
assert isinstance(allowlist, AllowlistProjectManager)
174174

175175
allowlist_content = allowlist.list()
176176
assert isinstance(allowlist_content, list)
177177

178178

179179
def test_add_project_to_allowlist(job_token_scope, resp_add_to_allowlist):
180180
allowlist = job_token_scope.allowlist
181-
assert isinstance(allowlist, AllowlistedProjectManager)
181+
assert isinstance(allowlist, AllowlistProjectManager)
182182

183183
resp = allowlist.create({"target_project_id": 2})
184184
assert resp.get_id() == 2
185185

186186

187187
def test_get_groups_allowlist(job_token_scope, resp_get_groups_allowlist):
188188
allowlist = job_token_scope.groups_allowlist
189-
assert isinstance(allowlist, AllowlistedGroupManager)
189+
assert isinstance(allowlist, AllowlistGroupManager)
190190

191191
allowlist_content = allowlist.list()
192192
assert isinstance(allowlist_content, list)
193193

194194

195195
def test_add_group_to_allowlist(job_token_scope, resp_add_to_groups_allowlist):
196196
allowlist = job_token_scope.groups_allowlist
197-
assert isinstance(allowlist, AllowlistedGroupManager)
197+
assert isinstance(allowlist, AllowlistGroupManager)
198198

199199
resp = allowlist.create({"target_group_id": 4})
200200
assert resp.get_id() == 4

0 commit comments

Comments
 (0)