boto3-refresh-session 1.0.0__py3-none-any.whl → 1.0.2__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.
@@ -6,6 +6,8 @@ credentials.
6
6
  """
7
7
  __all__ = ["RefreshableSession"]
8
8
 
9
+ from typing import Any, Dict
10
+
9
11
  from boto3 import client
10
12
  from boto3.session import Session
11
13
  from botocore.credentials import (
@@ -29,7 +31,7 @@ class RefreshableSession(Session):
29
31
  Default is ``True``.
30
32
  sts_client_kwargs : dict, optional
31
33
  Optional keyword arguments for the :class:`STS.Client` object. Default is
32
- an empty dictionary.
34
+ None.
33
35
 
34
36
  Other Parameters
35
37
  ----------------
@@ -94,9 +96,9 @@ class RefreshableSession(Session):
94
96
 
95
97
  def __init__(
96
98
  self,
97
- assume_role_kwargs: dict,
99
+ assume_role_kwargs: Dict[Any],
98
100
  defer_refresh: bool = True,
99
- sts_client_kwargs: dict = {},
101
+ sts_client_kwargs: Dict[Any] = None,
100
102
  **kwargs,
101
103
  ):
102
104
  # inheriting from boto3.session.Session
@@ -106,7 +108,10 @@ class RefreshableSession(Session):
106
108
  self.assume_role_kwargs = assume_role_kwargs
107
109
 
108
110
  # initializing the STS client
109
- self._sts_client = client(service_name="sts", **sts_client_kwargs)
111
+ if sts_client_kwargs is not None:
112
+ self._sts_client = client(service_name="sts", **sts_client_kwargs)
113
+ else:
114
+ self._sts_client = client(service_name="sts")
110
115
 
111
116
  # determining how exactly to refresh expired temporary credentials
112
117
  if not defer_refresh:
@@ -122,7 +127,7 @@ class RefreshableSession(Session):
122
127
  refresh_using=self._get_credentials, method="sts-assume-role"
123
128
  )
124
129
 
125
- def _get_credentials(self) -> dict:
130
+ def _get_credentials(self) -> Dict[Any]:
126
131
  """Returns temporary credentials via AWS STS.
127
132
 
128
133
  Returns
@@ -132,14 +137,12 @@ class RefreshableSession(Session):
132
137
  """
133
138
 
134
139
  # fetching temporary credentials
135
- _temporary_credentials = self._sts_client.assume_role(
140
+ temporary_credentials = self._sts_client.assume_role(
136
141
  **self.assume_role_kwargs
137
142
  )["Credentials"]
138
143
  return {
139
- "access_key": _temporary_credentials.get("AccessKeyId"),
140
- "secret_key": _temporary_credentials.get("SecretAccessKey"),
141
- "token": _temporary_credentials.get("SessionToken"),
142
- "expiry_time": _temporary_credentials.get(
143
- "Expiration"
144
- ).isoformat(),
144
+ "access_key": temporary_credentials.get("AccessKeyId"),
145
+ "secret_key": temporary_credentials.get("SecretAccessKey"),
146
+ "token": temporary_credentials.get("SessionToken"),
147
+ "expiry_time": temporary_credentials.get("Expiration").isoformat(),
145
148
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically.
5
5
  License: MIT
6
6
  Keywords: boto3,botocore,aws
@@ -83,13 +83,8 @@ assume_role_kwargs = {
83
83
  'DurationSeconds': '<your-selection>',
84
84
  ...
85
85
  }
86
- sts_client_kwargs = {
87
- ...
88
- }
89
86
  session = brs.RefreshableSession(
90
- assume_role_kwargs=assume_role_kwargs,
91
- sts_client_kwargs=sts_client_kwargs,
92
- region_name='us-east-1',
87
+ assume_role_kwargs=assume_role_kwargs
93
88
  )
94
89
  s3 = session.client(service_name='s3')
95
90
  buckets = s3.list_buckets()
@@ -0,0 +1,6 @@
1
+ boto3_refresh_session/__init__.py,sha256=NiaKXI1Ln9DU0cJOM3bYLEm0GNTyT7AV7D3itCGzfME,127
2
+ boto3_refresh_session/session.py,sha256=rQHJDvOAz0glymYXQBfSt1keFvQAM_G8AQXgMDLZq2U,5349
3
+ boto3_refresh_session-1.0.2.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
+ boto3_refresh_session-1.0.2.dist-info/METADATA,sha256=0AiJd6DKWLDG2JSC0smJTKpdqCQMcgukMfyAsvgX4R4,4395
5
+ boto3_refresh_session-1.0.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
+ boto3_refresh_session-1.0.2.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=NiaKXI1Ln9DU0cJOM3bYLEm0GNTyT7AV7D3itCGzfME,127
2
- boto3_refresh_session/session.py,sha256=flpqQ5E9Z6XdtFNpCO2Ew1ZVJDYGncF6PG7uwlA7IJ4,5234
3
- boto3_refresh_session-1.0.0.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
4
- boto3_refresh_session-1.0.0.dist-info/METADATA,sha256=5-yiWf1HbXj_aDfqBTqtpNzYn7tdrQxVlDjihudHQF4,4492
5
- boto3_refresh_session-1.0.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
- boto3_refresh_session-1.0.0.dist-info/RECORD,,