Permalink
Browse files

Merge pull request #3738 from houglum/develop

Allow specifying s3 host from boto config file.
  • Loading branch information...
mfschwartz committed Jun 14, 2017
2 parents af045f9 + 221699b commit dcfc751204bacb76c0db1738681c97530f3b7b70
Showing with 38 additions and 7 deletions.
  1. +6 −3 boto/s3/connection.py
  2. +4 −1 tests/integration/s3/test_key.py
  3. +28 −3 tests/unit/s3/test_connection.py
@@ -161,7 +161,7 @@ class HostRequiredError(BotoClientError):

class S3Connection(AWSAuthConnection):

DefaultHost = boto.config.get('s3', 'host', 's3.amazonaws.com')
DefaultHost = 's3.amazonaws.com'
DefaultCallingFormat = boto.config.get('s3', 'calling_format', 'boto.s3.connection.SubdomainCallingFormat')
QueryString = 'Signature=%s&Expires=%d&AWSAccessKeyId=%s'

@@ -174,9 +174,12 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
suppress_consec_slashes=True, anon=False,
validate_certs=None, profile_name=None):
no_host_provided = False
# Try falling back to the boto config file's value, if present.
if host is NoHostProvided:
no_host_provided = True
host = self.DefaultHost
host = boto.config.get('s3', 'host')
if host is None:
host = self.DefaultHost
no_host_provided = True
if isinstance(calling_format, six.string_types):
calling_format=boto.utils.find_class(calling_format)()
self.calling_format = calling_format
@@ -419,7 +419,10 @@ def test_header_encoding(self):
remote_metadata = check._get_remote_metadata()

# TODO: investigate whether encoding ' ' as '%20' makes sense
self.assertEqual(check.cache_control, 'public,%20max-age=500')
self.assertIn(
check.cache_control,
('public,%20max-age=500', 'public, max-age=500')
)
self.assertEqual(remote_metadata['cache-control'], 'public,%20max-age=500')
self.assertEqual(check.get_metadata('test-plus'), 'A plus (+)')
self.assertEqual(check.content_disposition, 'filename=Sch%C3%B6ne%20Zeit.txt')
@@ -84,6 +84,8 @@ def test_historical_behavior(self):
self.assertEqual(self.service_connection.host, 's3.amazonaws.com')

def test_sigv4_opt_in(self):
host_value = 's3.cn-north-1.amazonaws.com.cn'

# Switch it at the config, so we can check to see how the host is
# handled.
self.config = {
@@ -92,26 +94,49 @@ def test_sigv4_opt_in(self):
}
}

# Should raise an error if no host is given in either the config or
# in connection arguments.
with self.assertRaises(HostRequiredError):
# No host+SigV4 == KABOOM
self.connection_class(
aws_access_key_id='less',
aws_secret_access_key='more'
)

# Ensure passing a ``host`` still works.
# Ensure passing a ``host`` in the connection args still works.
conn = self.connection_class(
aws_access_key_id='less',
aws_secret_access_key='more',
host='s3.cn-north-1.amazonaws.com.cn'
host=host_value
)
self.assertEqual(
conn._required_auth_capability(),
['hmac-v4-s3']
)
self.assertEqual(
conn.host,
host_value
)

# Ensure that the host is populated from our config if one is not
# provided when creating a connection.
self.config = {
's3': {
'host': host_value,
'use-sigv4': True,
}
}
conn = self.connection_class(
aws_access_key_id='less',
aws_secret_access_key='more'
)
self.assertEqual(
conn._required_auth_capability(),
['hmac-v4-s3']
)
self.assertEqual(
conn.host,
's3.cn-north-1.amazonaws.com.cn'
host_value
)


0 comments on commit dcfc751

Please sign in to comment.