boto3-refresh-session 3.0.3__tar.gz → 4.0.0__tar.gz
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.
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/PKG-INFO +10 -26
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/README.md +8 -24
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/__init__.py +1 -2
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/__init__.py +1 -3
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/session.py +1 -2
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/typing.py +0 -2
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/pyproject.toml +2 -2
- boto3_refresh_session-3.0.3/boto3_refresh_session/methods/ecs.py +0 -115
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/LICENSE +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/NOTICE +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/exceptions.py +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/custom.py +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/iot/__init__.typed +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/iot/certificate.typed +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/iot/cognito.typed +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/iot/core.typed +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/sts.py +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/__init__.py +0 -0
- {boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/internal.py +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: boto3-refresh-session
|
3
|
-
Version:
|
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,
|
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
|
124
|
-
|
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)
|
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
|
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
|
|
@@ -95,13 +95,11 @@
|
|
95
95
|
## 😛 Features
|
96
96
|
|
97
97
|
- Drop-in replacement for `boto3.session.Session`
|
98
|
-
- Supports automatic credential refresh methods for
|
99
|
-
|
100
|
-
- ECS
|
101
|
-
- Supports custom authentication methods for complicated authentication flows
|
98
|
+
- Supports automatic credential refresh methods for STS
|
99
|
+
- Supports custom authentication methods with automatic refresh for complicated authentication flows
|
102
100
|
- Natively supports all parameters supported by `boto3.session.Session`
|
103
101
|
- [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/)
|
104
|
-
- Future releases will include support for IoT (coming soon)
|
102
|
+
- Future releases will include support for IoT (coming soon)
|
105
103
|
|
106
104
|
## ⚠️ Important Updates
|
107
105
|
|
@@ -113,6 +111,10 @@ Advanced users, however, particularly those using low-level objects such as `Bas
|
|
113
111
|
|
114
112
|
Please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/75) for additional details.
|
115
113
|
|
114
|
+
#### ✂️ v4.0.0
|
115
|
+
|
116
|
+
The `ecs` module has been dropped. For additional details and rationale, please review [this PR](https://github.com/michaelthomasletts/boto3-refresh-session/pull/78).
|
117
|
+
|
116
118
|
#### ☎️ Delayed Responses
|
117
119
|
|
118
120
|
I am currently grappling with a very serious medical condition. Accordingly, expect delayed responses to issues and requests until my health stabilizes.
|
@@ -146,7 +148,7 @@ pip install boto3-refresh-session
|
|
146
148
|
|
147
149
|
To use the `boto3.client` or `boto3.resource` interface, but with the benefits of `boto3-refresh-session`, you have a few options!
|
148
150
|
|
149
|
-
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
|
151
|
+
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!
|
150
152
|
|
151
153
|
##### `RefreshableSession.client` (Recommended)
|
152
154
|
|
@@ -244,24 +246,6 @@ pip install boto3-refresh-session
|
|
244
246
|
|
245
247
|
</details>
|
246
248
|
|
247
|
-
<details>
|
248
|
-
<summary><strong>ECS (click to expand)</strong></summary>
|
249
|
-
|
250
|
-
### ECS
|
251
|
-
|
252
|
-
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).
|
253
|
-
|
254
|
-
```python
|
255
|
-
session = RefreshableSession(
|
256
|
-
method="ecs",
|
257
|
-
region_name=region_name,
|
258
|
-
profile_name=profile_name,
|
259
|
-
...
|
260
|
-
)
|
261
|
-
```
|
262
|
-
|
263
|
-
</details>
|
264
|
-
|
265
249
|
<details>
|
266
250
|
<summary><strong>Custom Authentication Flows (click to expand)</strong></summary>
|
267
251
|
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/__init__.py
RENAMED
@@ -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__ = "
|
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,
|
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__)
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/session.py
RENAMED
@@ -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', '
|
62
|
+
e.g. 'sts', 'custom'.
|
64
63
|
"""
|
65
64
|
|
66
65
|
args = list(get_args(Method))
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/typing.py
RENAMED
@@ -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,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "boto3-refresh-session"
|
3
|
-
version = "
|
3
|
+
version = "4.0.0"
|
4
4
|
description = "A simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically."
|
5
5
|
authors = [
|
6
6
|
{name = "Mike Letts",email = "lettsmt@gmail.com"}
|
@@ -9,7 +9,7 @@ license = {text = "MIT"}
|
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.10"
|
11
11
|
dependencies = ["boto3", "botocore", "requests", "typing-extensions"]
|
12
|
-
keywords = ["boto3", "botocore", "aws", "sts", "
|
12
|
+
keywords = ["boto3", "botocore", "aws", "sts", "credentials", "token", "refresh"]
|
13
13
|
maintainers = [
|
14
14
|
{name="Michael Letts", email="lettsmt@gmail.com"},
|
15
15
|
]
|
@@ -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"}
|
File without changes
|
File without changes
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/exceptions.py
RENAMED
File without changes
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/custom.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/methods/sts.py
RENAMED
File without changes
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/__init__.py
RENAMED
File without changes
|
{boto3_refresh_session-3.0.3 → boto3_refresh_session-4.0.0}/boto3_refresh_session/utils/internal.py
RENAMED
File without changes
|