boto3-refresh-session 0.0.21__tar.gz → 0.0.23__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/PKG-INFO +3 -3
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/README.md +2 -2
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/boto3_refresh_session/session.py +26 -8
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/pyproject.toml +8 -2
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/LICENSE +0 -0
- {boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/boto3_refresh_session/__init__.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: boto3-refresh-session
|
3
|
-
Version: 0.0.
|
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
|
-
|
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>",
|
@@ -49,10 +49,10 @@ credentials. To learn more about how `boto3` searches for credentials on a
|
|
49
49
|
machine, check [this documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html).
|
50
50
|
|
51
51
|
```python
|
52
|
-
|
52
|
+
import boto3_refresh_session as brs
|
53
53
|
|
54
54
|
|
55
|
-
sess = AutoRefreshableSession(
|
55
|
+
sess = brs.AutoRefreshableSession(
|
56
56
|
region="<your-region>",
|
57
57
|
role_arn="<your-role-arn>",
|
58
58
|
session_name="<your-session-name>",
|
{boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/boto3_refresh_session/session.py
RENAMED
@@ -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,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
|
-
|
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
|
[project]
|
2
2
|
name = "boto3-refresh-session"
|
3
|
-
version = "0.0.
|
3
|
+
version = "0.0.23"
|
4
4
|
description = "A simple Python package for refreshing boto3 sessions automatically."
|
5
5
|
authors = [
|
6
6
|
{name = "Mike Letts",email = "michaelthomasletts@gmail.com"}
|
@@ -42,4 +42,10 @@ line_length = 79
|
|
42
42
|
ensure_newline_before_comments = true
|
43
43
|
use_parentheses = true
|
44
44
|
include_trailing_comma = true
|
45
|
-
multi_line_output = 3
|
45
|
+
multi_line_output = 3
|
46
|
+
|
47
|
+
[tool.pytest.ini_options]
|
48
|
+
log_cli = true
|
49
|
+
log_cli_level = "INFO"
|
50
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
51
|
+
log_cli_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
File without changes
|
{boto3_refresh_session-0.0.21 → boto3_refresh_session-0.0.23}/boto3_refresh_session/__init__.py
RENAMED
File without changes
|