boto3-refresh-session 1.3.5__py3-none-any.whl → 1.3.7__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.
@@ -3,5 +3,5 @@ from .session import RefreshableSession
3
3
  from .sts import STSRefreshableSession
4
4
 
5
5
  __all__ = ["RefreshableSession"]
6
- __version__ = "1.3.5"
6
+ __version__ = "1.3.7"
7
7
  __author__ = "Mike Letts"
@@ -4,6 +4,7 @@ __all__ = ["CustomRefreshableSession"]
4
4
 
5
5
  from typing import Any, Callable
6
6
 
7
+ from .exceptions import BRSError
7
8
  from .session import BaseRefreshableSession
8
9
 
9
10
 
@@ -50,7 +51,7 @@ class CustomRefreshableSession(BaseRefreshableSession, method="custom"):
50
51
  >>> sess = RefreshableSession(
51
52
  >>> method='custom',
52
53
  >>> custom_credentials_method=your_custom_credential_getter,
53
- >>> custom_credentials_methods_args=...,
54
+ >>> custom_credentials_method_args=...,
54
55
  >>> )
55
56
  """
56
57
 
@@ -77,11 +78,20 @@ class CustomRefreshableSession(BaseRefreshableSession, method="custom"):
77
78
  )
78
79
 
79
80
  def _get_credentials(self) -> dict[str, str]:
80
- return self._custom_get_credentials(
81
+ credentials = self._custom_get_credentials(
81
82
  **self._custom_get_credentials_args
82
83
  )
84
+ required_keys = {"access_key", "secret_key", "token", "expiry_time"}
83
85
 
84
- def get_identity(self):
86
+ if missing := required_keys - credentials.keys():
87
+ raise BRSError(
88
+ f"The dict returned by custom_credentials_method is missing these key-value pairs: "
89
+ f"{', '.join(repr(param) for param in missing)}. "
90
+ )
91
+
92
+ return credentials
93
+
94
+ def get_identity(self) -> dict[str, str]:
85
95
  """Returns metadata about the custom credential getter.
86
96
 
87
97
  Returns
@@ -90,7 +100,9 @@ class CustomRefreshableSession(BaseRefreshableSession, method="custom"):
90
100
  Dict containing information about the custom credential getter.
