boto3-refresh-session 1.2.3__py3-none-any.whl → 1.3.0__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.3"
6
+ __version__ = "1.3.0"
7
7
  __author__ = "Mike Letts"
@@ -0,0 +1,100 @@
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
+ <<<<<<< feature/custom_get_credentials
39
+
40
+ =======
41
+
42
+ >>>>>>> main
43
+ >>> def your_custom_credential_getter(your_param, another_param):
44
+ >>> ...
45
+ >>> return {
46
+ >>> 'access_key': ...,
47
+ >>> 'secret_key': ...,
48
+ >>> 'token': ...,
49
+ >>> 'expiry_time': ...,
50
+ >>> }
51
+
52
+ Pass that method to ``RefreshableSession``.
53
+
54
+ >>> sess = RefreshableSession(
55
+ >>> method='custom',
56
+ >>> custom_credentials_method=your_custom_credential_getter,
57
+ >>> custom_credentials_methods_args=...,
58
+ >>> )
59
+ """
60
+
61
+ def __init__(
62
+ self,
63
+ custom_credentials_method: Callable,
64
+ custom_credentials_method_args: dict[str, Any] | None = None,
65
+ defer_refresh: bool | None = None,
66
+ **kwargs,
67
+ ):
68
+ super().__init__(**kwargs)
69
+
70
+ self._custom_get_credentials = custom_credentials_method
71
+ self._custom_get_credentials_args = (
72
+ custom_credentials_method_args
73
+ if custom_credentials_method_args is not None
74
+ else {}
75
+ )
76
+
77
+ self._refresh_using(
78
+ credentials_method=self._get_credentials,
79
+ defer_refresh=defer_refresh is not False,
80
+ refresh_method="custom",
81
+ )
82
+
83
+ def _get_credentials(self) -> dict[str, str]:
84
+ return self._custom_get_credentials(
85
+ **self._custom_get_credentials_args
86
+ )
87
+
88
+ def get_identity(self):
89
+ """Returns metadata about the custom credential getter.
90
+
91
+ Returns
92
+ -------
93
+ dict[str, str]
94
+ Dict containing information about the custom credential getter.
95
+ """
96
+
97
+ return {
98
+ "method": "custom",
99
+ "source": repr(self._custom_get_credentials.__name__),
100
+ }
@@ -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.3
3
+ Version: 1.3.0
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">
@@ -73,7 +73,7 @@ Description-Content-Type: text/markdown
73
73
 
74
74
  <a href="https://medium.com/@lettsmt/you-shouldnt-have-to-think-about-refreshing-aws-credentials-214f7cbbd83b">
75
75
  <img src="https://img.shields.io/badge/Medium%20Article-📘-FF0000?style=flat&labelColor=555&logo=readthedocs" alt="Medium Article"/>
76
- </a>
76
+ </a>
77
77
 
78
78
  </div>
79
79
 
@@ -0,0 +1,11 @@
1
+ boto3_refresh_session/__init__.py,sha256=6BxJIN_2xE7AAt7aHPP-ca9La7lPMr0lfGg4F4guY8U,200
2
+ boto3_refresh_session/custom.py,sha256=oBsHpJ2hvVM_IJ0gTqBskWzTrL5__mPqUe_KBXGpTTA,3294
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.0.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
8
+ boto3_refresh_session-1.3.0.dist-info/METADATA,sha256=5dF_ymi5PcKg3fywjz73p3-jZESbyxVa1fj-bhhWYNg,7898
9
+ boto3_refresh_session-1.3.0.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
10
+ boto3_refresh_session-1.3.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ boto3_refresh_session-1.3.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- boto3_refresh_session/__init__.py,sha256=KMGil5Pgv78RAt3qeKOSE1rFUl0giSNomig21NJVzEM,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.3.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
7
- boto3_refresh_session-1.2.3.dist-info/METADATA,sha256=GL5xcmNfSqLdFSUZrI8vGNa7OFb8O6sYGaTj9mVV0pQ,7896
8
- boto3_refresh_session-1.2.3.dist-info/NOTICE,sha256=1s8r33qbl1z0YvPB942iWgvbkP94P_e8AnROr1qXXuw,939
9
- boto3_refresh_session-1.2.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
10
- boto3_refresh_session-1.2.3.dist-info/RECORD,,