|
23 | 23 | from rest_framework.permissions import IsAuthenticated, AllowAny |
24 | 24 | from rest_framework.response import Response |
25 | 25 | from rest_framework.viewsets import GenericViewSet |
26 | | -from rest_framework.decorators import parser_classes |
27 | 26 | from rest_framework.parsers import MultiPartParser |
28 | 27 |
|
29 | 28 | from api import monitor, models, permissions, serializers, viewsets, authentication |
|
33 | 32 | from django.views.decorators.cache import never_cache |
34 | 33 | from django.contrib.auth import REDIRECT_FIELD_NAME |
35 | 34 | from django.views.decorators.csrf import csrf_exempt |
36 | | -from django.http.response import StreamingHttpResponse |
| 35 | +from django.http.response import FileResponse, StreamingHttpResponse |
37 | 36 | from social_django.utils import psa |
38 | 37 | from social_django.views import _do_login |
39 | 38 | from social_core.utils import setting_name |
40 | | -from api import admissions, utils |
| 39 | +from api import admissions, utils, filer |
41 | 40 | from api.backend import OauthCacheManager |
42 | 41 | from api.apps_extra.social_core.actions import do_auth, do_complete |
43 | 42 |
|
@@ -827,21 +826,6 @@ def get_object(self): |
827 | 826 | app__id=self.kwargs['id'], |
828 | 827 | name=self.kwargs['name']) |
829 | 828 |
|
830 | | - @method_decorator(parser_classes([MultiPartParser])) |
831 | | - def client(self, request, **kwargs): |
832 | | - path = self.kwargs.get('path', '') |
833 | | - volume = self.get_object() |
834 | | - client = utils.VolumeClient(volume.app.id, volume, volume.app.scheduler()) |
835 | | - if request.method == "GET": |
836 | | - response = client.get(path, stream=True) |
837 | | - return StreamingHttpResponse( |
838 | | - status=response.status_code, streaming_content=response.iter_content(), |
839 | | - content_type=response.headers.get('Content-Type', 'application/octet-stream')) |
840 | | - elif request.method == "POST": |
841 | | - client.post(path, files=request.FILES) |
842 | | - return HttpResponse(status=status.HTTP_204_NO_CONTENT) |
843 | | - return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED) |
844 | | - |
845 | 829 | def expand(self, request, **kwargs): |
846 | 830 | volume = self.get_object() |
847 | 831 | volume.expand(request.data['size']) |
@@ -877,6 +861,46 @@ def path(self, request, *args, **kwargs): |
877 | 861 | return Response(serializer.data) |
878 | 862 |
|
879 | 863 |
|
| 864 | +class AppFilerClientViewSet(BaseDryccViewSet): |
| 865 | + """RESTful views for volumes apps with collaborators.""" |
| 866 | + model = models.volume.Volume |
| 867 | + parser_classes = [MultiPartParser] |
| 868 | + |
| 869 | + def get_client(self): |
| 870 | + volume = get_object_or_404( |
| 871 | + models.volume.Volume, app__id=self.kwargs['id'], name=self.kwargs['name']) |
| 872 | + return filer.FilerClient(volume.app.id, volume, volume.app.scheduler()) |
| 873 | + |
| 874 | + def list(self, request, **kwargs): |
| 875 | + path = request.query_params.get('path', '') |
| 876 | + client = self.get_client() |
| 877 | + results = client.get(path, params={"action": "list"}).json() |
| 878 | + # fake out pagination for now |
| 879 | + pagination = {'results': results, 'count': len(results)} |
| 880 | + return Response(data=pagination) |
| 881 | + |
| 882 | + def retrieve(self, request, **kwargs): |
| 883 | + path = self.kwargs.get('path', '') |
| 884 | + client = self.get_client() |
| 885 | + response = client.get(path, stream=True, params={"action": "get"}) |
| 886 | + return FileResponse( |
| 887 | + status=response.status_code, |
| 888 | + streaming_content=utils.iter_to_aiter(response.iter_content()), |
| 889 | + ) |
| 890 | + |
| 891 | + def create(self, request, **kwargs): |
| 892 | + path = request.data.get('path', '') |
| 893 | + client = self.get_client() |
| 894 | + response = client.post(path, files=request.FILES) |
| 895 | + return Response(data=response.content, status=response.status_code) |
| 896 | + |
| 897 | + def destroy(self, request, **kwargs): |
| 898 | + path = self.kwargs.get('path', '') |
| 899 | + client = self.get_client() |
| 900 | + response = client.delete(path) |
| 901 | + return Response(data=response.content, status=response.status_code) |
| 902 | + |
| 903 | + |
880 | 904 | class AppResourcesViewSet(AppResourceViewSet): |
881 | 905 | """RESTful views for resources apps with collaborators.""" |
882 | 906 | model = models.resource.Resource |
@@ -1193,8 +1217,6 @@ def status(self, request, **kwargs): |
1193 | 1217 | @method_decorator(vary_on_headers("Authorization")) |
1194 | 1218 | def metric(self, request, **kwargs): |
1195 | 1219 | app_id = self._get_app().id |
1196 | | - streaming_content = monitor.last_metrics(app_id) |
1197 | 1220 | return StreamingHttpResponse( |
1198 | | - content_type='application/json', |
1199 | | - streaming_content=streaming_content |
| 1221 | + streaming_content=monitor.last_metrics(app_id) |
1200 | 1222 | ) |
0 commit comments