boto3-refresh-session 0.0.22__py3-none-any.whl → 0.0.23__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 RefreshableCredentials
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
- # https://github.com/boto/botocore/blob/f8a1dd0820b548a5e8dc05420b28b6f1c6e21154/botocore/session.py#L143
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 0.0.22
3
+ Version: 0.0.23
4
4
  Summary: A simple Python package for refreshing boto3 sessions automatically.
5
5
  Home-page: https://github.com/michaelthomasletts/boto3-refresh-session
6
6
  License: MIT
@@ -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,,