91
101
  """
92
102
 
93
- return {
94
- "method": "custom",
95
- "source": repr(self._custom_get_credentials.__name__),
96
- }
103
+ source = getattr(
104
+ self._custom_get_credentials,
105
+ "__name__",
106
+ repr(self._custom_get_credentials),
107
+ )
108
+ return {"method": "custom", "source": repr(source)}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 1.3.5
3
+ Version: 1.3.7
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
@@ -106,27 +106,27 @@ A testimonial from a Cyber Security Engineer at a FAANG company:
106
106
  pip install boto3-refresh-session
107
107
  ```
108
108
 
109
- ## Usage
109
+ ## Usage (STS)
110
110
 
111
111
  ```python
112
112
  import boto3_refresh_session as brs
113
113
 
114
- # you can pass all of the params associated with boto3.session.Session
115
- profile_name = '<your-profile-name>'
116
- region_name = 'us-east-1'
114
+ # you can pass all of the params normally associated with boto3.session.Session
115
+ profile_name = "<your-profile-name>"
116
+ region_name = "us-east-1"
117
117
  ...
118
118
 
119
119
  # as well as all of the params associated with STS.Client.assume_role
120
120
  assume_role_kwargs = {
121
- 'RoleArn': '<your-role-arn>',
122
- 'RoleSessionName': '<your-role-session-name>',
123
- 'DurationSeconds': '<your-selection>',
121
+ "RoleArn": "<your-role-arn>",
122
+ "RoleSessionName": "<your-role-session-name>",
123
+ "DurationSeconds": "<your-selection>",
124
124
  ...
125
125
  }
126
126
 
127
127
  # as well as all of the params associated with STS.Client, except for 'service_name'
128
128
  sts_client_kwargs = {
129
- 'region_name': region_name,
129
+ "region_name": region_name,
130
130
  ...
131
131
  }
132
132
 
@@ -138,9 +138,41 @@ session = brs.RefreshableSession(
138
138
  profile_name=profile_name,
139
139
  ...
140
140
  )
141
+ ```
142
+
143
+ ## Usage (ECS)
144
+
145
+ ```python
146
+ session = RefreshableSession(
147
+ method="ecs",
148
+ region_name=region_name,
149
+ profile_name=profile_name,
150
+ ...
151
+ )
152
+ ```
153
+
154
+ ## Usage (Custom)
141
155
 
142
- # now you can create clients, resources, etc. without worrying about expired temporary
143
- # security credentials
144
- s3 = session.client(service_name='s3')
145
- buckets = s3.list_buckets()
156
+ If you have a highly sophisticated, novel, or idiosyncratic authentication flow not included in boto3-refresh-session then you will need to provide your own custom temporary credentials method. `RefreshableSession` accepts custom credentials methods, as shown below.
157
+
158
+ ```python
159
+ # create (or import) your custom credential method
160
+ def your_custom_credential_getter(...):
161
+ ...
162
+ return {
163
+ "access_key": ...,
164
+ "secret_key": ...,
165
+ "token": ...,
166
+ "expiry_time": ...,
167
+ }
168
+
169
+ # and pass it to RefreshableSession
170
+ session = RefreshableSession(
171
+ method="custom",
172
+ custom_credentials_method=your_custom_credential_getter,
173
+ custom_credentials_method_args=...,
174
+ region_name=region_name,
175
+ profile_name=profile_name,
176
+ ...
177
+ )
146
178
  ```
@@ -0,0 +1,11 @@
1
+ boto3_refresh_session/__init__.py,sha256=Uv136RK6A7H9vQ1nzXPCuIrJBbKZmH8DQaznDFduILU,200
2
+ boto3_refresh_session/custom.py,sha256=0EemEoai-CnixXpFyvjmE5M9QffgBRZpMoTIwQPaxmY,3744
3
+ boto3_refresh_session/ecs.py,sha256=WIC5mlbcEnM1oo-QXmmtiw2mjFDn01hBfcFh67ku42A,3713
4
+ boto3_refresh_session/exceptions.py,sha256=qcFzdIuK5PZirs77H_Kb64S9QFb6cn2OJtirjvaRLiY,972
5
+ boto3_refresh_session/session.py,sha256=ak8lvgoHMObaJgL4c80ih4bptRHS3ASojnaWdbxn5kA,5246
6
+ boto3_refresh_session/sts.py,sha256=paIgbmn9a3cATNX-6AEGxnSGNZnX1pj4rRQmh8gQSKs,3132
7
+ boto3_refresh_session-1.3.7.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
8
+ boto3_refresh_session-1.3.7.dist-info/METADATA,sha256=ORil-xBwlFnv7oaFgiVN8XKglY9HM0A9jF_2j7LDmxY,7033
9
+ boto3_refresh_session-1.3.7.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
10
+ boto3_refresh_session-1.3.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ boto3_refresh_session-1.3.7.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=D0r3Nr19lp_qzLeinuCSE-7G9iq2hBj-_hMgLlktRvw,200
2
- boto3_refresh_session/custom.py,sha256=ZnN94A69Eku9L-kHZ7JJxn_aWbrt6mJDWOIEWrJrIcY,3229
3
- boto3_refresh_session/ecs.py,sha256=WIC5mlbcEnM1oo-QXmmtiw2mjFDn01hBfcFh67ku42A,3713
4
- boto3_refresh_session/exceptions.py,sha256=qcFzdIuK5PZirs77H_Kb64S9QFb6cn2OJtirjvaRLiY,972
5
- boto3_refresh_session/session.py,sha256=ak8lvgoHMObaJgL4c80ih4bptRHS3ASojnaWdbxn5kA,5246
6
- boto3_refresh_session/sts.py,sha256=paIgbmn9a3cATNX-6AEGxnSGNZnX1pj4rRQmh8gQSKs,3132
7
- boto3_refresh_session-1.3.5.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
8
- boto3_refresh_session-1.3.5.dist-info/METADATA,sha256=mJKnoAJ7RJklmP_zOF7g801DkEw1H-7vNWaRpqVnt64,6271
9
- boto3_refresh_session-1.3.5.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
10
- boto3_refresh_session-1.3.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
- boto3_refresh_session-1.3.5.dist-info/RECORD,,