def __init__( self, verify: bool = True, proxies: Dict[str, str] = None, # {scheme: url} timeout: float = None, max_pool_connections: int = MAX_POOL_CONNECTIONS, socket_options=None, client_cert=None, proxies_config=None, connector_args=None ): # TODO: handle socket_options self._verify = verify self._proxy_config = ProxyConfiguration(proxies=proxies, proxies_settings=proxies_config) if isinstance(timeout, (list, tuple)): conn_timeout, read_timeout = timeout else: conn_timeout = read_timeout = timeout timeout = aiohttp.ClientTimeout( sock_connect=conn_timeout, sock_read=read_timeout ) self._cert_file = None self._key_file = None if isinstance(client_cert, str): self._cert_file = client_cert elif isinstance(client_cert, tuple): self._cert_file, self._key_file = client_cert self._timeout = timeout self._connector_args = connector_args if self._connector_args is None: # AWS has a 20 second idle timeout: # https://forums.aws.amazon.com/message.jspa?messageID=215367 # aiohttp default timeout is 30s so set something reasonable here self._connector_args = dict(keepalive_timeout=12) self._max_pool_connections = max_pool_connections self._socket_options = socket_options if socket_options is None: self._socket_options = [] # aiohttp handles 100 continue so we shouldn't need AWSHTTP[S]ConnectionPool # it also pools by host so we don't need a manager, and can pass proxy via # request so don't need proxy manager if proxies: proxies_settings = self._proxy_config.settings ssl_context = self._setup_proxy_ssl_context(proxies_settings) # TODO: add support for # proxies_settings.get('proxy_use_forwarding_for_https') else: ssl_context = self._get_ssl_context() # inline self._setup_ssl_cert if bool(verify): ca_certs = get_cert_path(verify) if ca_certs: ssl_context.load_verify_locations(ca_certs, None, None) self._connector = aiohttp.TCPConnector( limit=max_pool_connections, verify_ssl=bool(verify), ssl=ssl_context, **connector_args) self._session: Optional[aiohttp.ClientSession] = None
def test_get_cert_path_certifi_or_default(self): with patch('botocore.httpsession.where') as where: path = '/bundle/path' where.return_value = path cert_path = get_cert_path(True) self.assertEqual(path, cert_path)
def test_get_cert_path_path(self): path = '/some/path' cert_path = get_cert_path(path) self.assertEqual(path, cert_path)