boto3-refresh-session 0.1.16__py3-none-any.whl → 0.1.17__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.
@@ -14,7 +14,7 @@ object.
14
14
  """
15
15
  __all__ = ["AutoRefreshableSession"]
16
16
 
17
- from logging import getLogger
17
+ import logging
18
18
  from typing import Type
19
19
 
20
20
  from attrs import define, field
@@ -26,8 +26,14 @@ from botocore.credentials import (
26
26
  )
27
27
  from botocore.session import get_session
28
28
 
29
- logger = getLogger(__name__)
30
- has_logged = False
29
+ # configuring logging
30
+ logging.basicConfig(
31
+ level=logging.INFO,
32
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
33
+ )
34
+
35
+ # creating logger
36
+ logger = logging.getLogger(__name__)
31
37
 
32
38
 
33
39
  @define
@@ -99,10 +105,13 @@ class AutoRefreshableSession:
99
105
  default={}, validator=optional(instance_of(dict))
100
106
  )
101
107
  session: Type[Session] = field(init=False)
108
+ _creds_already_fetched: int = field(init=False, default=0)
102
109
 
103
110
  def __attrs_post_init__(self):
104
111
  __session = get_session()
105
112
 
113
+ logger.info("Fetching temporary AWS credentials.")
114
+
106
115
  if not self.defer_refresh:
107
116
  __credentials = RefreshableCredentials.create_from_metadata(
108
117
  metadata=self._get_credentials(),
@@ -128,11 +137,13 @@ class AutoRefreshableSession:
128
137
  AWS temporary credentials.
129
138
  """
130
139
 
131
- global has_logged
132
- logger.info(
133
- f"{'Fetching' if not has_logged else 'Refreshing'} temporary AWS credentials"
134
- )
135
- has_logged = True
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)
145
+ else:
146
+ self._creds_already_fetched += 1
136
147
 
137
148
  __sts_client = client(
138
149
  service_name="sts", region_name=self.region, **self.client_kwargs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 0.1.16
3
+ Version: 0.1.17
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=DC12GTqyuoCE1UVpQnYQ870S3yp2x7RZNdX-wtxk5ok,5518
3
+ boto3_refresh_session-0.1.17.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
+ boto3_refresh_session-0.1.17.dist-info/METADATA,sha256=ctmV-A0UiknIiwGfA4jgjDbFNuTQN3C86vLf4Epi0CM,4463
5
+ boto3_refresh_session-0.1.17.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
+ boto3_refresh_session-0.1.17.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=OMY8el4qROyEvo0vr1Kv8rtFU7g3xnjHuBss54XRTEA,135
2
- boto3_refresh_session/session.py,sha256=TbXUZeeDjB4KAte-AToCwCsBcOB0WgLXk9KN87aafAg,5133
3
- boto3_refresh_session-0.1.16.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
- boto3_refresh_session-0.1.16.dist-info/METADATA,sha256=MXK6MLL10Qu9SKDYEcs8MdjJ97ANH9rbBmfXW15-ogQ,4463
5
- boto3_refresh_session-0.1.16.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
- boto3_refresh_session-0.1.16.dist-info/RECORD,,