Skip to content

Commit 40af1c8

Browse files
nejchmax-wittig
authored andcommitted
feat(api): support the new registry protection rule endpoint
1 parent 9439132 commit 40af1c8

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 .projects import *
5757
from .push_rules import *
5858
from .registry_protection_rules import *
59+
from .registry_repository_protection_rules import *
5960
from .releases import *
6061
from .repositories import *
6162
from .resource_groups import *

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_tokens import ProjectAccessTokenManager # noqa: F401
8888
from .push_rules import ProjectPushRulesManager # noqa: F401
89-
from .registry_protection_rules import ( # noqa: F401
89+
from .registry_protection_rules import ( # noqa: F401; deprecated
9090
ProjectRegistryProtectionRuleManager,
9191
)
92+
from .registry_repository_protection_rules import ( # noqa: F401
93+
ProjectRegistryRepositoryProtectionRuleManager,
94+
)
9295
from .releases import ProjectReleaseManager # noqa: F401
9396
from .repositories import RepositoryMixin
9497
from .resource_groups import ProjectResourceGroupManager
@@ -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+
from gitlab.base import RESTManager, RESTObject
2+
from gitlab.mixins import CreateMixin, ListMixin, SaveMixin, UpdateMethod, UpdateMixin
3+
from gitlab.types import RequiredOptional
4+
5+
__all__ = [
6+
"ProjectRegistryRepositoryProtectionRule",
7+
"ProjectRegistryRepositoryProtectionRuleManager",
8+
]
9+
10+
11+
class ProjectRegistryRepositoryProtectionRule(SaveMixin, RESTObject):
12+
_repr_attr = "repository_path_pattern"
13+
14+
15+
class ProjectRegistryRepositoryProtectionRuleManager(
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
def test_project_protected_registry(project: Project):
14-
rules = project.registry_protection_rules.list()
14+
rules = project.registry_repository_protection_rules.list()
1515
assert isinstance(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
import pytest
66
import responses
77

8-
from gitlab.v4.objects import ProjectRegistryProtectionRule
8+
from gitlab.v4.objects import ProjectRegistryRepositoryProtectionRule
99

1010
protected_registry_content = {
1111
"id": 1,
@@ -21,7 +21,7 @@ def resp_list_protected_registries():
2121
with responses.RequestsMock() as rsps:
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
with responses.RequestsMock() as rsps:
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
with responses.RequestsMock() as rsps:
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
def test_list_project_protected_registries(project, resp_list_protected_registries):
62-
protected_registry = project.registry_protection_rules.list()[0]
63-
assert isinstance(protected_registry, ProjectRegistryProtectionRule)
62+
protected_registry = project.registry_repository_protection_rules.list()[0]
63+
assert isinstance(protected_registry, ProjectRegistryRepositoryProtectionRule)
6464
assert protected_registry.repository_path_pattern == "test/image"
6565

6666

6767
def test_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-
assert isinstance(protected_registry, ProjectRegistryProtectionRule)
74+
assert isinstance(protected_registry, ProjectRegistryRepositoryProtectionRule)
7575
assert protected_registry.repository_path_pattern == "test/image"
7676

7777

7878
def test_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
assert updated["repository_path_pattern"] == "abc*"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy