rb-commons 0.5.14__tar.gz → 0.5.16__tar.gz
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.
- {rb_commons-0.5.14 → rb_commons-0.5.16}/PKG-INFO +1 -1
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/configs/config.py +0 -13
- rb_commons-0.5.16/rb_commons/configs/v2/config.py +52 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/http/base_api.py +9 -12
- rb_commons-0.5.16/rb_commons/utils/__init__.py +0 -0
- rb_commons-0.5.16/rb_commons/utils/media.py +18 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons.egg-info/PKG-INFO +1 -1
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons.egg-info/SOURCES.txt +2 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/setup.py +1 -1
- rb_commons-0.5.14/rb_commons/utils/media.py +0 -9
- {rb_commons-0.5.14 → rb_commons-0.5.16}/README.md +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/broker/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/broker/consumer.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/configs/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/configs/injections.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/configs/rabbitmq.py +0 -0
- {rb_commons-0.5.14/rb_commons/http → rb_commons-0.5.16/rb_commons/configs/v2}/__init__.py +0 -0
- {rb_commons-0.5.14/rb_commons/orm → rb_commons-0.5.16/rb_commons/http}/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/http/consul.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/http/exceptions.py +0 -0
- {rb_commons-0.5.14/rb_commons/permissions → rb_commons-0.5.16/rb_commons/orm}/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/orm/exceptions.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/orm/managers.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/orm/services.py +0 -0
- {rb_commons-0.5.14/rb_commons/schemes → rb_commons-0.5.16/rb_commons/permissions}/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/permissions/role_permissions.py +0 -0
- {rb_commons-0.5.14/rb_commons/utils → rb_commons-0.5.16/rb_commons/schemes}/__init__.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/schemes/jwt.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons/schemes/pagination.py +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons.egg-info/dependency_links.txt +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons.egg-info/requires.txt +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/rb_commons.egg-info/top_level.txt +0 -0
- {rb_commons-0.5.14 → rb_commons-0.5.16}/setup.cfg +0 -0
@@ -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."""
|
@@ -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
|
-
|
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
|
-
|
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
|
82
|
-
except BadRequestException
|
83
|
-
raise
|
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("
|
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)
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from pydantic import ValidationError
|
2
|
+
|
3
|
+
class MediaUtils:
|
4
|
+
|
5
|
+
@staticmethod
|
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
|
+
|
16
|
+
return "{endpoint_url}/{bucket_name}/{key}" \
|
17
|
+
.format(endpoint_url=DIGITALOCEAN_S3_ENDPOINT_URL,
|
18
|
+
bucket_name=DIGITALOCEAN_STORAGE_BUCKET_NAME, key=key)
|
@@ -12,6 +12,8 @@ rb_commons/configs/__init__.py
|
|
12
12
|
rb_commons/configs/config.py
|
13
13
|
rb_commons/configs/injections.py
|
14
14
|
rb_commons/configs/rabbitmq.py
|
15
|
+
rb_commons/configs/v2/__init__.py
|
16
|
+
rb_commons/configs/v2/config.py
|
15
17
|
rb_commons/http/__init__.py
|
16
18
|
rb_commons/http/base_api.py
|
17
19
|
rb_commons/http/consul.py
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
5
|
|
6
6
|
setup(
|
7
7
|
name="rb-commons",
|
8
|
-
version="0.5.
|
8
|
+
version="0.5.16",
|
9
9
|
author="Abdulvoris",
|
10
10
|
author_email="erkinovabdulvoris101@gmail.com",
|
11
11
|
description="Commons of project and simplified orm based on sqlalchemy.",
|
@@ -1,9 +0,0 @@
|
|
1
|
-
from rb_commons.configs.config import configs
|
2
|
-
|
3
|
-
class MediaUtils:
|
4
|
-
|
5
|
-
@staticmethod
|
6
|
-
def url_builder(key: str):
|
7
|
-
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)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{rb_commons-0.5.14/rb_commons/schemes → rb_commons-0.5.16/rb_commons/permissions}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|