-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from cbrichford/botocore-updates
Botocore updates
- Loading branch information
Showing
6 changed files
with
120 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import botocore.client | ||
import copy | ||
from botocore.exceptions import ParamValidationError | ||
|
||
|
||
class AioConfig(botocore.client.Config): | ||
|
||
def __init__(self, connector_args=None, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
self._validate_connector_args(connector_args) | ||
self.connector_args = copy.copy(connector_args) | ||
if not self.connector_args: | ||
self.connector_args = dict() | ||
|
||
if 'keepalive_timeout' not in self.connector_args: | ||
# AWS has a 20 second idle timeout: | ||
# https://forums.aws.amazon.com/message.jspa?messageID=215367 | ||
# and aiohttp default timeout is 30s so we set it to something | ||
# reasonable here | ||
self.connector_args['keepalive_timeout'] = 12 | ||
|
||
def merge(self, other_config): | ||
# Adapted from parent class | ||
config_options = copy.copy(self._user_provided_options) | ||
config_options.update(other_config._user_provided_options) | ||
return AioConfig(self.connector_args, **config_options) | ||
|
||
@staticmethod | ||
def _validate_connector_args(connector_args): | ||
if connector_args is None: | ||
return | ||
|
||
for k, v in connector_args.items(): | ||
if k in ['use_dns_cache', 'verify_ssl']: | ||
if not isinstance(v, bool): | ||
raise ParamValidationError( | ||
report='{} value must be a boolean'.format(k)) | ||
elif k in ['conn_timeout', 'keepalive_timeout']: | ||
if not isinstance(v, float) and not isinstance(v, int): | ||
raise ParamValidationError( | ||
report='{} value must be a float/int'.format(k)) | ||
elif k == 'force_close': | ||
if not isinstance(v, bool): | ||
raise ParamValidationError( | ||
report='{} value must be a boolean'.format(k)) | ||
elif k == 'limit': | ||
if not isinstance(v, int): | ||
raise ParamValidationError( | ||
report='{} value must be an int'.format(k)) | ||
elif k == 'ssl_context': | ||
import ssl | ||
if not isinstance(v, ssl.SSLContext): | ||
raise ParamValidationError( | ||
report='{} must be an SSLContext instance'.format(k)) | ||
else: | ||
raise ParamValidationError( | ||
report='invalid connector_arg:{}'.format(k)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters