boto3-refresh-session 0.0.22__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.22 → boto3_refresh_session-0.0.23}/PKG-INFO +1 -1
- {boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/boto3_refresh_session/session.py +25 -7
- {boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/pyproject.toml +8 -2
- {boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/LICENSE +0 -0
- {boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/README.md +0 -0
- {boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/boto3_refresh_session/__init__.py +0 -0
{boto3_refresh_session-0.0.22 → 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,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
|
|
@@ -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
|
File without changes
|
{boto3_refresh_session-0.0.22 → boto3_refresh_session-0.0.23}/boto3_refresh_session/__init__.py
RENAMED
File without changes
|