Skip to content

Commit

Permalink
Fixing the handling of auth_path in HmacAuthV1Handler. Cleaning up a …
Browse files Browse the repository at this point in the history
…bit in cloudfront.
  • Loading branch information
Mitch Garnaat committed Jan 11, 2011
1 parent 132c75f commit aa90c55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
16 changes: 3 additions & 13 deletions boto/auth.py
@@ -1,4 +1,6 @@
# Copyright 2010 Google Inc.
# Copyright (c) 2011 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2011, Eucalyptus Systems, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -99,27 +101,15 @@ class HmacAuthV1Handler(AuthHandler, HmacKeys):

capability = ['hmac-v1', 's3']

S3_ENDPOINT = 's3.amazonaws.com'
GS_ENDPOINT = 'commondatastorage.googleapis.com'

def __init__(self, host, config, provider):
AuthHandler.__init__(self, host, config, provider)
HmacKeys.__init__(self, host, config, provider)
self._hmac_256 = None

def _get_bucket(self, http_request):
i = http_request.host.find('.' + self.S3_ENDPOINT)
if i != -1:
return '/' + http_request.host[:i]
i = http_request.host.find('.' + self.GS_ENDPOINT)
if i != -1:
return '/' + http_request.host[:i]
return ''

def add_auth(self, http_request):
headers = http_request.headers
method = http_request.method
auth_path = '%s%s' % (self._get_bucket(http_request), http_request.path)
auth_path = http_request.auth_path
if not headers.has_key('Date'):
headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
time.gmtime())
Expand Down
12 changes: 8 additions & 4 deletions boto/cloudfront/__init__.py
Expand Up @@ -223,17 +223,21 @@ def delete_origin_access_identity(self, access_id, etag):

# Object Invalidation

def create_invalidation_request(self, distribution_id, paths, caller_reference=None):
def create_invalidation_request(self, distribution_id, paths,
caller_reference=None):
"""Creates a new invalidation request
:see: http://docs.amazonwebservices.com/AmazonCloudFront/2010-08-01/APIReference/index.html?CreateInvalidation.html
:see: http://goo.gl/8vECq
"""
# We allow you to pass in either an array or
# an InvalidationBatch object
if not isinstance(paths, InvalidationBatch):
paths = InvalidationBatch(paths)
paths.connection = self
response = self.make_request('POST', '/%s/distribution/%s/invalidation' % (self.Version, distribution_id),
{'Content-Type' : 'text/xml'}, data=paths.to_xml())
uri = '/%s/distribution/%s/invalidation' % (self.Version,
distribution_id)
response = self.make_request('POST', uri,
{'Content-Type' : 'text/xml'},
data=paths.to_xml())
body = response.read()
if response.status == 201:
h = handler.XmlHandler(paths, self)
Expand Down
23 changes: 14 additions & 9 deletions boto/connection.py
Expand Up @@ -81,8 +81,8 @@ def __repr__(self):

class HTTPRequest(object):

def __init__(self, method, protocol, host, port, path, params,
headers, body):
def __init__(self, method, protocol, host, port, path, auth_path,
params, headers, body):
"""Represents an HTTP request.
:type method: string
Expand All @@ -101,6 +101,10 @@ def __init__(self, method, protocol, host, port, path, params,
:type path: string
:param path: URL path that is bein accessed.
:type auth_path: string
:param path: The part of the URL path used when creating the
authentication string.
:type params: dict
:param params: HTTP url query parameters, with key as name of the param,
and value as value of param.
Expand All @@ -118,6 +122,7 @@ def __init__(self, method, protocol, host, port, path, params,
self.host = host
self.port = port
self.path = path
self.auth_path = auth_path
self.params = params
self.headers = headers
self.body = body
Expand Down Expand Up @@ -478,16 +483,16 @@ def _mexe(self, method, path, data, headers, host=None, sender=None,
else:
raise BotoClientError('Please report this exception as a Boto Issue!')

def build_base_http_request(self, method, path, headers=None, data='',
host=None):
def build_base_http_request(self, method, path, auth_path,
headers=None, data='', host=None):
path = self.get_path(path)
if headers == None:
headers = {}
else:
headers = headers.copy()
host = host or self.host
return HTTPRequest(method, self.protocol, host, self.port, path, {},
headers, data)
return HTTPRequest(method, self.protocol, host, self.port, path, auth_path,
{}, headers, data)

def fill_in_auth(self, http_request):
headers = http_request.headers
Expand Down Expand Up @@ -518,8 +523,8 @@ def _send_http_request(self, http_request, sender=None,
def make_request(self, method, path, headers=None, data='', host=None,
auth_path=None, sender=None, override_num_retries=None):
"""Makes a request to the server, with stock multiple-retry logic."""
http_request = self.build_base_http_request(method, path, headers, data,
host)
http_request = self.build_base_http_request(method, path, auth_path,
headers, data, host)
http_request = self.fill_in_auth(http_request)
return self._send_http_request(http_request, sender,
override_num_retries)
Expand Down Expand Up @@ -552,7 +557,7 @@ def get_utf8_value(self, value):

def make_request(self, action, params=None, path='/', verb='GET'):
http_request = HTTPRequest(verb, self.protocol, self.host, self.port,
self.get_path(path), params, {}, '')
self.get_path(path), None, params, {}, '')
http_request.params['Action'] = action
http_request.params['Version'] = self.APIVersion
http_request = self.fill_in_auth(http_request)
Expand Down

0 comments on commit aa90c55

Please sign in to comment.