Commit 6d316491 authored by Nejc Habjan's avatar Nejc Habjan Committed by John Villalovos
Browse files

feat(api): add support for container registry protection rules

parent d509da60
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ API examples
   gl_objects/projects
   gl_objects/project_access_tokens
   gl_objects/protected_branches
   gl_objects/protected_container_repositories
   gl_objects/protected_environments
   gl_objects/protected_packages
   gl_objects/releases
+44 −0
Original line number Diff line number Diff line
################################
Protected container repositories
################################

You can list and manage container registry protection rules in a project.

References
----------

* v4 API:

  + :class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRule`
  + :class:`gitlab.v4.objects.ProjectRegistryProtectionRuleRuleManager`
  + :attr:`gitlab.v4.objects.Project.registry_protection_rules`

* GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html

Examples
--------

List the container registry protection rules for a project::

    registry_rules = project.registry_protection_rules.list()

Create a container registry protection rule::

    registry_rule = project.registry_protection_rules.create(
        {
            'repository_path_pattern': 'test/image',
            'minimum_access_level_for_push': 'maintainer',
            'minimum_access_level_for_delete': 'maintainer',
        }
    )

Update a container registry protection rule::

    registry_rule.minimum_access_level_for_push = 'owner'
    registry_rule.save()

Delete a container registry protection rule::

    registry_rule = project.registry_protection_rules.delete(registry_rule.id)
    # or
    registry_rule.delete()
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ from .pipelines import *
from .project_access_tokens import *
from .projects import *
from .push_rules import *
from .registry_protection_rules import *
from .releases import *
from .repositories import *
from .resource_groups import *
+4 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ 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
    ProjectRegistryProtectionRuleManager,
)
from .releases import ProjectReleaseManager  # noqa: F401
from .repositories import RepositoryMixin
from .resource_groups import ProjectResourceGroupManager
@@ -218,6 +221,7 @@ class Project(
    protectedbranches: ProjectProtectedBranchManager
    protectedtags: ProjectProtectedTagManager
    pushrules: ProjectPushRulesManager
    registry_protection_rules: ProjectRegistryProtectionRuleManager
    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__ = [
    "ProjectRegistryProtectionRule",
    "ProjectRegistryProtectionRuleManager",
]


class ProjectRegistryProtectionRule(SaveMixin, RESTObject):
    _repr_attr = "repository_path_pattern"


class ProjectRegistryProtectionRuleManager(
    ListMixin, CreateMixin, UpdateMixin, RESTManager
):
    _path = "/projects/{project_id}/registry/protection/rules"
    _obj_cls = ProjectRegistryProtectionRule
    _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
Loading