boto3-refresh-session 0.0.22__py3-none-any.whl → 0.0.23__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.
- boto3_refresh_session/session.py +25 -7
- {boto3_refresh_session-0.0.22.dist-info → boto3_refresh_session-0.0.23.dist-info}/METADATA +1 -1
- boto3_refresh_session-0.0.23.dist-info/RECORD +6 -0
- boto3_refresh_session-0.0.22.dist-info/RECORD +0 -6
- {boto3_refresh_session-0.0.22.dist-info → boto3_refresh_session-0.0.23.dist-info}/LICENSE +0 -0
- {boto3_refresh_session-0.0.22.dist-info → boto3_refresh_session-0.0.23.dist-info}/WHEEL +0 -0
boto3_refresh_session/session.py
CHANGED
@@ -23,7 +23,10 @@ from typing import Type
|
|
23
23
|
from attrs import define, field
|
24
24
|
from attrs.validators import instance_of, le, optional
|
25
25
|
from boto3 import Session
|
26
|
-
from botocore.credentials import
|
26
|
+
from botocore.credentials import (
|
27
|
+
DeferredRefreshableCredentials,
|
28
|
+
RefreshableCredentials,
|
29
|
+
)
|
27
30
|
from botocore.session import get_session
|
28
31
|
|
29
32
|
|
@@ -43,6 +46,10 @@ class AutoRefreshableSession:
|
|
43
46
|
AWS role ARN.
|
44
47
|
session_name : str
|
45
48
|
Name for session.
|
49
|
+
defer_refresh : bool, optional
|
50
|
+
If ``True`` then temporary credentials are not automatically refreshed until
|
51
|
+
they are explicitly needed. If ``False`` then temporary credentials refresh
|
52
|
+
immediately upon expiration. Default is ``True``.
|
46
53
|
ttl : int, optional
|
47
54
|
Number of seconds until temporary credentials expire, default 900.
|
48
55
|
session_kwargs : dict, optional
|
@@ -61,6 +68,10 @@ class AutoRefreshableSession:
|
|
61
68
|
Check the :ref:`authorization documentation <authorization>` for additional
|
62
69
|
information concerning how to authorize access to AWS.
|
63
70
|
|
71
|
+
The default ``defer_refresh`` parameter value results in temporary credentials not
|
72
|
+
being refreshed until they are explicitly requested; that is more efficient than
|
73
|
+
refreshing expired temporary credentials automatically after they expire.
|
74
|
+
|
64
75
|
Examples
|
65
76
|
--------
|
66
77
|
Here's how to initialize this object:
|
@@ -76,6 +87,7 @@ class AutoRefreshableSession:
|
|
76
87
|
region: str = field(validator=instance_of(str))
|
77
88
|
role_arn: str = field(validator=instance_of(str))
|
78
89
|
session_name: str = field(validator=instance_of(str))
|
90
|
+
defer_refresh: bool = field(default=True, validator=instance_of(bool))
|
79
91
|
ttl: int = field(
|
80
92
|
default=900, validator=optional([instance_of(int), le(900)])
|
81
93
|
)
|
@@ -88,13 +100,19 @@ class AutoRefreshableSession:
|
|
88
100
|
session: Type[Session] = field(init=False)
|
89
101
|
|
90
102
|
def __attrs_post_init__(self):
|
91
|
-
__credentials = RefreshableCredentials.create_from_metadata(
|
92
|
-
metadata=self._get_credentials(),
|
93
|
-
refresh_using=self._get_credentials,
|
94
|
-
method="sts-assume-role",
|
95
|
-
)
|
96
103
|
__session = get_session()
|
97
|
-
|
104
|
+
|
105
|
+
if not self.defer_refresh:
|
106
|
+
__credentials = RefreshableCredentials.create_from_metadata(
|
107
|
+
metadata=self._get_credentials(),
|
108
|
+
refresh_using=self._get_credentials,
|
109
|
+
method="sts-assume-role",
|
110
|
+
)
|
111
|
+
else:
|
112
|
+
__credentials = DeferredRefreshableCredentials(
|
113
|
+
refresh_using=self._get_credentials, method="sts-assume-role"
|
114
|
+
)
|
115
|
+
|
98
116
|
__session._credentials = __credentials
|
99
117
|
self.session = Session(botocore_session=__session)
|
100
118
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
boto3_refresh_session/__init__.py,sha256=OMY8el4qROyEvo0vr1Kv8rtFU7g3xnjHuBss54XRTEA,135
|
2
|
+
boto3_refresh_session/session.py,sha256=W5LAPD_s7oRUDmneqI3rTcB-MRd96RSbIr93QwtVW_s,5235
|
3
|
+
boto3_refresh_session-0.0.23.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
|
4
|
+
boto3_refresh_session-0.0.23.dist-info/METADATA,sha256=NS6-RSO485PN4a-Ok1m5A3etch71w8ClfdGwLpk67ak,3990
|
5
|
+
boto3_refresh_session-0.0.23.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
6
|
+
boto3_refresh_session-0.0.23.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
boto3_refresh_session/__init__.py,sha256=OMY8el4qROyEvo0vr1Kv8rtFU7g3xnjHuBss54XRTEA,135
|
2
|
-
boto3_refresh_session/session.py,sha256=Pyrhgw0rdLbFJ-7Cv1N_58EpUxx4OAoTM6Jn7ser2Zo,4493
|
3
|
-
boto3_refresh_session-0.0.22.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
|
4
|
-
boto3_refresh_session-0.0.22.dist-info/METADATA,sha256=-q_1T-SKGD6DpJB1j7kpG8uOjlHhOn1xpXLAxzFaK_g,3990
|
5
|
-
boto3_refresh_session-0.0.22.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
6
|
-
boto3_refresh_session-0.0.22.dist-info/RECORD,,
|
File without changes
|
File without changes
|