boto3-refresh-session 3.0.3__py3-none-any.whl → 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,12 @@ __all__ = []
3
3
  from . import exceptions, session
4
4
  from .exceptions import *
5
5
  from .methods.custom import *
6
- from .methods.ecs import *
7
6
  from .methods.sts import *
8
7
  from .session import *
9
8
 
10
9
  __all__.extend(session.__all__)
11
10
  __all__.extend(exceptions.__all__)
12
- __version__ = "3.0.3"
11
+ __version__ = "4.0.0"
13
12
  __title__ = "boto3-refresh-session"
14
13
  __author__ = "Mike Letts"
15
14
  __maintainer__ = "Mike Letts"
@@ -1,12 +1,10 @@
1
1
  __all__ = []
2
2
 
3
3
  # TODO: import iot submodules when finished
4
- from . import custom, ecs, sts
4
+ from . import custom, sts
5
5
  from .custom import CustomRefreshableSession
6
- from .ecs import ECSRefreshableSession
7
6
  from .sts import STSRefreshableSession
8
7
 
9
8
  # TODO: add iot submodules to __all__ when finished
10
9
  __all__.extend(custom.__all__)
11
- __all__.extend(ecs.__all__)
12
10
  __all__.extend(sts.__all__)
@@ -37,7 +37,6 @@ class RefreshableSession:
37
37
  --------
38
38
  boto3_refresh_session.methods.custom.CustomRefreshableSession
39
39
  boto3_refresh_session.methods.sts.STSRefreshableSession
40
- boto3_refresh_session.methods.ecs.ECSRefreshableSession
41
40
  """
42
41
 
43
42
  def __new__(
@@ -60,7 +59,7 @@ class RefreshableSession:
60
59
  -------
61
60
  list[str]
62
61
  A list of all currently available credential refresh methods,
63
- e.g. 'sts', 'ecs', 'custom'.
62
+ e.g. 'sts', 'custom'.
64
63
  """
65
64
 
66
65
  args = list(get_args(Method))
@@ -38,7 +38,6 @@ IoTAuthenticationMethod = Literal["certificate", "cognito", "__iot_sentinel__"]
38
38
  #: Type alias for all currently available credential refresh methods.
39
39
  Method = Literal[
40
40
  "sts",
41
- "ecs",
42
41
  "custom",
43
42
  "__sentinel__",
44
43
  ] # TODO: Add iot when implemented
