maleo-foundation 0.2.64__py3-none-any.whl → 0.2.66__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.
- maleo_foundation/managers/client/google/storage.py +50 -3
- {maleo_foundation-0.2.64.dist-info → maleo_foundation-0.2.66.dist-info}/METADATA +1 -1
- {maleo_foundation-0.2.64.dist-info → maleo_foundation-0.2.66.dist-info}/RECORD +5 -5
- {maleo_foundation-0.2.64.dist-info → maleo_foundation-0.2.66.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.2.64.dist-info → maleo_foundation-0.2.66.dist-info}/top_level.txt +0 -0
@@ -29,6 +29,7 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
29
29
|
if self._bucket is None:
|
30
30
|
self._client.close()
|
31
31
|
raise ValueError(f"Bucket '{self._bucket_name}' does not exist.")
|
32
|
+
self._root_location = service_key
|
32
33
|
self._logger.info("Client manager initialized successfully")
|
33
34
|
|
34
35
|
@property
|
@@ -46,7 +47,50 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
46
47
|
self._client = None
|
47
48
|
self._logger.info("Client manager disposed successfully")
|
48
49
|
|
49
|
-
def
|
50
|
+
def upload(
|
51
|
+
self,
|
52
|
+
content:bytes,
|
53
|
+
location:str,
|
54
|
+
content_type:Optional[str]=None,
|
55
|
+
make_public:bool=False,
|
56
|
+
expiration:timedelta=timedelta(minutes=15),
|
57
|
+
root_location_override:BaseTypes.OptionalString=None
|
58
|
+
) -> str:
|
59
|
+
"""
|
60
|
+
Upload a file to Google Cloud Storage.
|
61
|
+
|
62
|
+
Args:
|
63
|
+
content (bytes): The file content as bytes.
|
64
|
+
location (str): The path inside the bucket to save the file.
|
65
|
+
content_type (Optional[str]): MIME type (e.g., 'image/png').
|
66
|
+
make_public (bool): Whether to make the file publicly accessible.
|
67
|
+
|
68
|
+
Returns:
|
69
|
+
str: The public URL or blob path depending on `make_public`.
|
70
|
+
"""
|
71
|
+
if root_location_override is None or (isinstance(root_location_override, str) and len(root_location_override) <= 0):
|
72
|
+
blob = self._bucket.blob(f"{self._root_location}/{location}")
|
73
|
+
else:
|
74
|
+
blob = self._bucket.blob(f"{root_location_override}/{location}")
|
75
|
+
blob.upload_from_string(content, content_type=content_type)
|
76
|
+
|
77
|
+
if make_public:
|
78
|
+
blob.make_public()
|
79
|
+
url = blob.public_url
|
80
|
+
else:
|
81
|
+
url = blob.generate_signed_url(
|
82
|
+
version="v4",
|
83
|
+
expiration=expiration,
|
84
|
+
method="GET"
|
85
|
+
)
|
86
|
+
return url
|
87
|
+
|
88
|
+
def generate_signed_url(
|
89
|
+
self,
|
90
|
+
location:str,
|
91
|
+
expiration:timedelta=timedelta(minutes=15),
|
92
|
+
root_location_override:BaseTypes.OptionalString=None
|
93
|
+
) -> str:
|
50
94
|
"""
|
51
95
|
generate signed URL of a file in the bucket based on its location.
|
52
96
|
|
@@ -60,13 +104,16 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
60
104
|
Raises:
|
61
105
|
ValueError: If the file does not exist
|
62
106
|
"""
|
63
|
-
|
107
|
+
if root_location_override is None or (isinstance(root_location_override, str) and len(root_location_override) <= 0):
|
108
|
+
blob = self._bucket.blob(blob_name=f"{self._root_location}/{location}")
|
109
|
+
else:
|
110
|
+
blob = self._bucket.blob(blob_name=f"{root_location_override}/{location}")
|
64
111
|
if not blob.exists():
|
65
112
|
raise ValueError(f"File '{location}' did not exists.")
|
66
113
|
|
67
114
|
url = blob.generate_signed_url(
|
68
115
|
version="v4",
|
69
|
-
expiration=
|
116
|
+
expiration=expiration,
|
70
117
|
method="GET"
|
71
118
|
)
|
72
119
|
return url
|
@@ -45,7 +45,7 @@ maleo_foundation/managers/client/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5J
|
|
45
45
|
maleo_foundation/managers/client/google/base.py,sha256=eIdd6C2BFIu4EyZ1j017VZaJn_nSTPGFftBwQmVAUDA,1366
|
46
46
|
maleo_foundation/managers/client/google/parameter.py,sha256=Lnj7mQgxWQpsQwbmDRK5_bF01M1QpM5PS0eZP2q17yQ,1337
|
47
47
|
maleo_foundation/managers/client/google/secret.py,sha256=Ski1CHYeA8vjSk2Oc2Pf4CfFrzT_RcA6NEZwza7gM7Y,4464
|
48
|
-
maleo_foundation/managers/client/google/storage.py,sha256=
|
48
|
+
maleo_foundation/managers/client/google/storage.py,sha256=6pmpR44mOWhgad0ylyz0xoHCAfVo-AC3cT95tRKlNNM,4370
|
49
49
|
maleo_foundation/middlewares/authentication.py,sha256=UL6kL65SvqrzemlIDopoO9N1C05eWlYMHVR2tiRsVEA,4821
|
50
50
|
maleo_foundation/middlewares/base.py,sha256=0vHU0CJEj9s3slGE3fxCQwL0_hqXW-xvhu82WRVpkpg,14551
|
51
51
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
@@ -118,7 +118,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
|
|
118
118
|
maleo_foundation/utils/loaders/credential/google.py,sha256=SKsqPuFnAiCcYLf24CxKnMybhVHpgqnq1gGSlThqjts,994
|
119
119
|
maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
|
120
120
|
maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
|
121
|
-
maleo_foundation-0.2.
|
122
|
-
maleo_foundation-0.2.
|
123
|
-
maleo_foundation-0.2.
|
124
|
-
maleo_foundation-0.2.
|
121
|
+
maleo_foundation-0.2.66.dist-info/METADATA,sha256=bY6sPTZ-OaBLRJpHBQS3Yqm3bpFPouOI1nhlvSqi9rs,3598
|
122
|
+
maleo_foundation-0.2.66.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
123
|
+
maleo_foundation-0.2.66.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
124
|
+
maleo_foundation-0.2.66.dist-info/RECORD,,
|
File without changes
|
File without changes
|