From 40af1c8a14814cb0034dfeaaa33d8c38504fe34e Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Fri, 20 Dec 2024 15:08:39 +0100 Subject: [PATCH 1/4] feat(api): support the new registry protection rule endpoint --- .../protected_container_repositories.rst | 14 ++++---- gitlab/v4/objects/__init__.py | 1 + gitlab/v4/objects/projects.py | 6 +++- .../registry_repository_protection_rules.py | 35 +++++++++++++++++++ tests/functional/api/test_registry.py | 4 +-- .../objects/test_registry_protection_rules.py | 20 +++++------ 6 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 gitlab/v4/objects/registry_repository_protection_rules.py diff --git a/docs/gl_objects/protected_container_repositories.rst b/docs/gl_objects/protected_container_repositories.rst index 5990af8df..a5a939762 100644 --- a/docs/gl_objects/protected_container_repositories.rst +++ b/docs/gl_objects/protected_container_repositories.rst @@ -9,22 +9,22 @@ References * v4 API: - + :class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRule` - + :class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRuleManager` - + :attr:`gitlab.v4.objects.Project.registry_protection_rules` + + :class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRule` + + :class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRuleManager` + + :attr:`gitlab.v4.objects.Project.registry_repository_protection_rules` -* GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html +* GitLab API: https://docs.gitlab.com/ee/api/container_repository_protection_rules.html Examples -------- List the container registry protection rules for a project:: - registry_rules = project.registry_protection_rules.list() + registry_rules = project.registry_repository_protection_rules.list() Create a container registry protection rule:: - registry_rule = project.registry_protection_rules.create( + registry_rule = project.registry_repository_protection_rules.create( { 'repository_path_pattern': 'test/image', 'minimum_access_level_for_push': 'maintainer', @@ -39,6 +39,6 @@ Update a container registry protection rule:: Delete a container registry protection rule:: - registry_rule = project.registry_protection_rules.delete(registry_rule.id) + registry_rule = project.registry_repository_protection_rules.delete(registry_rule.id) # or registry_rule.delete() diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py index 7e11af525..d09b35675 100644 --- a/gitlab/v4/objects/__init__.py +++ b/gitlab/v4/objects/__init__.py @@ -56,6 +56,7 @@ from .projects import * from .push_rules import * from .registry_protection_rules import * +from .registry_repository_protection_rules import * from .releases import * from .repositories import * from .resource_groups import * diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index 937fd7221..ec54fd3c4 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -86,9 +86,12 @@ ) from .project_access_tokens import ProjectAccessTokenManager # noqa: F401 from .push_rules import ProjectPushRulesManager # noqa: F401 -from .registry_protection_rules import ( # noqa: F401 +from .registry_protection_rules import ( # noqa: F401; deprecated ProjectRegistryProtectionRuleManager, ) +from .registry_repository_protection_rules import ( # noqa: F401 + ProjectRegistryRepositoryProtectionRuleManager, +) from .releases import ProjectReleaseManager # noqa: F401 from .repositories import RepositoryMixin from .resource_groups import ProjectResourceGroupManager @@ -239,6 +242,7 @@ class Project( protectedtags: ProjectProtectedTagManager pushrules: ProjectPushRulesManager registry_protection_rules: ProjectRegistryProtectionRuleManager + registry_repository_protection_rules: ProjectRegistryRepositoryProtectionRuleManager releases: ProjectReleaseManager resource_groups: ProjectResourceGroupManager remote_mirrors: "ProjectRemoteMirrorManager" diff --git a/gitlab/v4/objects/registry_repository_protection_rules.py b/gitlab/v4/objects/registry_repository_protection_rules.py new file mode 100644 index 000000000..3c14e25f5 --- /dev/null +++ b/gitlab/v4/objects/registry_repository_protection_rules.py @@ -0,0 +1,35 @@ +from gitlab.base import RESTManager, RESTObject +from gitlab.mixins import CreateMixin, ListMixin, SaveMixin, UpdateMethod, UpdateMixin +from gitlab.types import RequiredOptional + +__all__ = [ + "ProjectRegistryRepositoryProtectionRule", + "ProjectRegistryRepositoryProtectionRuleManager", +] + + +class ProjectRegistryRepositoryProtectionRule(SaveMixin, RESTObject): + _repr_attr = "repository_path_pattern" + + +class ProjectRegistryRepositoryProtectionRuleManager( + ListMixin, CreateMixin, UpdateMixin, RESTManager +): + _path = "/projects/{project_id}/registry/repository/protection/rules" + _obj_cls = ProjectRegistryRepositoryProtectionRule + _from_parent_attrs = {"project_id": "id"} + _create_attrs = RequiredOptional( + required=("repository_path_pattern",), + optional=( + "minimum_access_level_for_push", + "minimum_access_level_for_delete", + ), + ) + _update_attrs = RequiredOptional( + optional=( + "repository_path_pattern", + "minimum_access_level_for_push", + "minimum_access_level_for_delete", + ), + ) + _update_method = UpdateMethod.PATCH diff --git a/tests/functional/api/test_registry.py b/tests/functional/api/test_registry.py index 5a3f4c9ba..4642a04bf 100644 --- a/tests/functional/api/test_registry.py +++ b/tests/functional/api/test_registry.py @@ -11,10 +11,10 @@ def protected_registry_feature(gl: Gitlab): @pytest.mark.skip(reason="Not released yet") def test_project_protected_registry(project: Project): - rules = project.registry_protection_rules.list() + rules = project.registry_repository_protection_rules.list() assert isinstance(rules, list) - protected_registry = project.registry_protection_rules.create( + protected_registry = project.registry_repository_protection_rules.create( { "repository_path_pattern": "test/image", "minimum_access_level_for_push": "maintainer", diff --git a/tests/unit/objects/test_registry_protection_rules.py b/tests/unit/objects/test_registry_protection_rules.py index c6f6d1fb4..53af1ba6c 100644 --- a/tests/unit/objects/test_registry_protection_rules.py +++ b/tests/unit/objects/test_registry_protection_rules.py @@ -1,11 +1,11 @@ """ -GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html +GitLab API: https://docs.gitlab.com/ee/api/container_repository_protection_rules.html """ import pytest import responses -from gitlab.v4.objects import ProjectRegistryProtectionRule +from gitlab.v4.objects import ProjectRegistryRepositoryProtectionRule protected_registry_content = { "id": 1, @@ -21,7 +21,7 @@ def resp_list_protected_registries(): with responses.RequestsMock() as rsps: rsps.add( method=responses.GET, - url="http://localhost/api/v4/projects/1/registry/protection/rules", + url="http://localhost/api/v4/projects/1/registry/repository/protection/rules", json=[protected_registry_content], content_type="application/json", status=200, @@ -34,7 +34,7 @@ def resp_create_protected_registry(): with responses.RequestsMock() as rsps: rsps.add( method=responses.POST, - url="http://localhost/api/v4/projects/1/registry/protection/rules", + url="http://localhost/api/v4/projects/1/registry/repository/protection/rules", json=protected_registry_content, content_type="application/json", status=201, @@ -50,7 +50,7 @@ def resp_update_protected_registry(): with responses.RequestsMock() as rsps: rsps.add( method=responses.PATCH, - url="http://localhost/api/v4/projects/1/registry/protection/rules/1", + url="http://localhost/api/v4/projects/1/registry/repository/protection/rules/1", json=updated_content, content_type="application/json", status=200, @@ -59,24 +59,24 @@ def resp_update_protected_registry(): def test_list_project_protected_registries(project, resp_list_protected_registries): - protected_registry = project.registry_protection_rules.list()[0] - assert isinstance(protected_registry, ProjectRegistryProtectionRule) + protected_registry = project.registry_repository_protection_rules.list()[0] + assert isinstance(protected_registry, ProjectRegistryRepositoryProtectionRule) assert protected_registry.repository_path_pattern == "test/image" def test_create_project_protected_registry(project, resp_create_protected_registry): - protected_registry = project.registry_protection_rules.create( + protected_registry = project.registry_repository_protection_rules.create( { "repository_path_pattern": "test/image", "minimum_access_level_for_push": "maintainer", } ) - assert isinstance(protected_registry, ProjectRegistryProtectionRule) + assert isinstance(protected_registry, ProjectRegistryRepositoryProtectionRule) assert protected_registry.repository_path_pattern == "test/image" def test_update_project_protected_registry(project, resp_update_protected_registry): - updated = project.registry_protection_rules.update( + updated = project.registry_repository_protection_rules.update( 1, {"repository_path_pattern": "abc*"} ) assert updated["repository_path_pattern"] == "abc*" From aa074496bdc4390a3629f1b0964d9846fe08ad92 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Fri, 20 Dec 2024 15:58:21 +0100 Subject: [PATCH 2/4] chore(renovate): update httpx and respx again --- .renovaterc.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.renovaterc.json b/.renovaterc.json index 4be00b01e..ea63c6cef 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -26,11 +26,6 @@ } ], "packageRules": [ - { - "description": "Pin httpx until https://github.com/lundberg/respx/issues/277 is solved", - "matchPackageNames": "httpx", - "allowedVersions": "<0.28.0" - }, { "depTypeList": [ "action" From 62b7eb7ca0adcb26912f9c0561de5c513b6ede6d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 01:35:55 +0000 Subject: [PATCH 3/4] chore(deps): update gitlab/gitlab-ee docker tag to v17.7.0-ee.0 (#3070) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- tests/functional/fixtures/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fixtures/.env b/tests/functional/fixtures/.env index 0b97a4024..d8b0d2a33 100644 --- a/tests/functional/fixtures/.env +++ b/tests/functional/fixtures/.env @@ -1,2 +1,2 @@ GITLAB_IMAGE=gitlab/gitlab-ee -GITLAB_TAG=17.6.2-ee.0 +GITLAB_TAG=17.7.0-ee.0 From c2582cf03b5dd4f3668195c13ae85ca14d755ec3 Mon Sep 17 00:00:00 2001 From: semantic-release Date: Sat, 28 Dec 2024 00:54:52 +0000 Subject: [PATCH 4/4] chore: release v5.3.0 --- CHANGELOG.md | 19 +++++++++++++++++++ gitlab/_version.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 428e2145d..972ed3a79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,25 @@ # CHANGELOG +## v5.3.0 (2024-12-28) + +### Chores + +- **deps**: Update gitlab/gitlab-ee docker tag to v17.7.0-ee.0 + ([#3070](https://github.com/python-gitlab/python-gitlab/pull/3070), + [`62b7eb7`](https://github.com/python-gitlab/python-gitlab/commit/62b7eb7ca0adcb26912f9c0561de5c513b6ede6d)) + +Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> + +- **renovate**: Update httpx and respx again + ([`aa07449`](https://github.com/python-gitlab/python-gitlab/commit/aa074496bdc4390a3629f1b0964d9846fe08ad92)) + +### Features + +- **api**: Support the new registry protection rule endpoint + ([`40af1c8`](https://github.com/python-gitlab/python-gitlab/commit/40af1c8a14814cb0034dfeaaa33d8c38504fe34e)) + + ## v5.2.0 (2024-12-17) ### Chores diff --git a/gitlab/_version.py b/gitlab/_version.py index ed39bdead..85a9c1333 100644 --- a/gitlab/_version.py +++ b/gitlab/_version.py @@ -3,4 +3,4 @@ __email__ = "gauvainpocentek@gmail.com" __license__ = "LGPL3" __title__ = "python-gitlab" -__version__ = "5.2.0" +__version__ = "5.3.0"