Merge pull request #25584 from rallytime/bp-24054-and-25576

Back-port #24054 and #25576 to 2015.5
This commit is contained in:
Mike Place 2015-07-21 15:16:37 -06:00
commit 9ffefc867e
3 changed files with 15 additions and 11 deletions

View File

@ -618,17 +618,17 @@ def _get_file_from_s3(metadata, saltenv, bucket_name, path, cached_file_path):
service_url=service_url,
verify_ssl=verify_ssl,
path=_quote(path),
local_file=cached_file_path
local_file=cached_file_path,
full_headers=True
)
if ret is not None:
for header in ret['headers']:
name, value = header.split(':', 1)
name = name.strip()
value = value.strip()
if name == 'Last-Modified':
for header_name, header_value in ret['headers'].items():
name = header_name.strip()
value = header_value.strip()
if name == 'Last-Modified'.lower():
s3_file_mtime = datetime.datetime.strptime(
value, '%a, %d %b %Y %H:%M:%S %Z')
elif name == 'Content-Length':
elif name == 'Content-Length'.lower():
s3_file_size = int(value)
if (cached_file_size == s3_file_size and
cached_file_mtime > s3_file_mtime):

View File

@ -176,7 +176,8 @@ def head(bucket, path=None, key=None, keyid=None, service_url=None,
key=key,
keyid=keyid,
service_url=service_url,
verify_ssl=verify_ssl)
verify_ssl=verify_ssl,
full_headers=True)
def put(bucket, path=None, return_bin=False, action=None, local_file=None,

View File

@ -30,7 +30,7 @@ DEFAULT_LOCATION = 'us-east-1'
def query(key, keyid, method='GET', params=None, headers=None,
requesturl=None, return_url=False, bucket=None, service_url=None,
path='', return_bin=False, action=None, local_file=None,
verify_ssl=True, location=DEFAULT_LOCATION):
verify_ssl=True, location=DEFAULT_LOCATION, full_headers=False):
'''
Perform a query against an S3-like API. This function requires that a
secret key and the id for that key are passed in. For instance:
@ -183,7 +183,10 @@ def query(key, keyid, method='GET', params=None, headers=None,
if result.status_code != requests.codes.ok:
return
ret = {'headers': []}
for header in result.headers:
ret['headers'].append(header.strip())
if full_headers:
ret['headers'] = dict(result.headers)
else:
for header in result.headers:
ret['headers'].append(header.strip())
return ret