Commit 40af1c8a authored by Nejc Habjan's avatar Nejc Habjan Committed by Max Wittig
Browse files

feat(api): support the new registry protection rule endpoint

parent 9439132b
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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()
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ from .project_access_tokens import *
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 *
+5 −1
Original line number Diff line number Diff line
@@ -86,9 +86,12 @@ from .pipelines import ( # noqa: F401
)
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"
+35 −0
Original line number Diff line number Diff line
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
+2 −2
Original line number Diff line number Diff line
@@ -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",
Loading