boto3-refresh-session 0.1.16__py3-none-any.whl → 0.1.18__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
+ from logging import INFO, basicConfig, getLogger
18
18
  from typing import Type
19
19
 
20
20
  from attrs import define, field
@@ -26,8 +26,13 @@ from botocore.credentials import (
26
26
  )
27
27
  from botocore.session import get_session
28
28
 
29
+ # configuring logging
30
+ basicConfig(
31
+ level=INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
32
+ )
33
+
34
+ # creating logger
29
35
  logger = getLogger(__name__)
30
- has_logged = False
31
36
 
32
37
 
33
38
  @define
@@ -99,10 +104,13 @@ class AutoRefreshableSession:
99
104
  default={}, validator=optional(instance_of(dict))
100
105
  )
101
106
  session: Type[Session] = field(init=False)
107
+ _creds_already_fetched: int = field(init=False, default=0)
102
108
 
103
109
  def __attrs_post_init__(self):
104
110
  __session = get_session()
105
111
 
112
+ logger.info("Fetching temporary AWS credentials.")
113
+
106
114
  if not self.defer_refresh:
107
115
  __credentials = RefreshableCredentials.create_from_metadata(
108
116
  metadata=self._get_credentials(),
@@ -128,11 +136,14 @@ class AutoRefreshableSession:
128
136
  AWS temporary credentials.
129
137
  """
130
138
 
131
- global has_logged
132
- logger.info(
133
- f"{'Fetching' if not has_logged else 'Refreshing'} temporary AWS credentials"
134
- )
135
- has_logged = True
139
+ # 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)
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.18
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=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,,
@@ -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,,