boto3-refresh-session 0.1.19__tar.gz → 0.1.20__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/PKG-INFO +1 -1
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/boto3_refresh_session/session.py +20 -11
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/pyproject.toml +1 -1
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/LICENSE +0 -0
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/README.md +0 -0
- {boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/boto3_refresh_session/__init__.py +0 -0
{boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/boto3_refresh_session/session.py
RENAMED
@@ -105,12 +105,20 @@ class AutoRefreshableSession:
|
|
105
105
|
)
|
106
106
|
session: Type[Session] = field(init=False)
|
107
107
|
_creds_already_fetched: int = field(init=False, default=0)
|
108
|
+
_sts_client: Type["botocore.client.STS"] = field(init=False)
|
108
109
|
|
109
110
|
def __attrs_post_init__(self):
|
110
|
-
|
111
|
+
# initializing session
|
112
|
+
_session = get_session()
|
113
|
+
|
114
|
+
# initializing STS client
|
115
|
+
self._sts_client = client(
|
116
|
+
service_name="sts", region_name=self.region, **self.client_kwargs
|
117
|
+
)
|
111
118
|
|
112
119
|
logger.info("Fetching temporary AWS credentials.")
|
113
120
|
|
121
|
+
# determining how to refresh expired temporary credentials
|
114
122
|
if not self.defer_refresh:
|
115
123
|
__credentials = RefreshableCredentials.create_from_metadata(
|
116
124
|
metadata=self._get_credentials(),
|
@@ -122,9 +130,12 @@ class AutoRefreshableSession:
|
|
122
130
|
refresh_using=self._get_credentials, method="sts-assume-role"
|
123
131
|
)
|
124
132
|
|
125
|
-
|
133
|
+
# mounting temporary credentials to session object
|
134
|
+
_session._credentials = __credentials
|
135
|
+
|
136
|
+
# initializing session using temporary credentials
|
126
137
|
self.session = Session(
|
127
|
-
botocore_session=
|
138
|
+
botocore_session=_session, **self.session_kwargs
|
128
139
|
)
|
129
140
|
|
130
141
|
def _get_credentials(self) -> dict:
|
@@ -144,19 +155,17 @@ class AutoRefreshableSession:
|
|
144
155
|
else:
|
145
156
|
self._creds_already_fetched += 1
|
146
157
|
|
147
|
-
|
148
|
-
|
149
|
-
)
|
150
|
-
__temporary_credentials = __sts_client.assume_role(
|
158
|
+
# fetching temporary credentials
|
159
|
+
_temporary_credentials = self._sts_client.assume_role(
|
151
160
|
RoleArn=self.role_arn,
|
152
161
|
RoleSessionName=self.session_name,
|
153
162
|
DurationSeconds=self.ttl,
|
154
163
|
)["Credentials"]
|
155
164
|
return {
|
156
|
-
"access_key":
|
157
|
-
"secret_key":
|
158
|
-
"token":
|
159
|
-
"expiry_time":
|
165
|
+
"access_key": _temporary_credentials.get("AccessKeyId"),
|
166
|
+
"secret_key": _temporary_credentials.get("SecretAccessKey"),
|
167
|
+
"token": _temporary_credentials.get("SessionToken"),
|
168
|
+
"expiry_time": _temporary_credentials.get(
|
160
169
|
"Expiration"
|
161
170
|
).isoformat(),
|
162
171
|
}
|
File without changes
|
File without changes
|
{boto3_refresh_session-0.1.19 → boto3_refresh_session-0.1.20}/boto3_refresh_session/__init__.py
RENAMED
File without changes
|