apitally 0.7.0__py3-none-any.whl → 0.7.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.
- apitally/__init__.py +1 -1
- apitally/django.py +30 -5
- {apitally-0.7.0.dist-info → apitally-0.7.1.dist-info}/METADATA +1 -1
- {apitally-0.7.0.dist-info → apitally-0.7.1.dist-info}/RECORD +6 -6
- {apitally-0.7.0.dist-info → apitally-0.7.1.dist-info}/LICENSE +0 -0
- {apitally-0.7.0.dist-info → apitally-0.7.1.dist-info}/WHEEL +0 -0
apitally/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.7.
|
1
|
+
__version__ = "0.7.1"
|
apitally/django.py
CHANGED
@@ -40,18 +40,25 @@ class ApitallyMiddleware:
|
|
40
40
|
|
41
41
|
def __init__(self, get_response: Callable[[HttpRequest], HttpResponse]) -> None:
|
42
42
|
self.get_response = get_response
|
43
|
-
self.
|
43
|
+
self.drf_available = _check_import("rest_framework")
|
44
44
|
self.drf_endpoint_enumerator = None
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
self.drf_endpoint_enumerator = EndpointEnumerator()
|
45
|
+
self.ninja_available = _check_import("ninja")
|
46
|
+
self.callbacks = set()
|
49
47
|
|
50
48
|
if self.config is None:
|
51
49
|
config = getattr(settings, "APITALLY_MIDDLEWARE", {})
|
52
50
|
self.configure(**config)
|
53
51
|
assert self.config is not None
|
54
52
|
|
53
|
+
if self.drf_available:
|
54
|
+
from rest_framework.schemas.generators import EndpointEnumerator
|
55
|
+
|
56
|
+
self.drf_endpoint_enumerator = EndpointEnumerator()
|
57
|
+
if None not in self.config.urlconfs:
|
58
|
+
self.callbacks.update(_get_drf_callbacks(self.config.urlconfs))
|
59
|
+
if self.ninja_available and None not in self.config.urlconfs:
|
60
|
+
self.callbacks.update(_get_ninja_callbacks(self.config.urlconfs))
|
61
|
+
|
55
62
|
self.client = ApitallyClient(client_id=self.config.client_id, env=self.config.env)
|
56
63
|
self.client.start_sync_loop()
|
57
64
|
self.client.set_app_info(
|
@@ -124,6 +131,8 @@ class ApitallyMiddleware:
|
|
124
131
|
def get_path(self, request: HttpRequest) -> Optional[str]:
|
125
132
|
if (match := request.resolver_match) is not None:
|
126
133
|
try:
|
134
|
+
if self.callbacks and match.func not in self.callbacks:
|
135
|
+
return None
|
127
136
|
if self.drf_endpoint_enumerator is not None:
|
128
137
|
from rest_framework.schemas.generators import is_api_view
|
129
138
|
|
@@ -206,6 +215,13 @@ def _get_drf_paths(urlconfs: List[Optional[str]]) -> List[Dict[str, str]]:
|
|
206
215
|
]
|
207
216
|
|
208
217
|
|
218
|
+
def _get_drf_callbacks(urlconfs: List[Optional[str]]) -> Set[Callable]:
|
219
|
+
from rest_framework.schemas.generators import EndpointEnumerator
|
220
|
+
|
221
|
+
enumerators = [EndpointEnumerator(urlconf=urlconf) for urlconf in urlconfs]
|
222
|
+
return {callback for enumerator in enumerators for _, _, callback in enumerator.get_api_endpoints()}
|
223
|
+
|
224
|
+
|
209
225
|
def _get_drf_schema(urlconfs: List[Optional[str]]) -> Optional[Dict[str, Any]]:
|
210
226
|
from rest_framework.schemas.openapi import SchemaGenerator
|
211
227
|
|
@@ -237,6 +253,15 @@ def _get_ninja_paths(urlconfs: List[Optional[str]]) -> List[Dict[str, str]]:
|
|
237
253
|
return endpoints
|
238
254
|
|
239
255
|
|
256
|
+
def _get_ninja_callbacks(urlconfs: List[Optional[str]]) -> Set[Callable]:
|
257
|
+
return {
|
258
|
+
path_view.get_view()
|
259
|
+
for api in _get_ninja_api_instances(urlconfs=urlconfs)
|
260
|
+
for _, router in api._routers
|
261
|
+
for path_view in router.path_operations.values()
|
262
|
+
}
|
263
|
+
|
264
|
+
|
240
265
|
def _get_ninja_schema(urlconfs: List[Optional[str]]) -> Optional[Dict[str, Any]]:
|
241
266
|
schemas = []
|
242
267
|
for api in _get_ninja_api_instances(urlconfs=urlconfs):
|
@@ -1,11 +1,11 @@
|
|
1
|
-
apitally/__init__.py,sha256=
|
1
|
+
apitally/__init__.py,sha256=2KJZDSMOG7KS82AxYOrZ4ZihYxX0wjfUjDsIZh3L024,22
|
2
2
|
apitally/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
apitally/client/asyncio.py,sha256=uR5JlH37G6gZvAJ7A1gYOGkjn3zjC-4I6avA1fncXHs,4433
|
4
4
|
apitally/client/base.py,sha256=E_yUTItAtZWPOx80K3Pm55CNBgF_NZ6RMyXZTnjSV9c,8511
|
5
5
|
apitally/client/logging.py,sha256=QMsKIIAFo92PNBUleeTgsrsQa7SEal-oJa1oOHUr1wI,507
|
6
6
|
apitally/client/threading.py,sha256=ihQzUStrSQFynpqXgFpseAXrHuc5Et1QvG-YHlzqDr8,4831
|
7
7
|
apitally/common.py,sha256=GbVmnXxhRvV30d7CfCQ9r0AeXj14Mv9Jm_Yd1bRWP28,1088
|
8
|
-
apitally/django.py,sha256=
|
8
|
+
apitally/django.py,sha256=SHSM00eRsvoJC2d4c4tK6gctKLnxLfrw4LoZ4CWPm4U,12124
|
9
9
|
apitally/django_ninja.py,sha256=iMvZd7j04nbOLpJgYxs7tpbsyXlZuhmHjcswXMvyUlU,82
|
10
10
|
apitally/django_rest_framework.py,sha256=iMvZd7j04nbOLpJgYxs7tpbsyXlZuhmHjcswXMvyUlU,82
|
11
11
|
apitally/fastapi.py,sha256=Q3n2bVREKQ_V_2yCQ48ngPtr-NJxDskpT_l20xhSbpM,85
|
@@ -13,7 +13,7 @@ apitally/flask.py,sha256=xxyrHchMiPuEMP3c_Us_niJn9K7x87RDvxD5GtntEvU,4769
|
|
13
13
|
apitally/litestar.py,sha256=Pl1tEbxve3vqrdflWdvZjPFrEVxNIr6NjuQVf4YSpzY,7171
|
14
14
|
apitally/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
apitally/starlette.py,sha256=9VKGdNuKPrRcnQv7GeyV5cLa7TpgidxMVnAKSxMsWjI,7345
|
16
|
-
apitally-0.7.
|
17
|
-
apitally-0.7.
|
18
|
-
apitally-0.7.
|
19
|
-
apitally-0.7.
|
16
|
+
apitally-0.7.1.dist-info/LICENSE,sha256=vbLzC-4TddtXX-_AFEBKMYWRlxC_MN0g66QhPxo8PgY,1065
|
17
|
+
apitally-0.7.1.dist-info/METADATA,sha256=SO16kB-1EwZGAm28P4m4E2EMltFfmKUy4uF44X4LB30,6736
|
18
|
+
apitally-0.7.1.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
19
|
+
apitally-0.7.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|