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

Commit40af1c8

Browse files
nejchmax-wittig
authored andcommitted
feat(api): support the new registry protection rule endpoint
1 parent9439132 commit40af1c8

File tree

6 files changed

+60
-20
lines changed

6 files changed

+60
-20
lines changed

‎docs/gl_objects/protected_container_repositories.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ References
99

1010
* v4 API:
1111

12-
+:class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRule`
13-
+:class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRuleManager`
14-
+:attr:`gitlab.v4.objects.Project.registry_protection_rules`
12+
+:class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRule`
13+
+:class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRuleManager`
14+
+:attr:`gitlab.v4.objects.Project.registry_repository_protection_rules`
1515

16-
* GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html
16+
* GitLab API: https://docs.gitlab.com/ee/api/container_repository_protection_rules.html
1717

1818
Examples
1919
--------
2020

2121
List the container registry protection rules for a project::
2222

23-
registry_rules = project.registry_protection_rules.list()
23+
registry_rules = project.registry_repository_protection_rules.list()
2424

2525
Create a container registry protection rule::
2626

27-
registry_rule = project.registry_protection_rules.create(
27+
registry_rule = project.registry_repository_protection_rules.create(
2828
{
2929
'repository_path_pattern': 'test/image',
3030
'minimum_access_level_for_push': 'maintainer',
@@ -39,6 +39,6 @@ Update a container registry protection rule::
3939

4040
Delete a container registry protection rule::
4141

42-
registry_rule = project.registry_protection_rules.delete(registry_rule.id)
42+
registry_rule = project.registry_repository_protection_rules.delete(registry_rule.id)
4343
# or
4444
registry_rule.delete()

‎gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from .projectsimport*
5757
from .push_rulesimport*
5858
from .registry_protection_rulesimport*
59+
from .registry_repository_protection_rulesimport*
5960
from .releasesimport*
6061
from .repositoriesimport*
6162
from .resource_groupsimport*

‎gitlab/v4/objects/projects.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@
8686
)
8787
from .project_access_tokensimportProjectAccessTokenManager# noqa: F401
8888
from .push_rulesimportProjectPushRulesManager# noqa: F401
89-
from .registry_protection_rulesimport (# noqa: F401
89+
from .registry_protection_rulesimport (# noqa: F401; deprecated
9090
ProjectRegistryProtectionRuleManager,
9191
)
92+
from .registry_repository_protection_rulesimport (# noqa: F401
93+
ProjectRegistryRepositoryProtectionRuleManager,
94+
)
9295
from .releasesimportProjectReleaseManager# noqa: F401
9396
from .repositoriesimportRepositoryMixin
9497
from .resource_groupsimportProjectResourceGroupManager
@@ -239,6 +242,7 @@ class Project(
239242
protectedtags:ProjectProtectedTagManager
240243
pushrules:ProjectPushRulesManager
241244
registry_protection_rules:ProjectRegistryProtectionRuleManager
245+
registry_repository_protection_rules:ProjectRegistryRepositoryProtectionRuleManager
242246
releases:ProjectReleaseManager
243247
resource_groups:ProjectResourceGroupManager
244248
remote_mirrors:"ProjectRemoteMirrorManager"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
fromgitlab.baseimportRESTManager,RESTObject
2+
fromgitlab.mixinsimportCreateMixin,ListMixin,SaveMixin,UpdateMethod,UpdateMixin
3+
fromgitlab.typesimportRequiredOptional
4+
5+
__all__= [
6+
"ProjectRegistryRepositoryProtectionRule",
7+
"ProjectRegistryRepositoryProtectionRuleManager",
8+
]
9+
10+
11+
classProjectRegistryRepositoryProtectionRule(SaveMixin,RESTObject):
12+
_repr_attr="repository_path_pattern"
13+
14+
15+
classProjectRegistryRepositoryProtectionRuleManager(
16+
ListMixin,CreateMixin,UpdateMixin,RESTManager
17+
):
18+
_path="/projects/{project_id}/registry/repository/protection/rules"
19+
_obj_cls=ProjectRegistryRepositoryProtectionRule
20+
_from_parent_attrs= {"project_id":"id"}
21+
_create_attrs=RequiredOptional(
22+
required=("repository_path_pattern",),
23+
optional=(
24+
"minimum_access_level_for_push",
25+
"minimum_access_level_for_delete",
26+
),
27+
)
28+
_update_attrs=RequiredOptional(
29+
optional=(
30+
"repository_path_pattern",
31+
"minimum_access_level_for_push",
32+
"minimum_access_level_for_delete",
33+
),
34+
)
35+
_update_method=UpdateMethod.PATCH

‎tests/functional/api/test_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ def protected_registry_feature(gl: Gitlab):
1111

1212
@pytest.mark.skip(reason="Not released yet")
1313
deftest_project_protected_registry(project:Project):
14-
rules=project.registry_protection_rules.list()
14+
rules=project.registry_repository_protection_rules.list()
1515
assertisinstance(rules,list)
1616

17-
protected_registry=project.registry_protection_rules.create(
17+
protected_registry=project.registry_repository_protection_rules.create(
1818
{
1919
"repository_path_pattern":"test/image",
2020
"minimum_access_level_for_push":"maintainer",

‎tests/unit/objects/test_registry_protection_rules.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html
2+
GitLab API: https://docs.gitlab.com/ee/api/container_repository_protection_rules.html
33
"""
44

55
importpytest
66
importresponses
77

8-
fromgitlab.v4.objectsimportProjectRegistryProtectionRule
8+
fromgitlab.v4.objectsimportProjectRegistryRepositoryProtectionRule
99

1010
protected_registry_content= {
1111
"id":1,
@@ -21,7 +21,7 @@ def resp_list_protected_registries():
2121
withresponses.RequestsMock()asrsps:
2222
rsps.add(
2323
method=responses.GET,
24-
url="http://localhost/api/v4/projects/1/registry/protection/rules",
24+
url="http://localhost/api/v4/projects/1/registry/repository/protection/rules",
2525
json=[protected_registry_content],
2626
content_type="application/json",
2727
status=200,
@@ -34,7 +34,7 @@ def resp_create_protected_registry():
3434
withresponses.RequestsMock()asrsps:
3535
rsps.add(
3636
method=responses.POST,
37-
url="http://localhost/api/v4/projects/1/registry/protection/rules",
37+
url="http://localhost/api/v4/projects/1/registry/repository/protection/rules",
3838
json=protected_registry_content,
3939
content_type="application/json",
4040
status=201,
@@ -50,7 +50,7 @@ def resp_update_protected_registry():
5050
withresponses.RequestsMock()asrsps:
5151
rsps.add(
5252
method=responses.PATCH,
53-
url="http://localhost/api/v4/projects/1/registry/protection/rules/1",
53+
url="http://localhost/api/v4/projects/1/registry/repository/protection/rules/1",
5454
json=updated_content,
5555
content_type="application/json",
5656
status=200,
@@ -59,24 +59,24 @@ def resp_update_protected_registry():
5959

6060

6161
deftest_list_project_protected_registries(project,resp_list_protected_registries):
62-
protected_registry=project.registry_protection_rules.list()[0]
63-
assertisinstance(protected_registry,ProjectRegistryProtectionRule)
62+
protected_registry=project.registry_repository_protection_rules.list()[0]
63+
assertisinstance(protected_registry,ProjectRegistryRepositoryProtectionRule)
6464
assertprotected_registry.repository_path_pattern=="test/image"
6565

6666

6767
deftest_create_project_protected_registry(project,resp_create_protected_registry):
68-
protected_registry=project.registry_protection_rules.create(
68+
protected_registry=project.registry_repository_protection_rules.create(
6969
{
7070
"repository_path_pattern":"test/image",
7171
"minimum_access_level_for_push":"maintainer",
7272
}
7373
)
74-
assertisinstance(protected_registry,ProjectRegistryProtectionRule)
74+
assertisinstance(protected_registry,ProjectRegistryRepositoryProtectionRule)
7575
assertprotected_registry.repository_path_pattern=="test/image"
7676

7777

7878
deftest_update_project_protected_registry(project,resp_update_protected_registry):
79-
updated=project.registry_protection_rules.update(
79+
updated=project.registry_repository_protection_rules.update(
8080
1, {"repository_path_pattern":"abc*"}
8181
)
8282
assertupdated["repository_path_pattern"]=="abc*"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp