utg-base 1.5.7__py3-none-any.whl → 1.6.1__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.
- utg_base/api/spectacular.py +33 -0
- utg_base/logging.py +13 -11
- utg_base/middleware/debug.py +10 -0
- utg_base/utils/translation.py +2 -3
- {utg_base-1.5.7.dist-info → utg_base-1.6.1.dist-info}/METADATA +1 -1
- {utg_base-1.5.7.dist-info → utg_base-1.6.1.dist-info}/RECORD +7 -5
- {utg_base-1.5.7.dist-info → utg_base-1.6.1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from django.http import HttpResponseForbidden
|
|
3
|
+
from django.urls import path
|
|
4
|
+
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
|
|
5
|
+
from rest_framework.views import APIView
|
|
6
|
+
|
|
7
|
+
from utg_base.env import env
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DebugTokenRequiredMixin(APIView):
|
|
11
|
+
"""
|
|
12
|
+
If Request header X-Debug-Token not found then 403
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def dispatch(self, request, *args, **kwargs):
|
|
16
|
+
token = request.headers.get("X-Debug-Token")
|
|
17
|
+
if not settings.DEBUG and token != env("DJANGO_SECRET_KEY"):
|
|
18
|
+
return HttpResponseForbidden("Forbidden")
|
|
19
|
+
return super().dispatch(request, *args, **kwargs)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ProtectedSpectacularAPIView(DebugTokenRequiredMixin, SpectacularAPIView):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ProtectedSpectacularSwaggerView(DebugTokenRequiredMixin, SpectacularSwaggerView):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
urlpatterns = [
|
|
31
|
+
path('api/swagger/schema/', ProtectedSpectacularAPIView.as_view(), name='schema'),
|
|
32
|
+
path('api/docs/', ProtectedSpectacularSwaggerView.as_view(url_name='schema'), name='docs'),
|
|
33
|
+
]
|
utg_base/logging.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
|
+
from utg_base.env import env
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
class UtgBaseFilter(logging.Filter):
|
|
6
8
|
BASE_DIR = os.getcwd()
|
|
@@ -21,10 +23,10 @@ class UtgBaseFilter(logging.Filter):
|
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
class UtgBaseLogging:
|
|
24
|
-
enable_console_info = int(
|
|
25
|
-
enable_db_debug = int(
|
|
26
|
-
enable_loki = int(
|
|
27
|
-
enable_loki_debug = int(
|
|
26
|
+
enable_console_info = int(env('LOGGING_CONSOLE_INFO', True))
|
|
27
|
+
enable_db_debug = int(env('LOGGING_DB_DEBUG', False))
|
|
28
|
+
enable_loki = int(env('LOGGING_LOKI', True))
|
|
29
|
+
enable_loki_debug = int(env('LOGGING_LOKI_DEBUG', False))
|
|
28
30
|
|
|
29
31
|
logger = logging.getLogger('main')
|
|
30
32
|
|
|
@@ -63,19 +65,19 @@ class UtgBaseLogging:
|
|
|
63
65
|
'filters': ['trim_path'],
|
|
64
66
|
},
|
|
65
67
|
'loki': {
|
|
66
|
-
'level':
|
|
68
|
+
'level': env('LOKI_LEVEL', 'ERROR'), # required
|
|
67
69
|
'class': 'django_loki.LokiHttpHandler', # required
|
|
68
|
-
'host':
|
|
70
|
+
'host': env('LOKI_HOST', env('DB_HOST')),
|
|
69
71
|
# required, your grafana/Loki server host, e.g:192.168.25.30
|
|
70
72
|
'formatter': 'loki', # required, loki formatter,
|
|
71
|
-
'port': int(
|
|
73
|
+
'port': int(env('LOKI_PORT', 3100)),
|
|
72
74
|
# optional, your grafana/Loki server port, default is 3100
|
|
73
|
-
'timeout': float(
|
|
75
|
+
'timeout': float(env('LOKI_TIMEOUT', 0.5)),
|
|
74
76
|
# optional, request Loki-server by http or https time out, default is 0.5
|
|
75
|
-
'protocol':
|
|
77
|
+
'protocol': env('LOKI_PROTOCOL', 'http'),
|
|
76
78
|
# optional, Loki-server protocol, default is http
|
|
77
|
-
'source':
|
|
78
|
-
'src_host':
|
|
79
|
+
'source': env('LOKI_SOURCE', 'Loki'), # optional, label name for Loki, default is Loki
|
|
80
|
+
'src_host': env('LOKI_SRC_HOST', 'localhost'),
|
|
79
81
|
# optional, label name for Loki, default is localhost
|
|
80
82
|
'tz': 'Asia/Tashkent',
|
|
81
83
|
# optional, timezone for formatting timestamp, default is UTC, e.g:Asia/Shanghai
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from django.utils.deprecation import MiddlewareMixin
|
|
2
|
+
|
|
3
|
+
from utg_base.env import env
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DebugOverrideMiddleware(MiddlewareMixin):
|
|
7
|
+
def process_exception(self, request, exception):
|
|
8
|
+
if request.headers.get("X-Debug-Token") == env("DJANGO_SECRET_KEY"):
|
|
9
|
+
from django.views import debug
|
|
10
|
+
return debug.technical_500_response(request, type(exception), exception, exception.__traceback__)
|
utg_base/utils/translation.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
1
|
import requests
|
|
4
2
|
from django.utils.translation import get_language
|
|
5
3
|
|
|
6
4
|
from utg_base.constants import AVAILABLE_LANGUAGES
|
|
5
|
+
from utg_base.env import env
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
def translate(key: str) -> str:
|
|
10
|
-
base_url =
|
|
9
|
+
base_url = env('TRANSLATION_SERVICE_URL')
|
|
11
10
|
lang = get_language()
|
|
12
11
|
if lang == 'uz-cyr':
|
|
13
12
|
lang = 'crl'
|
|
@@ -5,6 +5,7 @@ utg_base/api/pagination.py,sha256=zzIUwW3iF5G_11gFsno9y1DmgFiULQIWRHUj0LKhYfE,85
|
|
|
5
5
|
utg_base/api/permissions.py,sha256=RjkxYWPl5Xwgk5lIZrcBzIAwlXolX5XPlae1jr-Ln2w,323
|
|
6
6
|
utg_base/api/routers.py,sha256=lU54MVN2BF_q1AWp9EdXkG3m_ivYRtvbNGXFIRKz7u0,177
|
|
7
7
|
utg_base/api/serializers.py,sha256=qI6wWjwl1oeUPHCJUCpYFIaiRFvfQW6FM0xPC9fwfQI,1214
|
|
8
|
+
utg_base/api/spectacular.py,sha256=W1G2c6Mw8OkTVwXHxJYzbadW9jykkkAn0C8tQu9gfuA,1047
|
|
8
9
|
utg_base/api/views.py,sha256=yYCEJRouFA71cI2Ubc1A736oLg9NGWyTIVnD-Q85k6w,279
|
|
9
10
|
utg_base/authentications/__init__.py,sha256=a6twO_bBf8FAHYl7PXawfR2UbBwwdueG1uS_dbq2g_I,109
|
|
10
11
|
utg_base/authentications/microservice_authentication.py,sha256=6aAncxIpA4FcyRegd7QqRYvW5Wn8FxyPU0nQqCVuEs4,976
|
|
@@ -26,8 +27,9 @@ utg_base/celery/views/task_result.py,sha256=c9HIcohrToRfz1jfZRRZ1ri15FOasjKgMYnz
|
|
|
26
27
|
utg_base/constants/__init__.py,sha256=nC8qE-2V6APtjSz8j0A-3ez8yyoRpdRO8pwQnvvpRMk,53
|
|
27
28
|
utg_base/constants/available_languages.py,sha256=zQh0S0PMuYUdRW_RH36llvMxbvsfbdUtotDjFeysWfQ,56
|
|
28
29
|
utg_base/env.py,sha256=9jRWlaifSDmss6qU2FG2aP0SHP-gPSdk14rjohuXvfM,940
|
|
29
|
-
utg_base/logging.py,sha256=
|
|
30
|
+
utg_base/logging.py,sha256=JHGhuLKU1js_26ReE0LCLWZ66fmlGKuLG9sfbQSfI5w,4565
|
|
30
31
|
utg_base/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
+
utg_base/middleware/debug.py,sha256=exkeYUK-zSN3PMd4L9F6WlROmQ7Qlpmi_Gr2dqt5vk4,416
|
|
31
33
|
utg_base/middleware/locale.py,sha256=1hp_T_VuHCz0ITjwJ_F1rpf5kXQ0ulEmK1yoRWD1GRc,557
|
|
32
34
|
utg_base/models/__init__.py,sha256=1zXygGICiR3iUCKdkNal9d3i3kNp654gFgBf_VlR2gI,67
|
|
33
35
|
utg_base/models/jwt_user.py,sha256=6TQ5wB_OZBtGhRL-2MonBGZm0n0Y86s4BRTxiRlUJOk,375
|
|
@@ -47,7 +49,7 @@ utg_base/utils/date.py,sha256=thcbK6RgTUYZfs4_vW5ucuu2e8H0rei6tv7SEC72iwM,3612
|
|
|
47
49
|
utg_base/utils/dict_util.py,sha256=ipdCZO8aTukGQ319OWHb2Ij5MNtV-FioJQ4qCX3Th48,758
|
|
48
50
|
utg_base/utils/response_processors.py,sha256=WdZQL49wOJqCIY2MucAI6sez_llCqih0v_ltQa-mv7k,687
|
|
49
51
|
utg_base/utils/sql.py,sha256=rqIWcSjdjIMszdRnsnhV5TTYB8W17RPOujIQA9rKC_Y,762
|
|
50
|
-
utg_base/utils/translation.py,sha256=
|
|
51
|
-
utg_base-1.
|
|
52
|
-
utg_base-1.
|
|
53
|
-
utg_base-1.
|
|
52
|
+
utg_base/utils/translation.py,sha256=GxJHUt0iar_0E7RWBPbeLFQ4DhgXBjffHCmxfKyjFtk,463
|
|
53
|
+
utg_base-1.6.1.dist-info/METADATA,sha256=VFG9y4kzasChqU2btKkXSwCifVjnxEoaIFnIV9bAhlw,874
|
|
54
|
+
utg_base-1.6.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
55
|
+
utg_base-1.6.1.dist-info/RECORD,,
|
|
File without changes
|