Skip to content

Commit

Permalink
fix(registry-protection): fix api url
Browse files Browse the repository at this point in the history
  • Loading branch information
max-wittig authored and JohnVillalovos committed Jan 7, 2025
1 parent f4f7d7a commit 8c1aaa3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions docs/gl_objects/protected_container_repositories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ References

+ :class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRule`
+ :class:`gitlab.v4.objects.ProjectRegistryRepositoryProtectionRuleRuleManager`
+ :attr:`gitlab.v4.objects.Project.registry_repository_protection_rules`
+ :attr:`gitlab.v4.objects.Project.registry_protection_repository_rules`

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

Expand All @@ -20,11 +20,11 @@ Examples

List the container registry protection rules for a project::

registry_rules = project.registry_repository_protection_rules.list()
registry_rules = project.registry_protection_repository_rules.list()

Create a container registry protection rule::

registry_rule = project.registry_repository_protection_rules.create(
registry_rule = project.registry_protection_repository_rules.create(
{
'repository_path_pattern': 'test/image',
'minimum_access_level_for_push': 'maintainer',
Expand All @@ -39,6 +39,6 @@ Update a container registry protection rule::

Delete a container registry protection rule::

registry_rule = project.registry_repository_protection_rules.delete(registry_rule.id)
registry_rule = project.registry_protection_repository_rules.delete(registry_rule.id)
# or
registry_rule.delete()
2 changes: 1 addition & 1 deletion gitlab/v4/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
from .project_access_tokens import *
from .projects import *
from .push_rules import *
from .registry_protection_repository_rules import *
from .registry_protection_rules import *
from .registry_repository_protection_rules import *
from .releases import *
from .repositories import *
from .resource_groups import *
Expand Down
8 changes: 4 additions & 4 deletions gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@
)
from .project_access_tokens import ProjectAccessTokenManager # noqa: F401
from .push_rules import ProjectPushRulesManager # noqa: F401
from .registry_protection_repository_rules import ( # noqa: F401
ProjectRegistryRepositoryProtectionRuleManager,
)
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
Expand Down Expand Up @@ -242,7 +242,7 @@ class Project(
protectedtags: ProjectProtectedTagManager
pushrules: ProjectPushRulesManager
registry_protection_rules: ProjectRegistryProtectionRuleManager
registry_repository_protection_rules: ProjectRegistryRepositoryProtectionRuleManager
registry_protection_repository_rules: ProjectRegistryRepositoryProtectionRuleManager
releases: ProjectReleaseManager
resource_groups: ProjectResourceGroupManager
remote_mirrors: "ProjectRemoteMirrorManager"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProjectRegistryRepositoryProtectionRule(SaveMixin, RESTObject):
class ProjectRegistryRepositoryProtectionRuleManager(
ListMixin, CreateMixin, UpdateMixin, RESTManager
):
_path = "/projects/{project_id}/registry/repository/protection/rules"
_path = "/projects/{project_id}/registry/protection/repository/rules"
_obj_cls = ProjectRegistryRepositoryProtectionRule
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/api/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_repository_protection_rules.list()
rules = project.registry_protection_repository_rules.list()
assert isinstance(rules, list)

protected_registry = project.registry_repository_protection_rules.create(
protected_registry = project.registry_protection_repository_rules.create(
{
"repository_path_pattern": "test/image",
"minimum_access_level_for_push": "maintainer",
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/objects/test_registry_protection_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/repository/protection/rules",
url="http://localhost/api/v4/projects/1/registry/protection/repository/rules",
json=[protected_registry_content],
content_type="application/json",
status=200,
Expand All @@ -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/repository/protection/rules",
url="http://localhost/api/v4/projects/1/registry/protection/repository/rules",
json=protected_registry_content,
content_type="application/json",
status=201,
Expand All @@ -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/repository/protection/rules/1",
url="http://localhost/api/v4/projects/1/registry/protection/repository/rules/1",
json=updated_content,
content_type="application/json",
status=200,
Expand All @@ -59,13 +59,13 @@ def resp_update_protected_registry():


def test_list_project_protected_registries(project, resp_list_protected_registries):
protected_registry = project.registry_repository_protection_rules.list()[0]
protected_registry = project.registry_protection_repository_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_repository_protection_rules.create(
protected_registry = project.registry_protection_repository_rules.create(
{
"repository_path_pattern": "test/image",
"minimum_access_level_for_push": "maintainer",
Expand All @@ -76,7 +76,7 @@ def test_create_project_protected_registry(project, resp_create_protected_regist


def test_update_project_protected_registry(project, resp_update_protected_registry):
updated = project.registry_repository_protection_rules.update(
updated = project.registry_protection_repository_rules.update(
1, {"repository_path_pattern": "abc*"}
)
assert updated["repository_path_pattern"] == "abc*"

0 comments on commit 8c1aaa3

Please sign in to comment.