Browse Source

[raz] Unmarshall bucket object fully (#2042)

Romain Rigaux 4 years ago
parent
commit
e9999b1b1b
2 changed files with 27 additions and 7 deletions
  1. 27 1
      desktop/libs/aws/src/aws/s3/s3connection.py
  2. 0 6
      desktop/libs/aws/src/aws/s3/s3fs.py

+ 27 - 1
desktop/libs/aws/src/aws/s3/s3connection.py

@@ -102,7 +102,33 @@ class UrlBucket(Bucket):
     LOG.debug(response)
     LOG.debug(response.content)
 
-    k = self.key_class(self, key_name)
+    response.getheader = response.headers.get
+    response.getheaders = lambda: response.headers
+
+    # Copy from boto2 bucket.py _get_key_internal()
+    if response.status_code / 100 == 2:
+      k = self.key_class(self)
+      provider = self.connection.provider
+      # k.metadata = boto.utils.get_aws_metadata(response.msg, provider)
+      for field in Key.base_fields:
+          k.__dict__[field.lower().replace('-', '_')] = \
+              response.getheader(field)
+      # the following machinations are a workaround to the fact that
+      # apache/fastcgi omits the content-length header on HEAD
+      # requests when the content-length is zero.
+      # See http://goo.gl/0Tdax for more details.
+      clen = response.getheader('content-length')
+      if clen:
+          k.size = int(response.getheader('content-length'))
+      else:
+          k.size = 0
+      k.name = key_name
+      k.handle_version_headers(response)
+      k.handle_encryption_headers(response)
+      k.handle_restore_headers(response)
+      k.handle_addl_headers(response.getheaders())
+    else:
+      k  = None
 
     return k
 

+ 0 - 6
desktop/libs/aws/src/aws/s3/s3fs.py

@@ -168,8 +168,6 @@ class S3FileSystem(object):
     bucket_name, key_name = s3.parse_uri(path)[:2]
     bucket = self._get_bucket(bucket_name)
     try:
-      print('_get_key')
-      print(key_name)
       return bucket.get_key(key_name, validate=validate)
     except BotoClientError as e:
       raise S3FileSystemException(_('Failed to access path at "%s": %s') % (path, e.reason))
@@ -193,8 +191,6 @@ class S3FileSystem(object):
       return S3Stat.for_s3_root()
 
     try:
-      print('path:')
-      print(path)
       key = self._get_key(path, validate=True)
     except BotoClientError as e:
       raise S3FileSystemException(_('Failed to access path "%s": %s') % (path, e.reason))
@@ -206,8 +202,6 @@ class S3FileSystem(object):
       else:
         raise S3FileSystemException(_('Failed to access path "%s": %s') % (path, e.reason))
     except Exception as e: # SSL errors show up here, because they've been remapped in boto
-      import traceback
-      print(traceback.print_exc())
       raise S3FileSystemException(_('Failed to access path "%s": %s') % (path, str(e)))
     if key is None:
       key = self._get_key(path, validate=False)