Skip to content

Commit

Permalink
Update region override for no region given case
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleknap committed Feb 18, 2015
1 parent 1a25222 commit 68a4c9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
23 changes: 12 additions & 11 deletions botocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,27 +294,28 @@ def create_endpoint(self, service_model, region_name=None, is_secure=True,
raise
# We only support the credentialScope.region in the properties
# bag right now, so if it's available, it will override the
# provided region name if an endpoint url was not manually set.
# If a endpoint url was specified, the user must specify a region.
region_name_override = None
if endpoint_url is None:
region_name_override = endpoint['properties'].get(
'credentialScope', {}).get('region')
# provided region name.
region_name_override = endpoint['properties'].get(
'credentialScope', {}).get('region')
if signature_version is NOT_SET:
signature_version = service_model.signature_version
if 'signatureVersion' in endpoint['properties']:
signature_version = endpoint['properties']['signatureVersion']
if region_name_override is not None:
# Letting the heuristics rule override the region_name
# allows for having a default region of something like us-west-2
# for IAM, but we still will know to use us-east-1 for sigv4.
region_name = region_name_override
if endpoint_url is not None:
# If an endpoint_url is provided, do not use region name override if a region
# was provided by the user.
if region_name is not None:
region_name_override = None
# If the user provides an endpoint url, we'll use that
# instead of what the heuristics rule gives us.
final_endpoint_url = endpoint_url
else:
final_endpoint_url = endpoint['uri']
if region_name_override is not None:
# Letting the heuristics rule override the region_name
# allows for having a default region of something like us-west-2
# for IAM, but we still will know to use us-east-1 for sigv4.
region_name = region_name_override
return self._get_endpoint(service_model, region_name,
signature_version, final_endpoint_url,
verify, response_parser_factory)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,23 @@ def test_endpoint_resolver_no_uses_credential_scope_with_endpoint_url(self):
endpoint = creator.create_endpoint(self.service_model, endpoint_url='https://foo')
self.assertEqual(endpoint.region_name, 'us-west-2')

def test_endpoint_resolver_uses_credential_scope_with_endpoint_url_and_no_region(self):
resolver = Mock()
resolver_region_override = 'us-east-1'
resolver.construct_endpoint.return_value = {
'uri': 'https://endpoint.url',
'properties': {
'credentialScope': {
'region': resolver_region_override,
}
}
}
original_region_name = None
creator = EndpointCreator(resolver, original_region_name,
Mock(), 'user-agent')
endpoint = creator.create_endpoint(self.service_model, endpoint_url='https://foo')
self.assertEqual(endpoint.region_name, resolver_region_override)


class TestAWSSession(unittest.TestCase):
def test_auth_header_preserved_from_s3_redirects(self):
Expand Down

0 comments on commit 68a4c9d

Please sign in to comment.