예제 #1
0
 def test_construct_dualstack_endpoint_no_variant_raise_exception(self):
     with self.assertRaises(EndpointVariantError):
         resolver = regions.EndpointResolver(self._template())
         resolver.construct_endpoint('ec2',
                                     'foo-1',
                                     'foo',
                                     use_dualstack_endpoint=True)
예제 #2
0
 def test_gets_endpoint_names(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.get_available_endpoints('ec2',
                                               allow_non_regional=True)
     self.assertEqual(
         ['d', 'eu-baz', 'us-bar', 'us-dep', 'us-fizz', 'us-foo'],
         sorted(result))
 def test_constructs_regionalized_endpoints_for_exact_matches(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('not-regionalized', 'eu-baz')
     self.assertEqual('not-regionalized.eu-baz.amazonaws.com',
                      result['hostname'])
     self.assertEqual('aws', result['partition'])
     self.assertEqual('eu-baz', result['endpointName'])
예제 #4
0
 def test_construct_fips_endpoint_from_service_default_variant(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('ec2',
                                          'us-bar',
                                          use_fips_endpoint=True)
     self.assertEqual(result['hostname'], 'ec2-fips.us-bar.amazonaws.com')
     self.assertEqual(result['dnsSuffix'], 'amazonaws.com')
예제 #5
0
 def test_construct_dualstack_endpoint_from_partition_default_variant(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('dynamodb',
                                          'us-bar',
                                          use_dualstack_endpoint=True)
     self.assertEqual(result['hostname'], 'dynamodb.us-bar.api.aws')
     self.assertEqual(result['dnsSuffix'], 'api.aws')
예제 #6
0
 def test_construct_dualstack_from_endpoint_variant(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('ec2',
                                          'us-foo',
                                          use_dualstack_endpoint=True)
     self.assertEqual(result['hostname'], 'ec2.foo.api.aws')
     self.assertEqual(result['dnsSuffix'], 'api.aws')
 def test_merges_service_keys(self):
     resolver = regions.EndpointResolver(self._template())
     us_foo = resolver.construct_endpoint('merge', 'us-foo')
     us_bar = resolver.construct_endpoint('merge', 'us-bar')
     self.assertEqual(['http'], us_foo['protocols'])
     self.assertEqual(['v4'], us_foo['signatureVersions'])
     self.assertEqual(['https'], us_bar['protocols'])
     self.assertEqual(['v2'], us_bar['signatureVersions'])
예제 #8
0
 def _get_endpoint_url(service, region):
     data = boto_loader.create_loader().load_data("endpoints")
     endpoint_data = boto_regions.EndpointResolver(data).construct_endpoint(
         service, region)
     if not endpoint_data:
         raise TaskCatException(
             f"unable to resolve endpoint for {service} in {region}")
     return f"https://{service}.{region}.{endpoint_data['dnsSuffix']}"
예제 #9
0
 def test_constructs_dualstack_and_fips_endpoint_no_hostname_in_variant(
         self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('s3',
                                          'us-fizz',
                                          use_dualstack_endpoint=True,
                                          use_fips_endpoint=True)
     self.assertEqual('s3-fips.dualstack.us-fizz.api.aws',
                      result['hostname'])
예제 #10
0
 def test_construct_deprecated_endpoint_raises_warning(self):
     resolver = regions.EndpointResolver(self._template())
     with self.assertLogs('botocore.regions', level='WARNING') as log:
         result = resolver.construct_endpoint(
             'ec2',
             'us-dep',
             use_fips_endpoint=True,
         )
         self.assertIn('deprecated endpoint', log.output[0])
         self.assertEqual(result['hostname'],
                          'ec2-fips.us-dep.amazonaws.com')
         self.assertEqual(result['dnsSuffix'], 'amazonaws.com')
예제 #11
0
def _verify_expected_endpoint(service, region, fips, dualstack, endpoint):
    resolver = regions.EndpointResolver(_modeled_variants_template())
    resolved = resolver.construct_endpoint(service,
                                           region,
                                           use_dualstack_endpoint=dualstack,
                                           use_fips_endpoint=fips)
    # If we can't resolve the region, we attempt to get a
    # global endpoint.
    if not resolved:
        resolved = resolver.construct_endpoint(
            service,
            region,
            partition_name='aws',
            use_dualstack_endpoint=dualstack,
            use_fips_endpoint=fips)
    assert resolved['hostname'] == endpoint
 def test_constructs_partition_endpoints_for_real_partition_region(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('not-regionalized', 'us-bar')
     self.assertEqual('not-regionalized', result['hostname'])
     self.assertEqual('aws', result['partition'])
     self.assertEqual('aws', result['endpointName'])
 def test_constructs_partition_endpoints_for_regex_match(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('not-regionalized', 'us-abc')
     self.assertEqual('not-regionalized', result['hostname'])
 def test_returns_none_when_no_match(self):
     resolver = regions.EndpointResolver(self._template())
     self.assertIsNone(resolver.construct_endpoint('foo', 'baz'))
예제 #15
0
 def test_get_available_fips_and_dualstack_endpoints_none(self):
     resolver = regions.EndpointResolver(self._template())
     fips_and_dualstack_endpoints = resolver.get_available_endpoints(
         'ec2', 'foo', endpoint_variant_tags=['fips', 'dualstack'])
     self.assertEqual(fips_and_dualstack_endpoints, [])
 def test_gets_endpoint_names_for_partition(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.get_available_endpoints('ec2',
                                               allow_non_regional=True,
                                               partition_name='foo')
     self.assertEqual(['foo-1', 'foo-2', 'foo-3'], sorted(result))
 def test_list_regional_endpoints_only(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.get_available_endpoints('ec2',
                                               allow_non_regional=False)
     self.assertEqual(['eu-baz', 'us-bar', 'us-foo'], sorted(result))
예제 #18
0
 def test_constructs_fips_endpoint_no_hostname_in_variant(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('s3',
                                          'us-fizz',
                                          use_fips_endpoint=True)
     self.assertEqual('s3-fips.us-fizz.amazonaws.com', result['hostname'])
 def test_returns_dns_suffix_if_available(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('not-regionalized')
     self.assertEqual(result['dnsSuffix'], 'amazonaws.com')
 def test_gives_hostname_and_common_name_unaltered(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('s3', 'eu-baz')
     self.assertEqual('s3.eu-baz.amazonaws.com', result['sslCommonName'])
     self.assertEqual('foo', result['hostname'])
예제 #21
0
 def create_endpoint_resolver(self, rules):
     return regions.EndpointResolver(rules)
 def test_constructs_endpoints_for_regionalized_regex_match(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('s3', 'us-abc')
     self.assertEqual('s3.us-abc.amazonaws.com', result['hostname'])
 def test_constructs_endpoints_for_unknown_service_but_known_region(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('unknown', 'us-foo')
     self.assertEqual('unknown.us-foo.amazonaws.com', result['hostname'])
 def test_ensures_region_is_not_none(self):
     with self.assertRaises(NoRegionError):
         resolver = regions.EndpointResolver(self._template())
         resolver.construct_endpoint('foo', None)
 def test_merges_partition_default_keys_with_overwrite(self):
     resolver = regions.EndpointResolver(self._template())
     resolved = resolver.construct_endpoint('ec2', 'foo-2')
     self.assertEqual('bar', resolved['foo'])
     self.assertEqual(['http'], resolved['protocols'])
 def test_ensures_required_keys_present(self):
     with self.assertRaises(ValueError):
         regions.EndpointResolver({})
 def tests_uses_partition_endpoint_when_no_region_provided(self):
     resolver = regions.EndpointResolver(self._template())
     result = resolver.construct_endpoint('not-regionalized')
     self.assertEqual('not-regionalized', result['hostname'])
     self.assertEqual('aws', result['endpointName'])
 def test_returns_empty_list_when_listing_for_different_partition(self):
     resolver = regions.EndpointResolver(self._template())
     self.assertEqual([], resolver.get_available_endpoints('ec2', 'bar'))
예제 #29
0
 def _register_endpoint_resolver(self):
     self._components.lazy_register_component(
         'endpoint_resolver',
         lambda: regions.EndpointResolver(self.get_data('_endpoints')))
 def test_returns_empty_list_when_no_service_found(self):
     resolver = regions.EndpointResolver(self._template())
     self.assertEqual([], resolver.get_available_endpoints('what?'))