tracktolib 0.46.0__py3-none-any.whl → 0.46.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.
tracktolib/api.py CHANGED
@@ -24,6 +24,7 @@ from .utils import json_serial
24
24
 
25
25
  try:
26
26
  from fastapi import params, APIRouter
27
+ from fastapi.routing import APIRoute
27
28
  from fastapi.responses import JSONResponse
28
29
  from pydantic.alias_generators import to_camel
29
30
  from pydantic import BaseModel, ConfigDict
@@ -219,6 +220,42 @@ def set_ignore_config(config: str | IgnoreConfig):
219
220
  os.environ["IGNORE_CONFIG"] = config.model_dump_json()
220
221
 
221
222
 
223
+ def _filter_route(route: APIRoute, ignored_route: dict[Method, bool], ignore_missing: bool) -> APIRoute | None:
224
+ # If no config is provided and default is to ignore missing, return the route
225
+ if ignored_route is None and not ignore_missing:
226
+ return route
227
+
228
+ has_methods = False
229
+ enabled_methods = {method for method, has_access in ignored_route.items() if has_access}
230
+ for method in list(route.methods):
231
+ # If the config is not specified, we remove the method if ignore_missing is True
232
+ if method not in ignored_route:
233
+ if ignore_missing:
234
+ route.methods -= {method}
235
+ continue
236
+ else:
237
+ has_methods = True
238
+ continue
239
+ elif method not in enabled_methods:
240
+ route.methods -= {method}
241
+ else:
242
+ has_methods = True
243
+
244
+ if not has_methods:
245
+ return None
246
+ return route
247
+
248
+
249
+ def filter_routes(routes: list[APIRoute], ignore_config: IgnoreConfig) -> list[APIRoute]:
250
+ _routes = []
251
+ for route in routes:
252
+ _ignored_route = ignore_config.endpoints.get(route.path)
253
+ _route = _filter_route(route, _ignored_route or {}, ignore_missing=ignore_config.ignore_missing)
254
+ if _route is not None:
255
+ _routes.append(_route)
256
+ return _routes
257
+
258
+
222
259
  def _get_return_type(fn):
223
260
  return_type = get_type_hints(fn)["return"]
224
261
  _args = get_args(return_type)
@@ -236,12 +273,6 @@ def add_endpoint(
236
273
  ):
237
274
  _ignore_config = get_ignore_config()
238
275
  for _method, _meta in endpoint.methods.items():
239
- # Do not add endpoint if it is not in the ignore config
240
- if _ignore_config is not None:
241
- _has_access = _ignore_config.endpoints.get(path, {}).get(_method, not _ignore_config.ignore_missing)
242
- if not _has_access:
243
- continue
244
- #
245
276
  _fn = _meta["fn"]
246
277
  _status_code = _meta["status_code"]
247
278
  _dependencies = _meta["dependencies"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tracktolib
3
- Version: 0.46.0
3
+ Version: 0.46.1
4
4
  Summary: Utility library for python
5
5
  Home-page: https://github.com/tracktor/tracktolib
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
2
2
  tracktolib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- tracktolib/api.py,sha256=uimcKHZMme9Z8zdtedfyeUlKC5j5vgwJRwePzr2mzfk,8758
3
+ tracktolib/api.py,sha256=DILKtPQn6HRXmQk5FgYHA9o5ToSNGudHsMEF_ZXEuI8,9826
4
4
  tracktolib/http_utils.py,sha256=dqjRJTNCo1qDnvQBTcImw1ibi1LnqETrpWDAU5txBHs,2633
5
5
  tracktolib/logs.py,sha256=enezPjBU4v2s8knG_V6kIbQsoyxfNIKEpKVSSkr_2U8,2212
6
6
  tracktolib/pg/__init__.py,sha256=32kKBJzIDyppszZMAOSMgM3ggz7Ow0TaNKiMs740gyw,333
@@ -13,7 +13,7 @@ tracktolib/s3/minio.py,sha256=JaRpHOM6NqpMieplp58Fpc7uTh7PItyP8On7jMXhB-Q,1234
13
13
  tracktolib/s3/s3.py,sha256=0aPUo3Vnfy5Rk_Qp_y0KkCZa2kuMWw2JU2xrodn7oAE,3486
14
14
  tracktolib/tests.py,sha256=FS0uae3ShiiJOD7WE2WEv9h3QwRJCbLDHpe_8Ikc0j0,554
15
15
  tracktolib/utils.py,sha256=YZZROGgOioblJkqgneHGZRbof45nmZ-VLSk9LqcVkkE,4847
16
- tracktolib-0.46.0.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
17
- tracktolib-0.46.0.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
18
- tracktolib-0.46.0.dist-info/METADATA,sha256=Hw3poZoXh73R83sL2yXKJLcf9ZkjJtibzWtWayvpCEo,3610
19
- tracktolib-0.46.0.dist-info/RECORD,,
16
+ tracktolib-0.46.1.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
17
+ tracktolib-0.46.1.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
18
+ tracktolib-0.46.1.dist-info/METADATA,sha256=wi_XoRBTxEhgO2DvDPf1h_cf4XL8mcd0JP4i76_lHu0,3610
19
+ tracktolib-0.46.1.dist-info/RECORD,,