← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~julian-edwards/maas/anon-get-file into lp:maas

 

Julian Edwards has proposed merging lp:~julian-edwards/maas/anon-get-file into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~julian-edwards/maas/anon-get-file/+merge/98798
-- 
https://code.launchpad.net/~julian-edwards/maas/anon-get-file/+merge/98798
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/anon-get-file into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py	2012-03-21 05:56:36 +0000
+++ src/maasserver/api.py	2012-03-22 08:28:18 +0000
@@ -479,10 +479,38 @@
         return ('node_mac_handler', [node_system_id, mac_address])
 
 
+def get_file(request):
+    filename = request.GET.get("filename", None)
+    if not filename:
+        raise MAASAPIBadRequest("Filename not supplied")
+    try:
+        db_file = FileStorage.objects.get(filename=filename)
+    except FileStorage.DoesNotExist:
+        raise MAASAPINotFound("File not found")
+    return HttpResponse(db_file.data.read(), status=httplib.OK)
+
+
+@api_operations
+class AnonFilesHandler(AnonymousBaseHandler):
+    """Anonymous file operations."""
+    allowed_methods = ('GET',)
+
+    @api_exported('get', 'GET')
+    def get(self, request):
+        """Get a named file from the file storage.
+
+        :param filename: The exact name of the file you want to get.
+        :type filename: string
+        :return: The file is returned in the response content.
+        """
+        return get_file(request)
+
+
 @api_operations
 class FilesHandler(BaseHandler):
     """File management operations."""
     allowed_methods = ('GET', 'POST',)
+    anonymous = AnonFilesHandler
 
     @api_exported('get', 'GET')
     def get(self, request):
@@ -492,14 +520,7 @@
         :type filename: string
         :return: The file is returned in the response content.
         """
-        filename = request.GET.get("filename", None)
-        if not filename:
-            raise MAASAPIBadRequest("Filename not supplied")
-        try:
-            db_file = FileStorage.objects.get(filename=filename)
-        except FileStorage.DoesNotExist:
-            raise MAASAPINotFound("File not found")
-        return HttpResponse(db_file.data.read(), status=httplib.OK)
+        return get_file(request)
 
     @api_exported('add', 'POST')
     def add(self, request):