boto3-assist 0.2.3__py3-none-any.whl → 0.2.5__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_assist/s3/s3.py +21 -2
- boto3_assist/utilities/file_operations.py +10 -0
- boto3_assist/version.py +1 -1
- {boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/METADATA +1 -1
- {boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/RECORD +8 -8
- {boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/WHEEL +0 -0
- {boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/licenses/LICENSE-EXPLAINED.txt +0 -0
- {boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/licenses/LICENSE.txt +0 -0
boto3_assist/s3/s3.py
CHANGED
|
@@ -7,6 +7,7 @@ MIT License. See Project Root for the license information.
|
|
|
7
7
|
import os
|
|
8
8
|
import tempfile
|
|
9
9
|
import time
|
|
10
|
+
import io
|
|
10
11
|
from typing import Any, Dict, List, Optional
|
|
11
12
|
|
|
12
13
|
from aws_lambda_powertools import Logger
|
|
@@ -50,8 +51,22 @@ class S3(S3Connection):
|
|
|
50
51
|
aws_secret_access_key=aws_secret_access_key,
|
|
51
52
|
)
|
|
52
53
|
|
|
54
|
+
def create_bucket(self, *, bucket_name: str) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Create an S3 bucket
|
|
57
|
+
:param bucket_name: Bucket to create
|
|
58
|
+
:return: True if bucket is created, else False
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
self.client.create_bucket(Bucket=bucket_name)
|
|
62
|
+
logger.info(f"Bucket {bucket_name} created")
|
|
63
|
+
except ClientError as e:
|
|
64
|
+
logger.exception(e)
|
|
65
|
+
raise e
|
|
66
|
+
|
|
53
67
|
def generate_presigned_url(
|
|
54
68
|
self,
|
|
69
|
+
*,
|
|
55
70
|
bucket_name: str,
|
|
56
71
|
key_path: str,
|
|
57
72
|
user_id: str,
|
|
@@ -139,7 +154,7 @@ class S3(S3Connection):
|
|
|
139
154
|
|
|
140
155
|
return response
|
|
141
156
|
|
|
142
|
-
def upload_file_obj(self, bucket: str, key: str, file_obj: bytes | str) -> str:
|
|
157
|
+
def upload_file_obj(self, *, bucket: str, key: str, file_obj: bytes | str) -> str:
|
|
143
158
|
"""
|
|
144
159
|
Uploads a file object to s3. Returns the full s3 path s3://<bucket>/<key>
|
|
145
160
|
"""
|
|
@@ -160,7 +175,9 @@ class S3(S3Connection):
|
|
|
160
175
|
file_obj: bytes = (
|
|
161
176
|
file_obj.encode("utf-8") if isinstance(file_obj, str) else file_obj
|
|
162
177
|
)
|
|
163
|
-
self.client.upload_fileobj(
|
|
178
|
+
self.client.upload_fileobj(
|
|
179
|
+
Fileobj=io.BytesIO(file_obj), Bucket=bucket, Key=key
|
|
180
|
+
)
|
|
164
181
|
|
|
165
182
|
except ClientError as ce:
|
|
166
183
|
error = {
|
|
@@ -176,6 +193,7 @@ class S3(S3Connection):
|
|
|
176
193
|
|
|
177
194
|
def upload_file(
|
|
178
195
|
self,
|
|
196
|
+
*,
|
|
179
197
|
bucket: str,
|
|
180
198
|
key: str,
|
|
181
199
|
local_file_path: str,
|
|
@@ -222,6 +240,7 @@ class S3(S3Connection):
|
|
|
222
240
|
|
|
223
241
|
def download_file(
|
|
224
242
|
self,
|
|
243
|
+
*,
|
|
225
244
|
bucket: str,
|
|
226
245
|
key: str,
|
|
227
246
|
local_directory: str | None = None,
|
|
@@ -58,6 +58,16 @@ class FileOperations:
|
|
|
58
58
|
dirname = os.path.dirname(path)
|
|
59
59
|
return dirname
|
|
60
60
|
|
|
61
|
+
@staticmethod
|
|
62
|
+
def read_file(path: str, encoding: str = "utf-8") -> str:
|
|
63
|
+
"""
|
|
64
|
+
Read a file
|
|
65
|
+
"""
|
|
66
|
+
logger.debug(f"reading file {path}")
|
|
67
|
+
with open(path, "r", encoding=encoding) as file:
|
|
68
|
+
data = file.read()
|
|
69
|
+
return data
|
|
70
|
+
|
|
61
71
|
@staticmethod
|
|
62
72
|
def write_to_file(path: str, data: str, append: bool = False) -> str:
|
|
63
73
|
"""
|
boto3_assist/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.2.
|
|
1
|
+
__version__ = '0.2.5'
|
|
@@ -2,7 +2,7 @@ boto3_assist/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
boto3_assist/boto3session.py,sha256=NWhWtYR3143thEbTpoklkwdz77-fTMs-QsoQdqfRm6E,6430
|
|
3
3
|
boto3_assist/connection.py,sha256=EJlGueLIYqMSKs7aQlThK1S0Zkb8dOYBWch1iRZdgUI,3233
|
|
4
4
|
boto3_assist/connection_tracker.py,sha256=_s1t7h2DOi3CCIHIr_HIKyGjku65WR-HJ_v8vJHDvO0,2977
|
|
5
|
-
boto3_assist/version.py,sha256=
|
|
5
|
+
boto3_assist/version.py,sha256=8f4ummWTPl6PtdE9DzSUgZhPjGioA_NDC-hDpqzB9qI,22
|
|
6
6
|
boto3_assist/cloudwatch/cloudwatch_connection.py,sha256=mnGWaLSQpHh5EeY7Ek_2o9JKHJxOELIYtQVMX1IaHn4,2480
|
|
7
7
|
boto3_assist/cloudwatch/cloudwatch_connection_tracker.py,sha256=mzRtO1uHrcfJNh1XrGEiXdTqxwEP8d1RqJkraMNkgK0,410
|
|
8
8
|
boto3_assist/cloudwatch/cloudwatch_log_connection.py,sha256=qQMZHjUJ6gA8wU9utjQhOURXNSPH2RjxSoAy83bvoCs,1737
|
|
@@ -28,16 +28,16 @@ boto3_assist/environment_services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
|
|
|
28
28
|
boto3_assist/environment_services/environment_loader.py,sha256=jvG1xwMtgkZqu70NbjG1b1IefKiWgaidjZZoqsSfULk,3370
|
|
29
29
|
boto3_assist/environment_services/environment_variables.py,sha256=4ccBKdPt6O7hcRT3zBHd8vqu8yQU8udmoD5RLAT3iMs,6801
|
|
30
30
|
boto3_assist/errors/custom_exceptions.py,sha256=zC2V2Y4PUtKj3uLPn8mB-JessksKWJWvKM9kp1dmvt8,760
|
|
31
|
-
boto3_assist/s3/s3.py,sha256=
|
|
31
|
+
boto3_assist/s3/s3.py,sha256=DFCJs5z1mMIT8nZfnqPyr_cvhi9-FePuYH--tzD7b5E,17104
|
|
32
32
|
boto3_assist/s3/s3_connection.py,sha256=fMD1FxQazJ9gSFDrRmrv7YJE5QnCesGoWC1b5Dba_Jo,3774
|
|
33
33
|
boto3_assist/utilities/datetime_utility.py,sha256=TbqGQkJDTahqvaZAIV550nhYnW1Bsq0Hdu3Go6P4RRs,10282
|
|
34
|
-
boto3_assist/utilities/file_operations.py,sha256=
|
|
34
|
+
boto3_assist/utilities/file_operations.py,sha256=Zy8fu8fpuVNf7U9NimrLdy5FRF71XSI159cnRdzmzGY,3411
|
|
35
35
|
boto3_assist/utilities/http_utility.py,sha256=koFv7Va-8ng-47Nt1K2Sh7Ti95e62IYs9VMLlGh9Kt4,1173
|
|
36
36
|
boto3_assist/utilities/logging_utility.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
37
|
boto3_assist/utilities/serialization_utility.py,sha256=s_QQRIhtwIE7xN5nU13mNk2wtWyErBX_Sg7n0gbHj-M,4308
|
|
38
38
|
boto3_assist/utilities/string_utility.py,sha256=w8l063UT3GE48tuJopETyZrjG4CgAzWkyDWMAYMg5Og,7432
|
|
39
|
-
boto3_assist-0.2.
|
|
40
|
-
boto3_assist-0.2.
|
|
41
|
-
boto3_assist-0.2.
|
|
42
|
-
boto3_assist-0.2.
|
|
43
|
-
boto3_assist-0.2.
|
|
39
|
+
boto3_assist-0.2.5.dist-info/METADATA,sha256=hggHfXBaekU-StXveMPM2AI3Q8WYz1ZeC--FqMsPDiY,1742
|
|
40
|
+
boto3_assist-0.2.5.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
41
|
+
boto3_assist-0.2.5.dist-info/licenses/LICENSE-EXPLAINED.txt,sha256=WFREvTpfTjPjDHpOLADxJpCKpIla3Ht87RUUGii4ODU,606
|
|
42
|
+
boto3_assist-0.2.5.dist-info/licenses/LICENSE.txt,sha256=PXDhFWS5L5aOTkVhNvoitHKbAkgxqMI2uUPQyrnXGiI,1105
|
|
43
|
+
boto3_assist-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
{boto3_assist-0.2.3.dist-info → boto3_assist-0.2.5.dist-info}/licenses/LICENSE-EXPLAINED.txt
RENAMED
|
File without changes
|
|
File without changes
|