@@ -46,7 +45,6 @@ Method = Literal[
46
45
  #: Type alias for all refresh method names.
47
46
  RefreshMethod = Literal[
48
47
  "sts-assume-role",
49
- "ecs-container-metadata",
50
48
  "custom",
51
49
  ] # TODO: Add iot-certificate and iot-cognito when iot implemented
52
50
 
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 3.0.3
3
+ Version: 4.0.0
4
4
  Summary: A simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically.
5
5
  License: MIT
6
- Keywords: boto3,botocore,aws,sts,ecs,credentials,token,refresh
6
+ Keywords: boto3,botocore,aws,sts,credentials,token,refresh
7
7
  Author: Mike Letts
8
8
  Author-email: lettsmt@gmail.com
9
9
  Maintainer: Michael Letts
@@ -120,13 +120,11 @@ Description-Content-Type: text/markdown
120
120
  ## 😛 Features
121
121
 
122
122
  - Drop-in replacement for `boto3.session.Session`
123
- - Supports automatic credential refresh methods for various AWS services:
124
- - STS
125
- - ECS
126
- - Supports custom authentication methods for complicated authentication flows
123
+ - Supports automatic credential refresh methods for STS
124
+ - Supports custom authentication methods with automatic refresh for complicated authentication flows
127
125
  - Natively supports all parameters supported by `boto3.session.Session`
128
126
  - [Tested](https://github.com/michaelthomasletts/boto3-refresh-session/tree/main/tests), [documented](https://michaelthomasletts.github.io/boto3-refresh-session/index.html), and [published to PyPI](https://pypi.org/project/boto3-refresh-session/)
129
- - Future releases will include support for IoT (coming soon), EC2, and SSO
127
+ - Future releases will include support for IoT (coming soon)
130
128
 
131
129
  ## ⚠️ Important Updates
132
130
 
@@ -138,6 +136,10 @@ Advanced users, however, particularly those using low-level objects such as `Bas
138
136
 
139
137
  Please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/75) for additional details.
140
138
 
139
+ #### ✂️ v4.0.0
140
+
141
+ The `ecs` module has been dropped. For additional details and rationale, please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/78).
142
+
141
143
  #### ☎️ Delayed Responses
142
144
 
143
145
  I am currently grappling with a very serious medical condition. Accordingly, expect delayed responses to issues and requests until my health stabilizes.
@@ -171,7 +173,7 @@ pip install boto3-refresh-session
171
173
 
172
174
  To use the `boto3.client` or `boto3.resource` interface, but with the benefits of `boto3-refresh-session`, you have a few options!
173
175
 
174
- In the following examples, let's assume you want to use STS for retrieving temporary credentials for the sake of simplicity. Let's also focus specifically on `client`. Switching to `resource` follows the same exact idioms as below, except that `client` must be switched to `resource` in the pseudo-code, obviously. If you are not sure how to use `RefreshableSession` for STS (or ECS or custom auth flows) then check the usage instructions in the following sections!
176
+ In the following examples, let's assume you want to use STS for retrieving temporary credentials for the sake of simplicity. Let's also focus specifically on `client`. Switching to `resource` follows the same exact idioms as below, except that `client` must be switched to `resource` in the pseudo-code, obviously. If you are not sure how to use `RefreshableSession` for STS (or custom auth flows) then check the usage instructions in the following sections!
175
177
 
176
178
  ##### `RefreshableSession.client` (Recommended)
177
179
 
@@ -269,24 +271,6 @@ pip install boto3-refresh-session
269
271
 
270
272
  </details>
271
273
 
272
- <details>
273
- <summary><strong>ECS (click to expand)</strong></summary>
274
-
275
- ### ECS
276
-
277
- You can use boto3-refresh-session in an ECS container to automatically refresh temporary security credentials. For additional information on the exact parameters that `RefreshableSession` takes for ECS, [check this documentation](https://github.com/michaelthomasletts/boto3-refresh-session/blob/main/boto3_refresh_session/methods/ecs.py).
278
-
279
- ```python
280
- session = RefreshableSession(
281
- method="ecs",
282
- region_name=region_name,
283
- profile_name=profile_name,
284
- ...
285
- )
286
- ```
287
-
288
- </details>
289
-
290
274
  <details>
291
275
  <summary><strong>Custom Authentication Flows (click to expand)</strong></summary>
292
276
 
@@ -1,19 +1,18 @@
1
- boto3_refresh_session/__init__.py,sha256=L-9FGJIUsvwRFNlfJeKb_61NvZpT07xGdBAyV38DMhI,415
1
+ boto3_refresh_session/__init__.py,sha256=8Mws6gI3cPLZ1ODvQA2WhU-Clq9v5k7MvYMdM3mr5l8,388
2
2
  boto3_refresh_session/exceptions.py,sha256=DumBh6cDVU46eelSNt1CsG2uMSBekSbmhqWEaAWw130,1003
3
- boto3_refresh_session/methods/__init__.py,sha256=zpVBJIR4P-l4pjE9kMnLGffehPVawY1vLiX2CPcpV7w,352
3
+ boto3_refresh_session/methods/__init__.py,sha256=Npth3cOf8waY0XOS0xIvbG28pOIU8rs7_hi5NhJ9HwU,280
4
4
  boto3_refresh_session/methods/custom.py,sha256=j90Iv1DKdGgP1JNwQfpEhaJDBrB2AtDe8kqI2Mktwlg,4173
5
- boto3_refresh_session/methods/ecs.py,sha256=dxDrNOu8xTFHciuwL7jLh5nB2QXWwQRRA1CoY7AuO5g,3893
6
5
  boto3_refresh_session/methods/iot/__init__.typed,sha256=Z33nIB6oCsz9TZwikHfNHgY1SKxkSCdB5rwdPSUl3C4,135
7
6
  boto3_refresh_session/methods/iot/certificate.typed,sha256=sFTa1rF7tebr48Bjw_YtVeOdVvazAHBJGGiM33tsFXI,1828
8
7
  boto3_refresh_session/methods/iot/cognito.typed,sha256=wyBMWUkuhLt27JsKZIwtfylDdCavNexcEy16ZaDFjUY,435
9
8
  boto3_refresh_session/methods/iot/core.typed,sha256=Q5WshxgIIOgAaqoU7n8wBKMe9eSzZ6H8db-q1gThHzk,1407
10
9
  boto3_refresh_session/methods/sts.py,sha256=dzf68BE0f1nFsITOKOnygh-mTvBqThKkrW2eEc-wFKA,3326
11
- boto3_refresh_session/session.py,sha256=8YAdanwnJUG622Cv9MNKg25uj9ZmMYzRL4xiqH1i0nk,2089
10
+ boto3_refresh_session/session.py,sha256=aJaOJK1yBFWkSc2qZzrQuDcMYto73S_iyabCF5vJZls,2022
12
11
  boto3_refresh_session/utils/__init__.py,sha256=6F2ErbgBT2ZmZwFF3OzvQEd1Vh4XM3kaL6YGMTrcrkQ,156
13
12
  boto3_refresh_session/utils/internal.py,sha256=bpKTAF_xdBw1wJPHIG8aGRMiXkSkp7CI9et0U5o3qEI,6103
14
- boto3_refresh_session/utils/typing.py,sha256=I4VJS1vkRwIRdJF08dZF1YgUed_anviz3hq4hLvPnLw,3537
15
- boto3_refresh_session-3.0.3.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
16
- boto3_refresh_session-3.0.3.dist-info/METADATA,sha256=91keQVV9MNrd7zoC8s5c4e59qzrU7vMB9plvJ1d4Sr8,12561
17
- boto3_refresh_session-3.0.3.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
18
- boto3_refresh_session-3.0.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
- boto3_refresh_session-3.0.3.dist-info/RECORD,,
13
+ boto3_refresh_session/utils/typing.py,sha256=KXE-BFb303pVdIj5MUp66aJSRRDjDV3mfuPcSA_QE4g,3496
14
+ boto3_refresh_session-4.0.0.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
15
+ boto3_refresh_session-4.0.0.dist-info/METADATA,sha256=cH0FKUnHTxXNxzhuDpZFGXBxujnoYY0-FPuYsEqJqJM,12133
16
+ boto3_refresh_session-4.0.0.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
17
+ boto3_refresh_session-4.0.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
18
+ boto3_refresh_session-4.0.0.dist-info/RECORD,,
@@ -1,115 +0,0 @@
1
- __all__ = ["ECSRefreshableSession"]
2
-
3
- import os
4
-
5
- import requests
6
-
7
- from ..exceptions import BRSError, BRSWarning
8
- from ..utils import (
9
- BaseRefreshableSession,
10
- Identity,
11
- TemporaryCredentials,
12
- refreshable_session,
13
- )
14
-
15
- _ECS_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
16
- _ECS_CREDENTIALS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI"
17
- _ECS_AUTHORIZATION_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN"
18
- _DEFAULT_ENDPOINT_BASE = "http://169.254.170.2"
19
-
20
-
21
- @refreshable_session
22
- class ECSRefreshableSession(BaseRefreshableSession, registry_key="ecs"):
23
- """A boto3 session that automatically refreshes temporary AWS credentials
24
- from the ECS container credentials metadata endpoint.
25
-
26
- Parameters
27
- ----------
28
- defer_refresh : bool, optional
29
- If ``True`` then temporary credentials are not automatically
30
- refreshed until they are explicitly needed. If ``False`` then
31
- temporary credentials refresh immediately upon expiration. It
32
- is highly recommended that you use ``True``. Default is ``True``.
33
-
34
- Other Parameters
35
- ----------------
36
- kwargs : dict
37
- Optional keyword arguments passed to :class:`boto3.session.Session`.
38
- """
39
-
40
- def __init__(self, **kwargs):
41
- if "refresh_method" in kwargs:
42
- BRSWarning(
43
- "'refresh_method' cannot be set manually. "
44
- "Reverting to 'ecs-container-metadata'."
45
- )
46
- del kwargs["refresh_method"]
47
-
48
- # initializing BRSSession
49
- super().__init__(refresh_method="ecs-container-metadata", **kwargs)
50
-
51
- # initializing various other attributes
52
- self._endpoint = self._resolve_endpoint()
53
- self._headers = self._build_headers()
54
- self._http = self._init_http_session()
55
-
56
- def _resolve_endpoint(self) -> str:
57
- uri = os.environ.get(_ECS_CREDENTIALS_FULL_URI) or os.environ.get(
58
- _ECS_CREDENTIALS_RELATIVE_URI
59
- )
60
- if not uri:
61
- raise BRSError(
62
- "Neither AWS_CONTAINER_CREDENTIALS_FULL_URI nor "
63
- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set. "
64
- "Are you running inside an ECS container?"
65
- )
66
- if uri.startswith("http://") or uri.startswith("https://"):
67
- return uri
68
- return f"{_DEFAULT_ENDPOINT_BASE}{uri}"
69
-
70
- def _build_headers(self) -> dict[str, str]:
71
- token = os.environ.get(_ECS_AUTHORIZATION_TOKEN)
72
- if token:
73
- return {"Authorization": f"Bearer {token}"}
74
- return {}
75
-
76
- def _init_http_session(self) -> requests.Session:
77
- session = requests.Session()
78
- session.headers.update(self._headers)
79
- return session
80
-
81
- def _get_credentials(self) -> TemporaryCredentials:
82
- try:
83
- response = self._http.get(self._endpoint, timeout=3)
84
- response.raise_for_status()
85
- except requests.RequestException as exc:
86
- raise BRSError(
87
- f"Failed to retrieve ECS credentials from {self._endpoint}"
88
- ) from exc
89
-
90
- credentials = response.json()
91
- required = {
92
- "AccessKeyId",
93
- "SecretAccessKey",
94
- "SessionToken",
95
- "Expiration",
96
- }
97
- if not required.issubset(credentials):
98
- raise BRSError(f"Incomplete credentials received: {credentials}")
99
- return {
100
- "access_key": credentials.get("AccessKeyId"),
101
- "secret_key": credentials.get("SecretAccessKey"),
102
- "token": credentials.get("SessionToken"),
103
- "expiry_time": credentials.get("Expiration"), # already ISO8601
104
- }
105
-
106
- def get_identity(self) -> Identity:
107
- """Returns metadata about ECS.
108
-
109
- Returns
110
- -------
111
- Identity
112
- Dict containing metadata about ECS.
113
- """
114
-
115
- return {"method": "ecs", "source": "ecs-container-metadata"}