Beispiel #1
0
def test_single_service_region_endpoint(service_name, region_name,
                                        expected_endpoint):
    # Verify the actual values from the partition files.  While
    # TestEndpointHeuristics verified the generic functionality given any
    # endpoints file, this test actually verifies the partition data against a
    # fixed list of known endpoints.  This list doesn't need to be kept 100% up
    # to date, but serves as a basis for regressions as the endpoint data
    # logic evolves.
    resolver = _get_patched_session()._get_internal_component(
        'endpoint_resolver')
    bridge = ClientEndpointBridge(resolver, None, None)
    result = bridge.resolve(service_name, region_name)
    expected = 'https://%s' % expected_endpoint
    assert result['endpoint_url'] == expected
Beispiel #2
0
 async def create_client(self, service_name, region_name, is_secure=True,
                         endpoint_url=None, verify=None,
                         credentials=None, scoped_config=None,
                         api_version=None,
                         client_config=None):
     responses = await self._event_emitter.emit(
         'choose-service-name', service_name=service_name)
     service_name = first_non_none_response(responses, default=service_name)
     service_model = self._load_service_model(service_name, api_version)
     cls = await self._create_client_class(service_name, service_model)
     endpoint_bridge = ClientEndpointBridge(
         self._endpoint_resolver, scoped_config, client_config,
         service_signing_name=service_model.metadata.get('signingName'))
     client_args = self._get_client_args(
         service_model, region_name, is_secure, endpoint_url,
         verify, credentials, scoped_config, client_config, endpoint_bridge)
     service_client = cls(**client_args)
     self._register_retries(service_client)
     self._register_s3_events(
         service_client, endpoint_bridge, endpoint_url, client_config,
         scoped_config)
     self._register_s3_events(
         service_client, endpoint_bridge, endpoint_url, client_config,
         scoped_config)
     self._register_endpoint_discovery(
         service_client, endpoint_url, client_config
     )
     self._register_lazy_block_unknown_fips_pseudo_regions(service_client)
     return service_client
Beispiel #3
0
def get_service_info(endpoint_resolver: EndpointResolver, service_name: str,
                     region: str) -> ServiceInfo:
    service_model_json = create_loader().load_service_model(
        service_name, "service-2")

    service_data = ClientEndpointBridge(endpoint_resolver).resolve(
        service_name=ServiceModel(service_model_json,
                                  service_name=service_name).endpoint_prefix,
        region_name=region,
    )

    return ServiceInfo(
        service_name,
        service_data["metadata"]["hostname"],
        service_data["endpoint_url"],
        service_data["metadata"].get("credentialScope"),
    )
Beispiel #4
0
def _test_single_service_partition_endpoint(service_name, expected_endpoint,
                                            resolver):
    bridge = ClientEndpointBridge(resolver)
    result = bridge.resolve(service_name)
    assert_equals(result['endpoint_url'], expected_endpoint)
Beispiel #5
0
def _test_single_service_region(service_name, region_name,
                                expected_endpoint, resolver):
    bridge = ClientEndpointBridge(resolver, None, None)
    result = bridge.resolve(service_name, region_name)
    expected = 'https://%s' % expected_endpoint
    assert_equals(result['endpoint_url'], expected)
Beispiel #6
0
def test_single_service_partition_endpoint(service_name, expected_endpoint):
    resolver = _get_patched_session()._get_internal_component(
        'endpoint_resolver')
    bridge = ClientEndpointBridge(resolver)
    result = bridge.resolve(service_name)
    assert result['endpoint_url'] == expected_endpoint
Beispiel #7
0
def _test_single_service_partition_endpoint(service_name, expected_endpoint,
                                            resolver):
    bridge = ClientEndpointBridge(resolver)
    result = bridge.resolve(service_name)
    assert_equal(result['endpoint_url'], expected_endpoint)
Beispiel #8
0
def _test_single_service_region(service_name, region_name,
                                expected_endpoint, resolver):
    bridge = ClientEndpointBridge(resolver, None, None)
    result = bridge.resolve(service_name, region_name)
    expected = 'https://%s' % expected_endpoint
    assert_equal(result['endpoint_url'], expected)
Beispiel #9
0
    def _get_client_args(self, service_model, region_name, is_secure,
                         endpoint_url, verify, credentials,
                         scoped_config, client_config):

        # This is a near copy of botocore.client.ClientCreator. What's replaced
        # is Config->AioConfig and EndpointCreator->AioEndpointCreator
        # We don't re-use the parent's implementations due to weak refs

        service_name = service_model.endpoint_prefix
        protocol = service_model.metadata['protocol']
        parameter_validation = True
        if client_config:
            parameter_validation = client_config.parameter_validation
        serializer = botocore.serialize.create_serializer(
            protocol, parameter_validation)

        event_emitter = copy.copy(self._event_emitter)
        response_parser = botocore.parsers.create_parser(protocol)
        endpoint_bridge = ClientEndpointBridge(
            self._endpoint_resolver, scoped_config, client_config,
            service_signing_name=service_model.metadata.get('signingName'))
        endpoint_config = endpoint_bridge.resolve(
            service_name, region_name, endpoint_url, is_secure)

        # Override the user agent if specified in the client config.
        user_agent = self._user_agent
        if client_config is not None:
            if client_config.user_agent is not None:
                user_agent = client_config.user_agent
            if client_config.user_agent_extra is not None:
                user_agent += ' %s' % client_config.user_agent_extra

        signer = RequestSigner(
            service_name, endpoint_config['signing_region'],
            endpoint_config['signing_name'],
            endpoint_config['signature_version'],
            credentials, event_emitter)

        # Create a new client config to be passed to the client based
        # on the final values. We do not want the user to be able
        # to try to modify an existing client with a client config.
        config_kwargs = dict(
            region_name=endpoint_config['region_name'],
            signature_version=endpoint_config['signature_version'],
            user_agent=user_agent)
        if client_config is not None:
            config_kwargs.update(
                connect_timeout=client_config.connect_timeout,
                read_timeout=client_config.read_timeout)

        # Add any additional s3 configuration for client
        self._inject_s3_configuration(
            config_kwargs, scoped_config, client_config)

        if isinstance(client_config, AioConfig):
            connector_args = client_config.connector_args
        else:
            connector_args = None

        new_config = AioConfig(connector_args, **config_kwargs)
        endpoint_creator = AioEndpointCreator(event_emitter, self._loop)
        endpoint = endpoint_creator.create_endpoint(
            service_model, region_name=endpoint_config['region_name'],
            endpoint_url=endpoint_config['endpoint_url'], verify=verify,
            response_parser_factory=self._response_parser_factory,
            timeout=(new_config.connect_timeout, new_config.read_timeout),
            connector_args=new_config.connector_args)

        return {
            'serializer': serializer,
            'endpoint': endpoint,
            'response_parser': response_parser,
            'event_emitter': event_emitter,
            'request_signer': signer,
            'service_model': service_model,
            'loader': self._loader,
            'client_config': new_config
        }