boto3-refresh-session 1.2.2__py3-none-any.whl → 1.2.4__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.2.2"
6
+ __version__ = "1.2.4"
7
7
  __author__ = "Mike Letts"
@@ -0,0 +1,96 @@
1
+ from __future__ import annotations
2
+
3
+ __all__ = ["CustomRefreshableSession"]
4
+
5
+ from typing import Any, Callable
6
+
7
+ from .session import BaseRefreshableSession
8
+
9
+
10
+ class CustomRefreshableSession(BaseRefreshableSession, method="custom"):
11
+ """A :class:`boto3.session.Session` object that automatically refreshes temporary credentials
12
+ returned by a custom credential getter provided by the user. Useful for users with highly
13
+ sophisticated or idiosyncratic authentication flows.
14
+
15
+ Parameters
16
+ ----------
17
+ custom_credentials_method: Callable
18
+ Required. Accepts a Python function that returns temporary AWS security credentials. That
19
+ function must return a dictionary containing 'access_key', 'secret_key', 'token', and
20
+ 'expiry_time' when called.
21
+ custom_credentials_method_args : dict[str, Any], optional
22
+ Optional keyword arguments for the function passed to the ``custom_credentials_method``
23
+ parameter.
24
+ defer_refresh : bool, optional
25
+ If ``True`` then temporary credentials are not automatically refreshed until
26
+ they are explicitly needed. If ``False`` then temporary credentials refresh
27
+ immediately upon expiration. It is highly recommended that you use ``True``.
28
+ Default is ``True``.
29
+
30
+ Other Parameters
31
+ ----------------
32
+ kwargs : dict
33
+ Optional keyword arguments for the :class:`boto3.session.Session` object.
34
+
35
+ Examples
36
+ --------
37
+ Write (or import) the method for obtaining temporary AWS security credentials.
38
+
39
+ >>> def your_custom_credential_getter(your_param, another_param):
40
+ >>> ...
41
+ >>> return {
42
+ >>> 'access_key': ...,
43
+ >>> 'secret_key': ...,
44
+ >>> 'token': ...,
45
+ >>> 'expiry_time': ...,
46
+ >>> }
47
+
48
+ Pass that method to ``RefreshableSession``.
49
+
50
+ >>> sess = RefreshableSession(
51
+ >>> method='custom',
52
+ >>> custom_credentials_method=your_custom_credential_getter,
53
+ >>> custom_credentials_methods_args=...,
54
+ >>> )
55
+ """
56
+
57
+ def __init__(
58
+ self,
59
+ custom_credentials_method: Callable,
60
+ custom_credentials_method_args: dict[str, Any] | None = None,
61
+ defer_refresh: bool | None = None,
62
+ **kwargs,
63
+ ):
64
+ super().__init__(**kwargs)
65
+
66
+ self._custom_get_credentials = custom_credentials_method
67
+ self._custom_get_credentials_args = (
68
+ custom_credentials_method_args
69
+ if custom_credentials_method_args is not None
70
+ else {}
71
+ )
72
+
73
+ self._refresh_using(
74
+ credentials_method=self._get_credentials,
75
+ defer_refresh=defer_refresh is not False,
76
+ refresh_method="custom",
77
+ )
78
+
79
+ def _get_credentials(self) -> dict[str, str]:
80
+ return self._custom_get_credentials(
81
+ **self._custom_get_credentials_args
82
+ )
83
+
84
+ def get_identity(self):
85
+ """Returns metadata about the custom credential getter.
86
+
87
+ Returns
88
+ -------
89
+ dict[str, str]
90
+ Dict containing information about the custom credential getter.
91
+ """
92
+
93
+ return {
94
+ "method": "custom",
95
+ "source": repr(self._custom_get_credentials.__name__),
96
+ }
@@ -14,8 +14,8 @@ from botocore.credentials import (
14
14
  from .exceptions import BRSError, BRSWarning
15
15
 
16
16
  #: Type alias for all currently available credential refresh methods.
17
- Method = Literal["sts", "ecs"]
18
- RefreshMethod = Literal["sts-assume-role", "ecs-container-metadata"]
17
+ Method = Literal["sts", "ecs", "custom"]
18
+ RefreshMethod = Literal["sts-assume-role", "ecs-container-metadata", "custom"]
19
19
 
20
20
 
21
21
  class BaseRefreshableSession(ABC, Session):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: boto3-refresh-session
3
- Version: 1.2.2
3
+ Version: 1.2.4
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
@@ -56,7 +56,7 @@ Description-Content-Type: text/markdown
56
56
  </a>
57
57
 
58
58
  <a href="https://pepy.tech/project/boto3-refresh-session">
59
- <img src="https://img.shields.io/badge/downloads-59.8K-red?logo=python&color=%23FF0000&label=Downloads" alt="Downloads"/>
59
+ <img src="https://img.shields.io/badge/downloads-62.9K-red?logo=python&color=%23FF0000&label=Downloads" alt="Downloads"/>
60
60
  </a>
61
61
 
62
62
  <a href="https://michaelthomasletts.github.io/boto3-refresh-session/index.html">
@@ -71,12 +71,16 @@ Description-Content-Type: text/markdown
71
71
  <img src="https://img.shields.io/badge/Q%26A-❔-FF0000?style=flat&labelColor=555&logo=vercel&label=Q%26A" alt="Q&A Badge"/>
72
72
  </a>
73
73
 
74
+ <a href="https://medium.com/@lettsmt/you-shouldnt-have-to-think-about-refreshing-aws-credentials-214f7cbbd83b">
75
+ <img src="https://img.shields.io/badge/Medium%20Article-📘-FF0000?style=flat&labelColor=555&logo=readthedocs" alt="Medium Article"/>
76
+ </a>
77
+
74
78
  </div>
75
79
 
76
80
  ## Features
77
81
 
78
82
  - Drop-in replacement for `boto3.session.Session`
79
- - Supports automatic credential refresh methods for the following AWS services:
83
+ - Supports automatic credential refresh methods for various AWS services:
80
84
  - STS
81
85
  - ECS
82
86
  - Supports `assume_role` configuration, custom STS clients, and profile / region configuration, as well as all other parameters supported by `boto3.session.Session`
@@ -0,0 +1,11 @@
1
+ boto3_refresh_session/__init__.py,sha256=xC5R29qlAHd-N5HGJ5UnlYSQjQYWKwHvnAXi2aLcAQY,200
2
+ boto3_refresh_session/custom.py,sha256=IZ5D0mf1FP3OsdZoctwsXKNeDPRv5Ks03Iyt4qOcdyA,3233
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.2.4.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
8
+ boto3_refresh_session-1.2.4.dist-info/METADATA,sha256=fu1UvMUHKLjodms2cpYHcsD1_MmWXgvm1jlFk6XjvrQ,7898
9
+ boto3_refresh_session-1.2.4.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
10
+ boto3_refresh_session-1.2.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ boto3_refresh_session-1.2.4.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=GxjBuAEtnvwoSO-PQOvzG0IK6LlO84zbabISpX3Mh3A,200
2
- boto3_refresh_session/ecs.py,sha256=WIC5mlbcEnM1oo-QXmmtiw2mjFDn01hBfcFh67ku42A,3713
3
- boto3_refresh_session/exceptions.py,sha256=qcFzdIuK5PZirs77H_Kb64S9QFb6cn2OJtirjvaRLiY,972
4
- boto3_refresh_session/session.py,sha256=MtaTVdAy-Yx7x_x9SUJ0FlQs0w_8D3kHjvOS8C3bK2E,5226
5
- boto3_refresh_session/sts.py,sha256=paIgbmn9a3cATNX-6AEGxnSGNZnX1pj4rRQmh8gQSKs,3132
6
- boto3_refresh_session-1.2.2.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
7
- boto3_refresh_session-1.2.2.dist-info/METADATA,sha256=eW0320X2RCmISQ-UotSbSWp5s2DVEA90z7iR-SMt7ro,7639
8
- boto3_refresh_session-1.2.2.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
9
- boto3_refresh_session-1.2.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
10
- boto3_refresh_session-1.2.2.dist-info/RECORD,,