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

Commit7b0b22d

Browse files
committed
feat(job_token_scope): support job token access allowlist API
1 parent72e1aa7 commit7b0b22d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

‎docs/gl_objects/job_token_scope.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,23 @@ Refresh the current state of job token scope::
4949
scope.refresh()
5050
print(scope.inbound_enabled)
5151
# False
52+
53+
Get a project's CI/CD job token inbound allowlist::
54+
55+
allowlist = scope.allowlist.list()
56+
57+
Add a project to the project's inbound allowlist::
58+
59+
allowed_project = scope.allowlist.create({"target_project_id": 42})
60+
61+
Remove a project from the project's inbound allowlist::
62+
63+
allowed_project.delete()
64+
# or directly using a project ID
65+
scope.allowlist.delete(42)
66+
67+
..warning::
68+
69+
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
71+
regardless of how the object was created, always use its ``.get_id()`` method.

‎gitlab/v4/objects/job_token_scope.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
fromgitlab.baseimportRESTManager,RESTObject
44
fromgitlab.mixinsimport (
5+
CreateMixin,
6+
DeleteMixin,
57
GetWithoutIdMixin,
8+
ListMixin,
9+
ObjectDeleteMixin,
610
RefreshMixin,
711
SaveMixin,
812
UpdateMethod,
913
UpdateMixin,
1014
)
15+
fromgitlab.typesimportRequiredOptional
16+
1117

1218
__all__= [
1319
"ProjectJobTokenScope",
@@ -18,6 +24,8 @@
1824
classProjectJobTokenScope(RefreshMixin,SaveMixin,RESTObject):
1925
_id_attr=None
2026

27+
allowlist:"AllowlistedProjectManager"
28+
2129

2230
classProjectJobTokenScopeManager(GetWithoutIdMixin,UpdateMixin,RESTManager):
2331
_path="/projects/{project_id}/job_token_scope"
@@ -27,3 +35,23 @@ class ProjectJobTokenScopeManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
2735

2836
defget(self,**kwargs:Any)->ProjectJobTokenScope:
2937
returncast(ProjectJobTokenScope,super().get(**kwargs))
38+
39+
40+
classAllowlistedProject(ObjectDeleteMixin,RESTObject):
41+
_id_attr="target_project_id"# note: only true for create endpoint
42+
43+
defget_id(self)->int:
44+
"""Returns the id of the resource. This override deals with
45+
the fact that either an `id` or a `target_project_id` attribute
46+
is returned by the server depending on the endpoint called."""
47+
try:
48+
returncast(int,getattr(self,self._id_attr))
49+
exceptAttributeError:
50+
returncast(int,getattr(self,"id"))
51+
52+
53+
classAllowlistedProjectManager(ListMixin,CreateMixin,DeleteMixin,RESTManager):
54+
_path="/projects/{project_id}/job_token_scope/allowlist"
55+
_obj_cls=AllowlistedProject
56+
_from_parent_attrs= {"project_id":"project_id"}
57+
_create_attrs=RequiredOptional(required=("target_project_id",))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp