diff options
author | Paul Tax <paultax@gmail.com> | 2012-01-14 16:54:02 +0100 |
---|---|---|
committer | Paul Tax <paultax@gmail.com> | 2012-01-14 16:54:02 +0100 |
commit | c03063e5555cce2c2ccf3ae7d26837a9773a99ef (patch) | |
tree | 491cb1e1c12b68b71ba2d4b90b7eba29095ecbaf /awsauth.py | |
parent | 9917626ee17ca661d43e74c8ed861c0c071cd83f (diff) | |
download | python-requests-aws-c03063e5555cce2c2ccf3ae7d26837a9773a99ef.tar.gz |
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
Diffstat (limited to 'awsauth.py')
-rw-r--r-- | awsauth.py | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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'] |