|
5 | 5 | .. versionadded:: 1.5.0
|
6 | 6 |
|
7 | 7 | """
|
| 8 | +import functools |
8 | 9 | import logging
|
9 | 10 |
|
10 | 11 | import attr
|
11 | 12 | import six
|
12 | 13 | from attr.validators import deep_iterable, instance_of, is_callable, optional
|
13 | 14 | from botocore.client import BaseClient
|
| 15 | +from botocore.config import Config as BotocoreConfig |
| 16 | +from botocore.session import Session as BotocoreSession |
14 | 17 |
|
15 | 18 | from aws_encryption_sdk.exceptions import UnknownRegionError
|
| 19 | +from aws_encryption_sdk.identifiers import USER_AGENT_SUFFIX |
16 | 20 | from aws_encryption_sdk.internal.validators import value_is_not_a_string
|
17 | 21 |
|
18 | 22 | from .client_cache import ClientCache
|
@@ -58,11 +62,36 @@ class DefaultClientSupplier(ClientSupplier):
|
58 | 62 |
|
59 | 63 | .. versionadded:: 1.5.0
|
60 | 64 |
|
61 |
| - :param botocore_session: botocore session to use when creating clients (optional) |
| 65 | + If you want clients to have special credentials or other configuration, |
| 66 | + you can provide those with custom ``botocore`` Session and/or `Config`_ instances. |
| 67 | +
|
| 68 | + .. _Config: https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html |
| 69 | +
|
| 70 | + .. code-block:: python |
| 71 | +
|
| 72 | + from aws_encryption_sdk.keyrings.aws_kms.client_supplier import DefaultClientSupplier |
| 73 | + from botocore.session import Session |
| 74 | + from botocore.config import Config |
| 75 | +
|
| 76 | + my_client_supplier = DefaultClientSupplier( |
| 77 | + botocore_session=Session(**_get_custom_credentials()), |
| 78 | + client_config=Config(connect_timeout=10), |
| 79 | + ) |
| 80 | +
|
| 81 | + :param botocore_session: Botocore session to use when creating clients (optional) |
62 | 82 | :type botocore_session: botocore.session.Session
|
| 83 | + :param client_config: Config to use when creating client (optional) |
| 84 | + :type client_config: botocore.config.Config |
63 | 85 | """
|
64 | 86 |
|
65 |
| - _client_cache = attr.ib(default=attr.Factory(ClientCache), validator=instance_of(ClientCache)) |
| 87 | + _botocore_session = attr.ib(default=attr.Factory(BotocoreSession), validator=instance_of(BotocoreSession)) |
| 88 | + _client_config = attr.ib( |
| 89 | + default=attr.Factory(functools.partial(BotocoreConfig, user_agent_extra=USER_AGENT_SUFFIX)), |
| 90 | + validator=instance_of(BotocoreConfig), |
| 91 | + ) |
| 92 | + |
| 93 | + def __attrs_post_init__(self): |
| 94 | + self._client_cache = ClientCache(botocore_session=self._botocore_session, client_config=self._client_config) |
66 | 95 |
|
67 | 96 | def __call__(self, region_name):
|
68 | 97 | # type: (Union[None, str]) -> BaseClient
|
|
0 commit comments