rb-commons 0.5.14__py3-none-any.whl → 0.5.16__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.
@@ -25,19 +25,6 @@ class CommonConfigs(BaseSettings):
25
25
  DIGITALOCEAN_STORAGE_BUCKET_NAME: Optional[str] = None
26
26
  DIGITALOCEAN_S3_ENDPOINT_URL: Optional[str] = None
27
27
 
28
- @field_validator("POSTGRES_PORT", mode="before")
29
- @classmethod
30
- def convert_port(cls, value):
31
- print("DEBUG: POSTGRES_PORT from env =", value)
32
-
33
- if value is None:
34
- return None
35
- try:
36
- print(value)
37
- return int(value)
38
- except ValueError:
39
- raise ValueError(f"POSTGRES_PORT must be an integer, got: {value}")
40
-
41
28
  @property
42
29
  def database_url(self) -> Optional[str]:
43
30
  """Construct the database URL if all required fields are present."""
File without changes
@@ -0,0 +1,52 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import field_validator
4
+ from pydantic_settings import BaseSettings
5
+
6
+ class CommonConfigs(BaseSettings):
7
+ service_name: Optional[str] = None
8
+ service_port: Optional[int] = None
9
+ service_id: Optional[str] = None
10
+ service_hostname: Optional[Any] = '127.0.0.1'
11
+ service_host: Optional[str] = None
12
+
13
+ # db
14
+ POSTGRES_HOST: Optional[str] = None
15
+ POSTGRES_USER: Optional[str] = None
16
+ POSTGRES_PORT: Optional[int] = None
17
+ POSTGRES_PASSWORD: Optional[str] = None
18
+ POSTGRES_DB: Optional[str] = None
19
+ DB_ALEMBIC_URL: Optional[str] = None
20
+
21
+ # Broker
22
+
23
+ RABBITMQ_URL: Optional[str] = None
24
+
25
+ DIGITALOCEAN_STORAGE_BUCKET_NAME: Optional[str] = None
26
+ DIGITALOCEAN_S3_ENDPOINT_URL: Optional[str] = None
27
+
28
+ @property
29
+ def database_url(self) -> Optional[str]:
30
+ """Construct the database URL if all required fields are present."""
31
+ required_fields = [
32
+ self.POSTGRES_USER,
33
+ self.POSTGRES_PASSWORD,
34
+ self.POSTGRES_HOST,
35
+ self.POSTGRES_PORT,
36
+ self.POSTGRES_DB
37
+ ]
38
+ if all(required_fields):
39
+ return (
40
+ f"postgresql+asyncpg://{self.POSTGRES_USER}:"
41
+ f"{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:"
42
+ f"{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
43
+ )
44
+ return None
45
+
46
+ class Config:
47
+ env_file = "/robosell/.env"
48
+ env_file_encoding = "utf-8"
49
+ extra = "ignore"
50
+
51
+
52
+ configs = CommonConfigs()
@@ -66,25 +66,22 @@ class BaseAPI:
66
66
  else:
67
67
  data = {}
68
68
  except ValueError as e:
69
- raise BadRequestException(f"Invalid JSON response: {response.text}")
70
-
69
+ error_message = data.get("message") or data.get("detail") or response.text
70
+ raise BadRequestException(f"Invalid JSON response: {response.text}", additional_info={"error_message": error_message})
71
71
  if not (200 <= response.status_code < 300):
72
- error_message = data.get("message")
73
- if error_message is not None:
74
- raise BadRequestException(error_message)
75
-
76
- raise BadRequestException(f"Unexpected error occured: {response.text}")
72
+ error_message = data.get("message") or data.get("detail") or response.text
73
+ raise BadRequestException(f"Unexpected error occured: {response.text}", additional_info={"error_message": error_message})
77
74
 
78
75
  return response
79
76
 
80
77
  except RequestException as e:
81
- raise BadRequestException(f"Request failed: {e}")
82
- except BadRequestException as e:
83
- raise BadRequestException(e.message)
78
+ raise BadRequestException(f"Request exception: {str(e)}", additional_info={"error_message": str(e)})
79
+ except BadRequestException:
80
+ raise
84
81
  except (json.JSONDecodeError, ValueError) as e:
85
- raise InternalException(f"Failed to parse JSON: {e}")
82
+ raise InternalException(f"Failed to parse JSON: {str(e)}")
86
83
  except Exception as e:
87
- raise InternalException("Something went wrong")
84
+ raise InternalException(f"Unhandled error: {str(e)}")
88
85
 
89
86
  def _post(self, path: str, data: dict | list, headers: dict = None, params: dict = None, reset_base_url: bool = False, form_encoded: bool = False) -> requests.Response:
90
87
  return self._make_request('POST', path, data=data, headers=headers, params=params, reset_base_url=reset_base_url, form_encoded=form_encoded)
