Beispiel #1
0
def test_backwards_compatibility():
    # Tests backwards compatibility with the old endpoint generation tooling.
    # There are snapshots of the two endpoint formats at a single point in
    # time. Given the snapshot of the new endpoint file, this asserts that
    # we can generate the exact data in the snapshot of the old endpoints file.
    # A single 'test' is generated for each service.
    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')
    new_endpoints_file = os.path.join(data_dir, 'new_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(new_endpoints_file) as f:
        new_endpoints = json.load(f)

    resolver = BotoEndpointResolver(new_endpoints)
    builder = StaticEndpointBuilder(resolver)
    services = resolver.get_available_services()
    built = builder.build_static_endpoints(services)

    for service in services:
        old = old_endpoints[service]
        new = built[service]
        case = EndpointTestCase(service, old, new)
        yield case.run
Beispiel #2
0
def test_backwards_compatibility():
    # Tests backwards compatibility with the old endpoint generation tooling.
    # There are snapshots of the two endpoint formats at a single point in
    # time. Given the snapshot of the new endpoint file, this asserts that
    # we can generate the exact data in the snapshot of the old endpoints file.
    # A single 'test' is generated for each service.
    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')
    new_endpoints_file = os.path.join(data_dir, 'new_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(new_endpoints_file) as f:
        new_endpoints = json.load(f)

    resolver = BotoEndpointResolver(new_endpoints)
    builder = StaticEndpointBuilder(resolver)
    services = resolver.get_available_services()
    built = builder.build_static_endpoints(services)

    for service in services:
        old = old_endpoints[service]
        new = built[service]
        case = EndpointTestCase(service, old, new)
        yield case.run
Beispiel #3
0
 def test_resolve_hostname_with_rename(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(endpoint_data=self._endpoint_data(),
                                     service_rename_map=rename_map)
     hostname = resolver.resolve_hostname('ec3', 'us-foo')
     expected_hostname = 'ec2.us-foo.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #4
0
 def test_get_all_regions_with_renames(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(endpoint_data=self._endpoint_data(),
                                     service_rename_map=rename_map)
     regions = sorted(resolver.get_all_available_regions('ec2'))
     expected_regions = sorted(
         ['us-bar', 'eu-baz', 'us-foo', 'foo-1', 'foo-2', 'foo-3'])
     self.assertEqual(regions, expected_regions)
Beispiel #5
0
 def test_get_available_services_with_renames(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(endpoint_data=self._endpoint_data(),
                                     service_rename_map=rename_map)
     services = sorted(resolver.get_available_services())
     expected_services = sorted(
         ['ec3', 's3', 'not-regionalized', 'non-partition', 'merge'])
     self.assertEqual(services, expected_services)
Beispiel #6
0
 def test_resolve_hostname_with_rename(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(
         endpoint_data=self._endpoint_data(),
         service_rename_map=rename_map
     )
     hostname = resolver.resolve_hostname('ec3', 'us-foo')
     expected_hostname = 'ec2.us-foo.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #7
0
 def test_get_available_services_with_renames(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(
         endpoint_data=self._endpoint_data(),
         service_rename_map=rename_map
     )
     services = sorted(resolver.get_available_services())
     expected_services = sorted([
         'ec3', 's3', 'not-regionalized', 'non-partition', 'merge'])
     self.assertEqual(services, expected_services)
Beispiel #8
0
 def test_get_all_regions_with_renames(self):
     rename_map = {'ec3': 'ec2'}
     resolver = BotoEndpointResolver(
         endpoint_data=self._endpoint_data(),
         service_rename_map=rename_map
     )
     regions = sorted(resolver.get_all_available_regions('ec2'))
     expected_regions = sorted([
         'us-bar', 'eu-baz', 'us-foo', 'foo-1', 'foo-2', 'foo-3'])
     self.assertEqual(regions, expected_regions)
Beispiel #9
0
def _get_region_with_heuristics(service_name, region_name, region_cls=None,
                                connection_cls=None):
    """Finds the region using known regions and heuristics."""
    endpoints = load_endpoint_json(boto.ENDPOINTS_PATH)
    resolver = BotoEndpointResolver(endpoints)
    hostname = resolver.resolve_hostname(service_name, region_name)

    return region_cls(
        name=region_name,
        endpoint=hostname,
        connection_cls=connection_cls
    )
Beispiel #10
0
def _get_region_with_heuristics(service_name,
                                region_name,
                                region_cls=None,
                                connection_cls=None):
    """Finds the region using known regions and heuristics."""
    endpoints = load_endpoint_json(boto.ENDPOINTS_PATH)
    resolver = BotoEndpointResolver(endpoints)
    hostname = resolver.resolve_hostname(service_name, region_name)

    return region_cls(name=region_name,
                      endpoint=hostname,
                      connection_cls=connection_cls)
Beispiel #11
0
def _load_builtin_endpoints(_cache=_endpoints_cache):
    """Loads the builtin endpoints in the legacy format."""
    # If there's a cached response, return it
    if _cache:
        return _cache

    # Load the endpoints file
    endpoints = _load_json_file(boto.ENDPOINTS_PATH)

    # Build the endpoints into the legacy format
    resolver = BotoEndpointResolver(endpoints)
    builder = StaticEndpointBuilder(resolver)
    endpoints = builder.build_static_endpoints()

    # Cache the endpoints and then return them
    _cache.update(endpoints)
    return _cache
Beispiel #12
0
def test_no_lost_endpoints():
    # This makes sure that a bad sync doesn't cause us to loose any services

    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(boto.ENDPOINTS_PATH) as f:
        new_endpoints = json.load(f)

    builder = StaticEndpointBuilder(BotoEndpointResolver(new_endpoints))
    built = builder.build_static_endpoints()

    # Assert no services are lost
    for service, service_endpoints in old_endpoints.items():
        new_service_endpoints = built.get(service, {})
        for region, regional_endpoint in service_endpoints.items():
            new_regional_endpoint = new_service_endpoints.get(region)
            case = EndpointPreservedTestCase(service, region,
                                             regional_endpoint,
                                             new_regional_endpoint)
            yield case.run
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--endpoints-file',
        help=('Path to endpoints.json.  If this argument is not given, '
              'then the endpoints.json file bundled with botocore will be '
              'used.'))

    # Since the built in endpoints are no longer in the legacy format,
    # overwrite should not be allowed with legacy format output.
    exclusive = parser.add_mutually_exclusive_group()
    exclusive.add_argument(
        '--overwrite', action='store_true',
        help=('Overwrite the endpoints file built into boto2. This is not '
              'compatible with the legacy format.'))
    exclusive.add_argument(
        '--legacy-format', action='store_true',
        help=('Generate the endpoints in the legacy format, suitable for use '
              'as custom endpoints.'))
    args = parser.parse_args()
    endpoints_data = load_endpoints(args.endpoints_file)
    filter_services(endpoints_data)

    if args.legacy_format:
        builder = StaticEndpointBuilder(BotoEndpointResolver(endpoints_data))
        endpoints_data = builder.build_static_endpoints()

    json_data = json.dumps(
        endpoints_data, indent=2, separators=(',', ': '))

    if args.overwrite:
        with open(EXISTING_ENDPOINTS_FILE, 'w') as f:
            f.write(json_data)
            f.write('\n')
    else:
        print(json_data)
Beispiel #14
0
 def test_resolve_hostname(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('ec2', 'us-foo')
     expected_hostname = 'ec2.us-foo.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #15
0
 def test_get_available_services(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     services = sorted(resolver.get_available_services())
     expected_services = sorted(
         ['ec2', 's3', 'not-regionalized', 'non-partition', 'merge'])
     self.assertEqual(services, expected_services)
Beispiel #16
0
 def test_resolve_hostname_with_ssl_common_name(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('s3', 'us-foo')
     expected_hostname = 'us-foo.s3.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #17
0
 def test_resolve_hostname_with_ssl_common_name(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('s3', 'us-foo')
     expected_hostname = 'us-foo.s3.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #18
0
 def test_resolve_hostname_on_invalid_region_prefix(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('s3', 'fake-west-1')
     self.assertIsNone(hostname)
Beispiel #19
0
 def test_resolve_hostname_on_invalid_region_prefix(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('s3', 'fake-west-1')
     self.assertIsNone(hostname)
Beispiel #20
0
 def test_resolve_hostname(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     hostname = resolver.resolve_hostname('ec2', 'us-foo')
     expected_hostname = 'ec2.us-foo.amazonaws.com'
     self.assertEqual(hostname, expected_hostname)
Beispiel #21
0
 def test_get_available_services(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     services = sorted(resolver.get_available_services())
     expected_services = sorted([
         'ec2', 's3', 'not-regionalized', 'non-partition', 'merge'])
     self.assertEqual(services, expected_services)
Beispiel #22
0
 def test_get_all_regions_on_non_regional_service(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     regions = sorted(
         resolver.get_all_available_regions('not-regionalized'))
     expected_regions = sorted(['us-foo', 'us-bar', 'eu-baz'])
     self.assertEqual(regions, expected_regions)
Beispiel #23
0
 def test_get_all_regions_on_non_regional_service(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     regions = sorted(
         resolver.get_all_available_regions('not-regionalized'))
     expected_regions = sorted(['us-foo', 'us-bar', 'eu-baz'])
     self.assertEqual(regions, expected_regions)
Beispiel #24
0
 def test_get_all_available_regions(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     regions = sorted(resolver.get_all_available_regions('ec2'))
     expected_regions = sorted(
         ['us-bar', 'eu-baz', 'us-foo', 'foo-1', 'foo-2', 'foo-3'])
     self.assertEqual(regions, expected_regions)
Beispiel #25
0
 def test_get_all_available_regions(self):
     resolver = BotoEndpointResolver(self._endpoint_data())
     regions = sorted(resolver.get_all_available_regions('ec2'))
     expected_regions = sorted([
         'us-bar', 'eu-baz', 'us-foo', 'foo-1', 'foo-2', 'foo-3'])
     self.assertEqual(regions, expected_regions)