boto3-refresh-session 1.0.5__py3-none-any.whl → 1.0.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.
- boto3_refresh_session/__init__.py +1 -1
- boto3_refresh_session/session.py +9 -2
- {boto3_refresh_session-1.0.5.dist-info → boto3_refresh_session-1.0.7.dist-info}/METADATA +47 -42
- boto3_refresh_session-1.0.7.dist-info/RECORD +6 -0
- boto3_refresh_session-1.0.5.dist-info/RECORD +0 -6
- {boto3_refresh_session-1.0.5.dist-info → boto3_refresh_session-1.0.7.dist-info}/LICENSE +0 -0
- {boto3_refresh_session-1.0.5.dist-info → boto3_refresh_session-1.0.7.dist-info}/WHEEL +0 -0
boto3_refresh_session/session.py
CHANGED
@@ -7,6 +7,7 @@ credentials.
|
|
7
7
|
__all__ = ["RefreshableSession"]
|
8
8
|
|
9
9
|
from typing import Any, Dict
|
10
|
+
from warnings import warn
|
10
11
|
|
11
12
|
from boto3 import client
|
12
13
|
from boto3.session import Session
|
@@ -30,8 +31,8 @@ class RefreshableSession(Session):
|
|
30
31
|
immediately upon expiration. It is highly recommended that you use ``True``.
|
31
32
|
Default is ``True``.
|
32
33
|
sts_client_kwargs : dict, optional
|
33
|
-
Optional keyword arguments for the :class:`STS.Client` object.
|
34
|
-
None.
|
34
|
+
Optional keyword arguments for the :class:`STS.Client` object. Do not provide
|
35
|
+
values for ``service_name``. Default is None.
|
35
36
|
|
36
37
|
Other Parameters
|
37
38
|
----------------
|
@@ -109,6 +110,12 @@ class RefreshableSession(Session):
|
|
109
110
|
|
110
111
|
# initializing the STS client
|
111
112
|
if sts_client_kwargs is not None:
|
113
|
+
# overwriting 'service_name' in case it appears in sts_client_kwargs
|
114
|
+
if "service_name" in sts_client_kwargs:
|
115
|
+
warn(
|
116
|
+
"The sts_client_kwargs parameter cannot contain values for service_name. Reverting to service_name = 'sts'."
|
117
|
+
)
|
118
|
+
del sts_client_kwargs["service_name"]
|
112
119
|
self._sts_client = client(service_name="sts", **sts_client_kwargs)
|
113
120
|
else:
|
114
121
|
self._sts_client = client(service_name="sts")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: boto3-refresh-session
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.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
|
@@ -32,71 +32,76 @@ Description-Content-Type: text/markdown
|
|
32
32
|
|
33
33
|
A simple Python package for refreshing the temporary security credentials in a `boto3.session.Session` object automatically.
|
34
34
|
|
35
|
-
- [Documentation](https://michaelthomasletts.github.io/boto3-refresh-session/index.html)
|
35
|
+
- [Official Documentation](https://michaelthomasletts.github.io/boto3-refresh-session/index.html)
|
36
36
|
- [Source Code](https://github.com/michaelthomasletts/boto3-refresh-session)
|
37
37
|
- [PyPI](https://pypi.org/project/boto3-refresh-session/)
|
38
38
|
- [Contributing](https://michaelthomasletts.github.io/boto3-refresh-session/contributing.html)
|
39
|
+
- [Authorization](https://michaelthomasletts.github.io/boto3-refresh-session/authorization.html)
|
39
40
|
|
40
|
-
###
|
41
|
-
|
42
|
-
It is common for data pipelines and workflows that interact with the AWS API via
|
43
|
-
`boto3` to run for a long time and, accordingly, for temporary credentials to
|
44
|
-
expire.
|
45
|
-
|
46
|
-
Usually, engineers deal with that problem one of two different ways:
|
47
|
-
|
48
|
-
- A `try except` block that catches `botocore.exceptions.ClientError` exceptions
|
49
|
-
- A similar approach as that used in this project -- that is, using methods available
|
50
|
-
within `botocore` for refreshing temporary credentials automatically.
|
51
|
-
|
52
|
-
Speaking personally, variations of the code found herein exists in code bases at
|
53
|
-
nearly every company where I have worked. Sometimes, I turned that code into a module;
|
54
|
-
other times, I wrote it from scratch. Clearly, that is inefficient.
|
55
|
-
|
56
|
-
I decided to finally turn that code into a proper Python package with unit testing,
|
57
|
-
automatic documentation, and quality checks; the idea being that, henceforth, depending
|
58
|
-
on my employer's open source policy, I may simply import this package instead of
|
59
|
-
reproducing the code herein for the Nth time.
|
41
|
+
### Installation
|
60
42
|
|
61
|
-
|
43
|
+
```bash
|
44
|
+
pip install boto3-refresh-session
|
45
|
+
```
|
62
46
|
|
63
47
|
### Usage
|
64
48
|
|
65
|
-
Simply pass the basic parameters and initialize the `RefreshableSession` object;
|
66
|
-
that's it! You're good to go!
|
67
|
-
|
68
|
-
`RefreshableSession` will refresh
|
69
|
-
temporary credentials for you in the background. In the following example,
|
70
|
-
continue using the `s3_client` object without worry of using `try` and
|
71
|
-
`except` blocks!
|
72
|
-
|
73
|
-
To use this package, your machine must be configured with AWS
|
74
|
-
credentials. To learn more about how `boto3` searches for credentials on a
|
75
|
-
machine, check [this documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html).
|
76
|
-
|
77
49
|
```python
|
78
50
|
import boto3_refresh_session as brs
|
79
51
|
|
52
|
+
# you can pass all of the params associated with boto3.session.Session
|
53
|
+
profile_name = '<your-profile-name>'
|
54
|
+
region_name = 'us-east-1'
|
55
|
+
...
|
56
|
+
|
57
|
+
# as well as all of the params associated with STS.Client.assume_role
|
80
58
|
assume_role_kwargs = {
|
81
59
|
'RoleArn': '<your-role-arn>',
|
82
60
|
'RoleSessionName': '<your-role-session-name>',
|
83
61
|
'DurationSeconds': '<your-selection>',
|
84
62
|
...
|
85
63
|
}
|
64
|
+
|
65
|
+
# as well as all of the params associated with STS.Client, except for 'service_name'
|
66
|
+
sts_client_kwargs = {
|
67
|
+
'region_name': region_name,
|
68
|
+
...
|
69
|
+
}
|
70
|
+
|
71
|
+
# basic initialization of boto3.session.Session
|
86
72
|
session = brs.RefreshableSession(
|
87
|
-
assume_role_kwargs=assume_role_kwargs
|
73
|
+
assume_role_kwargs=assume_role_kwargs, # required
|
74
|
+
sts_client_kwargs=sts_client_kwargs,
|
75
|
+
region_name=region_name,
|
76
|
+
profile_name=profile_name,
|
77
|
+
...
|
88
78
|
)
|
79
|
+
|
80
|
+
# now you can create clients, resources, etc. without worrying about expired temporary
|
81
|
+
# security credentials
|
89
82
|
s3 = session.client(service_name='s3')
|
90
83
|
buckets = s3.list_buckets()
|
91
84
|
```
|
92
85
|
|
93
|
-
###
|
86
|
+
### Raison d'être
|
94
87
|
|
95
|
-
|
96
|
-
|
97
|
-
|
88
|
+
It is common for data pipelines and workflows that interact with the AWS API via
|
89
|
+
`boto3` to run for a long time and, accordingly, for temporary credentials to
|
90
|
+
expire.
|
91
|
+
|
92
|
+
Usually, engineers deal with that problem one of two ways:
|
98
93
|
|
99
|
-
|
94
|
+
- `try except` blocks that catch `ClientError` exceptions
|
95
|
+
- A similar approach as that used in this project -- that is, using methods available
|
96
|
+
within `botocore` for refreshing temporary credentials automatically.
|
97
|
+
|
98
|
+
Speaking personally, variations of the code found herein exists in code bases at
|
99
|
+
nearly every company where I have worked. Sometimes, I turned that code into a module;
|
100
|
+
other times, I wrote it from scratch. Clearly, that is inefficient.
|
100
101
|
|
101
|
-
|
102
|
+
I decided to finally turn that code into a proper Python package with unit testing,
|
103
|
+
automatic documentation, and quality checks; the idea being that, henceforth, depending
|
104
|
+
on my employer's open source policy, I may simply import this package instead of
|
105
|
+
reproducing the code herein for the Nth time.
|
102
106
|
|
107
|
+
If any of that sounds relatable, then `boto3-refresh-session` should help you.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
boto3_refresh_session/__init__.py,sha256=mJmZoHQhXLNiReopzgvH0alWL0kjwNFk1kAumCrKXxo,157
|
2
|
+
boto3_refresh_session/session.py,sha256=p4adQ4G2rVm8PPT8xOVV8oMPLS-2h6pSgZNeFd1E1uI,5775
|
3
|
+
boto3_refresh_session-1.0.7.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
|
4
|
+
boto3_refresh_session-1.0.7.dist-info/METADATA,sha256=s3AXxwUzo2HsFcDqgTsaxGoKstwsXOzdDqXA3aL3Whs,4450
|
5
|
+
boto3_refresh_session-1.0.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
6
|
+
boto3_refresh_session-1.0.7.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
boto3_refresh_session/__init__.py,sha256=fhdmmJvDMjsAMZIl9911pQ4yfIcEKrPsfMd5aPFhOfM,157
|
2
|
-
boto3_refresh_session/session.py,sha256=rQHJDvOAz0glymYXQBfSt1keFvQAM_G8AQXgMDLZq2U,5349
|
3
|
-
boto3_refresh_session-1.0.5.dist-info/LICENSE,sha256=I3ZYTXAjbIly6bm6J-TvFTuuHwTKws4h89QaY5c5HiY,1067
|
4
|
-
boto3_refresh_session-1.0.5.dist-info/METADATA,sha256=SkOptv4Q18voBDOooLYjs7VW7Jgsby-6kY8SikHK08U,4395
|
5
|
-
boto3_refresh_session-1.0.5.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
6
|
-
boto3_refresh_session-1.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|