| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9439132 commit 40af1c8
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,22 +9,22 @@ References | |||
| 9 | 9 | ||
| 10 | 10 | * v4 API: | |
| 11 | 11 | ||
| 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` | ||
| 15 | 15 | ||
| 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 | ||
| 17 | 17 | ||
| 18 | 18 | Examples | |
| 19 | 19 | -------- | |
| 20 | 20 | ||
| 21 | 21 | List the container registry protection rules for a project:: | |
| 22 | 22 | ||
| 23 | - registry_rules = project.registry_protection_rules.list() | ||
| 23 | + registry_rules = project.registry_repository_protection_rules.list() | ||
| 24 | 24 | ||
| 25 | 25 | Create a container registry protection rule:: | |
| 26 | 26 | ||
| 27 | - registry_rule = project.registry_protection_rules.create( | ||
| 27 | + registry_rule = project.registry_repository_protection_rules.create( | ||
| 28 | 28 | { | |
| 29 | 29 | 'repository_path_pattern': 'test/image', | |
| 30 | 30 | 'minimum_access_level_for_push': 'maintainer', | |
@@ -39,6 +39,6 @@ Update a container registry protection rule:: | |||
| 39 | 39 | ||
| 40 | 40 | Delete a container registry protection rule:: | |
| 41 | 41 | ||
| 42 | - registry_rule = project.registry_protection_rules.delete(registry_rule.id) | ||
| 42 | + registry_rule = project.registry_repository_protection_rules.delete(registry_rule.id) | ||
| 43 | 43 | # or | |
| 44 | 44 | registry_rule.delete() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,7 @@ | |||
| 56 | 56 | from .projects import * | |
| 57 | 57 | from .push_rules import * | |
| 58 | 58 | from .registry_protection_rules import * | |
| 59 | + from .registry_repository_protection_rules import * | ||
| 59 | 60 | from .releases import * | |
| 60 | 61 | from .repositories import * | |
| 61 | 62 | from .resource_groups import * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,9 +86,12 @@ | |||
| 86 | 86 | ) | |
| 87 | 87 | from .project_access_tokens import ProjectAccessTokenManager # noqa: F401 | |
| 88 | 88 | from .push_rules import ProjectPushRulesManager # noqa: F401 | |
| 89 | - from .registry_protection_rules import ( # noqa: F401 | ||
| 89 | + from .registry_protection_rules import ( # noqa: F401; deprecated | ||
| 90 | 90 | ProjectRegistryProtectionRuleManager, | |
| 91 | 91 | ) | |
| 92 | + from .registry_repository_protection_rules import ( # noqa: F401 | ||
| 93 | + ProjectRegistryRepositoryProtectionRuleManager, | ||
| 94 | + ) | ||
| 92 | 95 | from .releases import ProjectReleaseManager # noqa: F401 | |
| 93 | 96 | from .repositories import RepositoryMixin | |
| 94 | 97 | from .resource_groups import ProjectResourceGroupManager | |
@@ -239,6 +242,7 @@ class Project( | |||
| 239 | 242 | protectedtags: ProjectProtectedTagManager | |
| 240 | 243 | pushrules: ProjectPushRulesManager | |
| 241 | 244 | registry_protection_rules: ProjectRegistryProtectionRuleManager | |
| 245 | + registry_repository_protection_rules: ProjectRegistryRepositoryProtectionRuleManager | ||
| 242 | 246 | releases: ProjectReleaseManager | |
| 243 | 247 | resource_groups: ProjectResourceGroupManager | |
| 244 | 248 | remote_mirrors: "ProjectRemoteMirrorManager" | |
| Original file line number | Diff line number | Diff 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,10 @@ def protected_registry_feature(gl: Gitlab): | |||
| 11 | 11 | ||
| 12 | 12 | @pytest.mark.skip(reason="Not released yet") | |
| 13 | 13 | def test_project_protected_registry(project: Project): | |
| 14 | - rules = project.registry_protection_rules.list() | ||
| 14 | + rules = project.registry_repository_protection_rules.list() | ||
| 15 | 15 | assert isinstance(rules, list) | |
| 16 | 16 | ||
| 17 | - protected_registry = project.registry_protection_rules.create( | ||
| 17 | + protected_registry = project.registry_repository_protection_rules.create( | ||
| 18 | 18 | { | |
| 19 | 19 | "repository_path_pattern": "test/image", | |
| 20 | 20 | "minimum_access_level_for_push": "maintainer", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | """ | |
| 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 | ||
| 3 | 3 | """ | |
| 4 | 4 | ||
| 5 | 5 | import pytest | |
| 6 | 6 | import responses | |
| 7 | 7 | ||
| 8 | - from gitlab.v4.objects import ProjectRegistryProtectionRule | ||
| 8 | + from gitlab.v4.objects import ProjectRegistryRepositoryProtectionRule | ||
| 9 | 9 | ||
| 10 | 10 | protected_registry_content = { | |
| 11 | 11 | "id": 1, | |
@@ -21,7 +21,7 @@ def resp_list_protected_registries(): | |||
| 21 | 21 | with responses.RequestsMock() as rsps: | |
| 22 | 22 | rsps.add( | |
| 23 | 23 | 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", | ||
| 25 | 25 | json=[protected_registry_content], | |
| 26 | 26 | content_type="application/json", | |
| 27 | 27 | status=200, | |
@@ -34,7 +34,7 @@ def resp_create_protected_registry(): | |||
| 34 | 34 | with responses.RequestsMock() as rsps: | |
| 35 | 35 | rsps.add( | |
| 36 | 36 | 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", | ||
| 38 | 38 | json=protected_registry_content, | |
| 39 | 39 | content_type="application/json", | |
| 40 | 40 | status=201, | |
@@ -50,7 +50,7 @@ def resp_update_protected_registry(): | |||
| 50 | 50 | with responses.RequestsMock() as rsps: | |
| 51 | 51 | rsps.add( | |
| 52 | 52 | 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", | ||
| 54 | 54 | json=updated_content, | |
| 55 | 55 | content_type="application/json", | |
| 56 | 56 | status=200, | |
@@ -59,24 +59,24 @@ def resp_update_protected_registry(): | |||
| 59 | 59 | ||
| 60 | 60 | ||
| 61 | 61 | 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) | ||
| 64 | 64 | assert protected_registry.repository_path_pattern == "test/image" | |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | 67 | 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( | ||
| 69 | 69 | { | |
| 70 | 70 | "repository_path_pattern": "test/image", | |
| 71 | 71 | "minimum_access_level_for_push": "maintainer", | |
| 72 | 72 | } | |
| 73 | 73 | ) | |
| 74 | - assert isinstance(protected_registry, ProjectRegistryProtectionRule) | ||
| 74 | + assert isinstance(protected_registry, ProjectRegistryRepositoryProtectionRule) | ||
| 75 | 75 | assert protected_registry.repository_path_pattern == "test/image" | |
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | 78 | 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( | ||
| 80 | 80 | 1, {"repository_path_pattern": "abc*"} | |
| 81 | 81 | ) | |
| 82 | 82 | assert updated["repository_path_pattern"] == "abc*" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments