Skip to content

Commit

Permalink
Support deleting a collection (#967) (#960)
Browse files Browse the repository at this point in the history
Issue: AAH-711

Co-authored-by: Andrew Crosby <[email protected]>
  • Loading branch information
ShaiahWren and awcrosby authored Sep 23, 2021
1 parent 9758448 commit 076d526
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/438.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create remote sync api endpoint.
4 changes: 4 additions & 0 deletions galaxy_ng/app/access_control/access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ def get_object(self):
return True

return False


class ContainerRemoteSyncAccessPolicy(AccessPolicyBase):
NAME = 'ContainerSyncRemoteView'
11 changes: 10 additions & 1 deletion galaxy_ng/app/access_control/statements/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,14 @@
"effect": "allow",
"condition": "has_distro_permission:container.change_containerdistribution"
},
]
],

'ContainerSyncRemoteView': [
{
"action": "sync",
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_perms:ansible.change_containerremote"
},
],
}
4 changes: 4 additions & 0 deletions galaxy_ng/app/api/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
"remotes/",
viewsets.ContainerRemoteViewSet.as_view({'get': 'list', 'post': 'create'}),
name='execution-environments-remote-list'),
path(
"repositories/<str:base_path>/sync/",
views.ContainerSyncRemoteView.as_view(),
name='container-repository-sync'),

# image names can't start with _, so namespacing all the nested views
# under _content prevents cases where an image could be named foo/images
Expand Down
4 changes: 4 additions & 0 deletions galaxy_ng/app/api/ui/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .controller import ControllerListView

from .settings import SettingsView
from .sync import ContainerSyncRemoteView

__all__ = (
# auth
Expand All @@ -21,4 +22,7 @@

# settings
"SettingsView",

# sync
"ContainerSyncRemoteView",
)
57 changes: 57 additions & 0 deletions galaxy_ng/app/api/ui/views/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.exceptions import ValidationError

from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _

from pulp_container.app import models as pulp_models
from pulp_container.app.tasks.synchronize import synchronize as container_sync
from pulpcore.plugin.viewsets import (
OperationPostponedResponse,
)
from pulpcore.plugin.tasking import dispatch

from galaxy_ng.app.api import base as api_base
from galaxy_ng.app.access_control import access_policy
from galaxy_ng.app import models


class ContainerSyncRemoteView(api_base.APIView):
permission_classes = [access_policy.ContainerRemoteSyncAccessPolicy]
action = 'sync'

def post(self, request: Request, *args, **kwargs) -> Response:
distro_path = kwargs['base_path']
distro = get_object_or_404(pulp_models.ContainerDistribution, base_path=distro_path)

if not distro.repository or not distro.repository.remote:
raise ValidationError(
detail={'remote': _('The %s distribution does not have'
' any remotes associated with it.') % distro_path})

remote = distro.repository.remote.cast()

try:
registry = remote.registry.registry
except models.ContainerRegistryRepos.repository_remote.RelatedObjectDoesNotExist:
raise ValidationError(
detail={'remote': _('The %s remote does not have'
' any registries associated with it.') % distro_path}
)

for key, value in registry.get_connection_fields().items():
setattr(remote, key, value)
remote.save()

result = dispatch(
container_sync,
shared_resources=[remote],
exclusive_resources=[distro.repository],
kwargs={
"remote_pk": str(remote.pk),
"repository_pk": str(distro.repository.pk),
"mirror": True,
},
)
return OperationPostponedResponse(result, request)

0 comments on commit 076d526

Please sign in to comment.