From c03063e5555cce2c2ccf3ae7d26837a9773a99ef Mon Sep 17 00:00:00 2001 From: Paul Tax Date: Sat, 14 Jan 2012 16:54:02 +0100 Subject: Buckets can have dots - Function to extract bucket did not work for buckets with dots - Added extra param to work with services other then amazon S3 --- awsauth.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'awsauth.py') diff --git a/awsauth.py b/awsauth.py index eddcb6a..29c2fdb 100644 --- a/awsauth.py +++ b/awsauth.py @@ -14,6 +14,7 @@ from requests.auth import AuthBase class S3Auth(AuthBase): """Attaches AWS Authentication to the given Request object.""" + service_base_url = 's3.amazonaws.com' # List of Query String Arguments of Interest special_params = [ 'acl', 'location', 'logging', 'partNumber', 'policy', 'requestPayment', @@ -22,8 +23,11 @@ class S3Auth(AuthBase): 'response-expires', 'reponse-cache-control', 'response-content-disposition', 'response-content-encoding' ] + - def __init__(self, access_key, secret_key): + def __init__(self, access_key, secret_key, service_url=None): + if service_url: + self.service_base_url = service_url self.access_key = str(access_key) self.secret_key = str(secret_key) @@ -46,15 +50,11 @@ class S3Auth(AuthBase): #Sort alphabetical query_args.sort() - bucket = '' - split = parsedurl.netloc.split('.') - - if len(split) == 4: - bucket = split[0] - - if len(split) == 3 and split[0].lower() != 's3': - bucket = split[0] + bucket = parsedurl.netloc[:-len(self.service_base_url)] + if len(bucket) > 1: + # remove last dot + bucket = bucket[:-1] interesting_headers = {} ok_keys = ['content-md5', 'content-type', 'date'] -- cgit v1.2.1