boto3-refresh-session 0.0.21__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,11 +68,15 @@ 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:
67
78
 
68
- >>> sess = AutoRefreshableSession(
79
+ >>> sess = brs.AutoRefreshableSession(
69
80
  >>> region="us-east-1",
70
81
  >>> role_arn="<your-arn>",
71
82
  >>> session_name="test",
@@ -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.21
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
@@ -74,10 +74,10 @@ credentials. To learn more about how `boto3` searches for credentials on a
74
74
  machine, check [this documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html).
75
75
 
76
76
  ```python
77
- from boto3_refresh_session import AutoRefreshableSession
77
+ import boto3_refresh_session as brs
78
78
 
79
79
 
80
- sess = AutoRefreshableSession(
80
+ sess = brs.AutoRefreshableSession(
81
81
  region="<your-region>",
82
82
  role_arn="<your-role-arn>",
83
83
  session_name="<your-session-name>",
@@ -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=3bzw-zs_5TXmJsFJSSV8ENpPK3XrItvCuU2otVKn8X8,4489
3
- boto3_refresh_session-0.0.21.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
- boto3_refresh_session-0.0.21.dist-info/METADATA,sha256=eNGmHlSIeXhl-tO5vyu33VaHXbXKm9WduO8S8KrhHmQ,4007
5
- boto3_refresh_session-0.0.21.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
6
- boto3_refresh_session-0.0.21.dist-info/RECORD,,