maleo-foundation 0.2.62__py3-none-any.whl → 0.2.65__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.
@@ -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,45 @@ class GoogleCloudStorage(GoogleClientManager):
46
47
  self._client = None
47
48
  self._logger.info("Client manager disposed successfully")
48
49
 
49
- def generate_signed_url(self, location:str) -> str:
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
+ ) -> str:
58
+ """
59
+ Upload a file to Google Cloud Storage.
60
+
61
+ Args:
62
+ content (bytes): The file content as bytes.
63
+ location (str): The path inside the bucket to save the file.
64
+ content_type (Optional[str]): MIME type (e.g., 'image/png').
65
+ make_public (bool): Whether to make the file publicly accessible.
66
+
67
+ Returns:
68
+ str: The public URL or blob path depending on `make_public`.
69
+ """
70
+ blob = self._bucket.blob(f"{self._root_location}/{location}")
71
+ blob.upload_from_string(content, content_type=content_type)
72
+
73
+ if make_public:
74
+ blob.make_public()
75
+ url = blob.public_url
76
+ else:
77
+ url = blob.generate_signed_url(
78
+ version="v4",
79
+ expiration=expiration,
80
+ method="GET"
81
+ )
82
+ return url
83
+
84
+ def generate_signed_url(
85
+ self,
86
+ location:str,
87
+ expiration:timedelta=timedelta(minutes=15)
88
+ ) -> str:
50
89
  """
51
90
  generate signed URL of a file in the bucket based on its location.
52
91
 
@@ -60,13 +99,13 @@ class GoogleCloudStorage(GoogleClientManager):
60
99
  Raises:
61
100
  ValueError: If the file does not exist
62
101
  """
63
- blob = self._bucket.blob(blob_name=location)
102
+ blob = self._bucket.blob(blob_name=f"{self._root_location}/{location}")
64
103
  if not blob.exists():
65
104
  raise ValueError(f"File '{location}' did not exists.")
66
105
 
67
106
  url = blob.generate_signed_url(
68
107
  version="v4",
69
- expiration=timedelta(minutes=15),
108
+ expiration=expiration,
70
109
  method="GET"
71
110
  )
72
111
  return url
@@ -41,7 +41,7 @@ from maleo_foundation.utils.logging import (
41
41
  ServiceLogger,
42
42
  MiddlewareLogger
43
43
  )
44
- from maleo_foundation.utils.mergers import BaseMergers
44
+ from maleo_foundation.utils.merger import deep_merge
45
45
 
46
46
  class Settings(BaseSettings):
47
47
  ENVIRONMENT:BaseEnums.EnvironmentType = Field(..., description="Environment")
@@ -264,7 +264,7 @@ class ServiceManager:
264
264
  )
265
265
 
266
266
  #* Load whole configurations
267
- merged_configs = BaseMergers.deep_merge(
267
+ merged_configs = deep_merge(
268
268
  static_configs.model_dump(),
269
269
  runtime_configs.model_dump(exclude={"database"}),
270
270
  {"cache": cache.model_dump()},
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.62
3
+ Version: 0.2.65
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -34,7 +34,7 @@ maleo_foundation/expanded_types/encryption/rsa.py,sha256=Esf_H8nMz2kOLAWa3M7dlD-
34
34
  maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  maleo_foundation/managers/db.py,sha256=cpY1IOiUytT9XXYtzS0E9OSYOuB7jBKo0XHe__uI1Jg,5340
36
36
  maleo_foundation/managers/middleware.py,sha256=77wRCC_CWc22nSDL-UJanO3rXmSB7wLzaAIXEFjXq6M,4249
37
- maleo_foundation/managers/service.py,sha256=ner08wL3ewUGhTLto7HJMHwXu-YDJoMtMTHDm236Bdc,19265
37
+ maleo_foundation/managers/service.py,sha256=CB6JI_jMWrVQo32jJ3oCGRgSdOfsdBehCu1pVhAJzBo,19251
38
38
  maleo_foundation/managers/cache/__init__.py,sha256=CeY0oof2bVl_v5WS-FKXNwn2gf3xrEMfUsHK9cHo59s,471
39
39
  maleo_foundation/managers/cache/base.py,sha256=YyPjde4KTsp2IHV6NdFMysa0ev-1GX1rtX-0jQPuIBU,837
40
40
  maleo_foundation/managers/cache/redis.py,sha256=xLa8QfXdNtghs0eBxIqc04H3XTYmxLEzrqJZAFCigvM,1150
@@ -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=ECyEBgEvvbTDVfqXey-meGnoU4qvIRU32BxbCuzcaHU,2576
48
+ maleo_foundation/managers/client/google/storage.py,sha256=TaOc2Dmj_CP0rpqrlBMQYAfqLSDkpgcIui1683PKR9Y,3796
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.62.dist-info/METADATA,sha256=YHruZS9nCTQHrcO0se4LewI5rveFO_GMulIRZitoqGA,3598
122
- maleo_foundation-0.2.62.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
123
- maleo_foundation-0.2.62.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
124
- maleo_foundation-0.2.62.dist-info/RECORD,,
121
+ maleo_foundation-0.2.65.dist-info/METADATA,sha256=GDsEA14M9OdABexRKjRzPB_uS5Ee8nKZ34FLm8bNgfg,3598
122
+ maleo_foundation-0.2.65.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
123
+ maleo_foundation-0.2.65.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
124
+ maleo_foundation-0.2.65.dist-info/RECORD,,