[ARVADOS] updated: 78387b4fb0abf03bbc6523acec7babf1e6ef321b

git at public.curoverse.com git at public.curoverse.com
Tue Mar 3 16:21:04 EST 2015


Summary of changes:
 sdk/python/arvados/api.py    | 9 +++++++++
 sdk/python/tests/test_api.py | 5 +++++
 2 files changed, 14 insertions(+)

       via  78387b4fb0abf03bbc6523acec7babf1e6ef321b (commit)
      from  4d26f92c806e36c4dcfcb4809c854d5081c86fff (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 78387b4fb0abf03bbc6523acec7babf1e6ef321b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue Mar 3 16:24:21 2015 -0500

    4956: Add maximum request size checking to http_request patch in api.py.
    Raises MediaUploadSizeError if the request is too big.

diff --git a/sdk/python/arvados/api.py b/sdk/python/arvados/api.py
index a227e43..949ead3 100644
--- a/sdk/python/arvados/api.py
+++ b/sdk/python/arvados/api.py
@@ -21,6 +21,12 @@ class CredentialsFromToken(object):
     @staticmethod
     def http_request(self, uri, **kwargs):
         from httplib import BadStatusLine
+
+        if (self.max_request_size and
+            kwargs.get('body') and
+            self.max_request_size < len(kwargs['body'])):
+            raise apiclient_errors.MediaUploadSizeError("Request size %i bytes exceeds published limit of %i bytes" % (len(kwargs['body']), self.max_request_size))
+
         if 'headers' not in kwargs:
             kwargs['headers'] = {}
 
@@ -38,10 +44,12 @@ class CredentialsFromToken(object):
             # previous call did not succeed, so this is slightly
             # risky.
             return self.orig_http_request(uri, **kwargs)
+
     def authorize(self, http):
         http.arvados_api_token = self.api_token
         http.orig_http_request = http.request
         http.request = types.MethodType(self.http_request, http)
+        http.max_request_size = 0
         return http
 
 # Monkey patch discovery._cast() so objects and arrays get serialized
@@ -147,6 +155,7 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
 
     svc = apiclient_discovery.build('arvados', version, **kwargs)
     svc.api_token = token
+    kwargs['http'].max_request_size = svc._rootDesc.get('maxRequestSize', 0)
     kwargs['http'].cache = None
     return svc
 
diff --git a/sdk/python/tests/test_api.py b/sdk/python/tests/test_api.py
index 5cf2d2b..1080b3c 100644
--- a/sdk/python/tests/test_api.py
+++ b/sdk/python/tests/test_api.py
@@ -100,6 +100,11 @@ class ArvadosApiClientTest(unittest.TestCase):
             self.api.humans().delete(uuid='xyz-xyz-abcdef').execute()
         self.assertIn("500", str(err_ctx.exception))
 
+    def test_request_too_large(self):
+        with self.assertRaises(apiclient_errors.MediaUploadSizeError):
+            text = "X" * (128 * 1024 * 1024)
+            arvados.api('v1').collections().create(body={"manifest_text": text}).execute()
+
 
 if __name__ == '__main__':
     unittest.main()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list