Added bucket specification support to SecureS3 helper method
1 files changed, 19 insertions(+), 5 deletions(-)

M webutils/aws/secures3.py
M webutils/aws/secures3.py +19 -5
@@ 54,7 54,7 @@ class SecureS3(object):
 
         return (bucket, filename, s.scheme)
 
-    def get_auth_link(self, bucket, filename, scheme='http', expires=300,
+    def get_auth_link(self, bucket, filename, scheme='https', expires=300,
                       timestamp=None, client_method='get_object'):
         ''' Return a secure S3 link with an expiration on the download.
 

          
@@ 86,7 86,13 @@ class SecureS3(object):
         )
         return url
 
-    def get_easy_auth_link(self, url, expires=600, client_method='get_object'):
+    def get_easy_auth_link(
+        self,
+        url,
+        expires=600,
+        client_method='get_object',
+        use_bucket=None,
+    ):
         ''' url should be the full URL to the secure file hosted on S3.
             examples:
             http://s3.amazonaws.com/your-bucket/yourfile.zip

          
@@ 94,9 100,17 @@ class SecureS3(object):
             http://media.your-domain.com/yourfile.zip  (CNAME path to S3)
         '''
         try:
-            data = self.get_file_details(url)
+            bucket, fname, scheme = self.get_file_details(url)
         except ValueError:
             return None
 
-        return self.get_auth_link(*data[:2], scheme=data[2], expires=expires,
-                                  client_method=client_method)
+        if use_bucket is not None:
+            bucket = use_bucket
+
+        return self.get_auth_link(
+            bucket,
+            fname,
+            scheme=scheme,
+            expires=expires,
+            client_method=client_method,
+        )