# HG changeset patch # User Peter Sanchez # Date 1571082106 25200 # Mon Oct 14 12:41:46 2019 -0700 # Node ID f0a0dcb94d666cbc67640388d019efaac79b000c # Parent f5371f956d8ea408fe7015f683ede4f817d0c31c Added bucket specification support to SecureS3 helper method diff --git a/webutils/aws/secures3.py b/webutils/aws/secures3.py --- a/webutils/aws/secures3.py +++ b/webutils/aws/secures3.py @@ -54,7 +54,7 @@ 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 @@ ) 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 @@ 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, + )