rb_commons/utils/media.py CHANGED
@@ -1,9 +1,18 @@
1
- from rb_commons.configs.config import configs
1
+ from pydantic import ValidationError
2
2
 
3
3
  class MediaUtils:
4
4
 
5
5
  @staticmethod
6
6
  def url_builder(key: str):
7
+ try:
8
+ from rb_commons.configs.config import configs
9
+ DIGITALOCEAN_S3_ENDPOINT_URL = configs.DIGITALOCEAN_S3_ENDPOINT_URL
10
+ DIGITALOCEAN_STORAGE_BUCKET_NAME = configs.DIGITALOCEAN_STORAGE_BUCKET_NAME
11
+ except ValidationError as e:
12
+ from rb_commons.configs.v2.config import configs
13
+ DIGITALOCEAN_S3_ENDPOINT_URL = configs.DIGITALOCEAN_S3_ENDPOINT_URL
14
+ DIGITALOCEAN_STORAGE_BUCKET_NAME = configs.DIGITALOCEAN_STORAGE_BUCKET_NAME
15
+
7
16
  return "{endpoint_url}/{bucket_name}/{key}" \
8
- .format(endpoint_url=configs.DIGITALOCEAN_S3_ENDPOINT_URL,
9
- bucket_name=configs.DIGITALOCEAN_STORAGE_BUCKET_NAME, key=key)
17
+ .format(endpoint_url=DIGITALOCEAN_S3_ENDPOINT_URL,
18
+ bucket_name=DIGITALOCEAN_STORAGE_BUCKET_NAME, key=key)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rb-commons
3
- Version: 0.5.14
3
+ Version: 0.5.16
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -2,11 +2,13 @@ rb_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  rb_commons/broker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  rb_commons/broker/consumer.py,sha256=84yLq8kJIGNYAH9_ySSTDpOMNL54NSs3cA8lNG8CTGY,1264
4
4
  rb_commons/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- rb_commons/configs/config.py,sha256=E501qNU9ATQEOGKlNnZejehU4Yj5pAwAz2aTrvOZ75k,1971
5
+ rb_commons/configs/config.py,sha256=1XVqxb9QY0E3P3n7vRJF_w238WgRpArfPVcpeT3geUE,1571
6
6
  rb_commons/configs/injections.py,sha256=6B1EOgIGnkWv3UrFaV9PRgG0-CJAbLu1UZ3kq-SjPVU,273
7
7
  rb_commons/configs/rabbitmq.py,sha256=vUqa_PcZkPp1lX0B6HLSAXVMUcPR2_8-8cN-C7xFxRI,741
8
+ rb_commons/configs/v2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ rb_commons/configs/v2/config.py,sha256=kZ02y_HIMD-SXqA990yR1r9qrkpvzwn4Nda6fhVMcmo,1581
8
10
  rb_commons/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- rb_commons/http/base_api.py,sha256=Kpr8qSbRtoAqB9oBzXJvZjspJpMoCmq8EDGSrItPFSA,5169
11
+ rb_commons/http/base_api.py,sha256=L4bZmJJrtfIp0N9vdlc9m8FzyZXb3dZ7_RMe4RQVers,5313
10
12
  rb_commons/http/consul.py,sha256=Ioq72VD1jGwoC96set7n2SgxN40olzI-myA2lwKkYi4,1864
11
13
  rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
12
14
  rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -19,8 +21,8 @@ rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
19
21
  rb_commons/schemes/jwt.py,sha256=4MLw3J1-LiU2CXIgm0kP1mlGoDmNfMXmj9iav2s-1Iw,2056
20
22
  rb_commons/schemes/pagination.py,sha256=8VZW1wZGJIPR9jEBUgppZUoB4uqP8ORudHkMwvEJSxg,1866
21
23
  rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- rb_commons/utils/media.py,sha256=KNY_9SdRa3Rp7d3B1tZaXkhmzVa65RcS62BYwZP1bVM,332
23
- rb_commons-0.5.14.dist-info/METADATA,sha256=urSAiGh-Tz0zO-AXXIooTHwCYiGwhM49Stpsoo1g_Rk,6571
24
- rb_commons-0.5.14.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
25
- rb_commons-0.5.14.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
26
- rb_commons-0.5.14.dist-info/RECORD,,
24
+ rb_commons/utils/media.py,sha256=J2Zi0J28DhcVQVzt-myNNVuzj9Msaetul53VjZtdDdc,820
25
+ rb_commons-0.5.16.dist-info/METADATA,sha256=Qe3eYj1PSMM85qmjtBzpY8TxcbOIAQjqQShsH56p_Lk,6571
26
+ rb_commons-0.5.16.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
27
+ rb_commons-0.5.16.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
28
+ rb_commons-0.5.16.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.7.1)
2
+ Generator: setuptools (80.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5