boto3-refresh-session 0.1.18__py3-none-any.whl → 0.1.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- __session = get_session()
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
- __session._credentials = __credentials
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=__session, **self.session_kwargs
138
+ botocore_session=_session, **self.session_kwargs
128
139
  )
129
140
 
130
141
  def _get_credentials(self) -> dict:
@@ -137,27 +148,24 @@ class AutoRefreshableSession:
137
148
  """
138
149
 
139
150
  # being careful not to duplicate logs
140
- msg = "Refreshing temporary AWS credentials"
141
- if self.defer_refresh and self._creds_already_fetched:
142
- logger.info(msg)
143
- elif not self.defer_refresh and self._creds_already_fetched > 1:
144
- logger.info(msg)
151
+ if (self.defer_refresh and self._creds_already_fetched) or (
152
+ not self.defer_refresh and self._creds_already_fetched > 1
153
+ ):
154
+ logger.info("Refreshing temporary AWS credentials")
145
155
  else:
146
156
  self._creds_already_fetched += 1
147
157
 
148
- __sts_client = client(
149
- service_name="sts", region_name=self.region, **self.client_kwargs
150
- )
151
- __temporary_credentials = __sts_client.assume_role(
158
+ # fetching temporary credentials
159
+ _temporary_credentials = self._sts_client.assume_role(
152
160
  RoleArn=self.role_arn,
153
161
  RoleSessionName=self.session_name,
154
162
  DurationSeconds=self.ttl,
155
163
  )["Credentials"]
156
164
  return {
157
- "access_key": __temporary_credentials.get("AccessKeyId"),
158
- "secret_key": __temporary_credentials.get("SecretAccessKey"),
159
- "token": __temporary_credentials.get("SessionToken"),
160
- "expiry_time": __temporary_credentials.get(
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(
161
169
  "Expiration"
162
170
  ).isoformat(),
163
171
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 0.1.18
3
+ Version: 0.1.20
4
4
  Summary: A simple Python package for refreshing boto3 sessions automatically.
5
5
  License: MIT
6
6
  Keywords: boto3,botocore,aws
@@ -0,0 +1,6 @@
1
+ boto3_refresh_session/__init__.py,sha256=OMY8el4qROyEvo0vr1Kv8rtFU7g3xnjHuBss54XRTEA,135
2
+ boto3_refresh_session/session.py,sha256=xp5MNsNgdQ9LMryPk0JQLt6Ctp0qL9WgoVXMErTv6f0,5895
3
+ boto3_refresh_session-0.1.20.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
+ boto3_refresh_session-0.1.20.dist-info/METADATA,sha256=2Q2x_9MhXu87lLjN9q-Qlhxos6QFAttVLZemReGc_Bs,4463
5
+ boto3_refresh_session-0.1.20.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
+ boto3_refresh_session-0.1.20.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=OMY8el4qROyEvo0vr1Kv8rtFU7g3xnjHuBss54XRTEA,135
2
- boto3_refresh_session/session.py,sha256=NIQLVWoXvQQIyfBBi_MHE351RIZdGUoSO3xHK1V01Rw,5569
3
- boto3_refresh_session-0.1.18.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
- boto3_refresh_session-0.1.18.dist-info/METADATA,sha256=_91E3MIBGwiklTHQKpKKoVrSE0lLq0JNhRJIytuB7vc,4463
5
- boto3_refresh_session-0.1.18.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
- boto3_refresh_session-0.1.18.dist-info/RECORD,,