boto3-refresh-session 0.1.15__tar.gz → 0.1.17__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 0.1.15
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
@@ -14,6 +14,7 @@ object.
14
14
  """
15
15
  __all__ = ["AutoRefreshableSession"]
16
16
 
17
+ import logging
17
18
  from typing import Type
18
19
 
19
20
  from attrs import define, field
@@ -25,6 +26,15 @@ from botocore.credentials import (
25
26
  )
26
27
  from botocore.session import get_session
27
28
 
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__)
37
+
28
38
 
29
39
  @define
30
40
  class AutoRefreshableSession:
@@ -95,10 +105,13 @@ class AutoRefreshableSession:
95
105
  default={}, validator=optional(instance_of(dict))
96
106
  )
97
107
  session: Type[Session] = field(init=False)
108
+ _creds_already_fetched: int = field(init=False, default=0)
98
109
 
99
110
  def __attrs_post_init__(self):
100
111
  __session = get_session()
101
112
 
113
+ logger.info("Fetching temporary AWS credentials.")
114
+
102
115
  if not self.defer_refresh:
103
116
  __credentials = RefreshableCredentials.create_from_metadata(
104
117
  metadata=self._get_credentials(),
@@ -124,6 +137,14 @@ class AutoRefreshableSession:
124
137
  AWS temporary credentials.
125
138
  """
126
139
 
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
147
+
127
148
  __sts_client = client(
128
149
  service_name="sts", region_name=self.region, **self.client_kwargs
129
150
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "boto3-refresh-session"
3
- version = "0.1.15"
3
+ version = "0.1.17"
4
4
  description = "A simple Python package for refreshing boto3 sessions automatically."
5
5
  authors = [
6
6
  {name = "Mike Letts",email = "lettsmt@gmail.com"}