fix for route checks

This commit is contained in:
Ishaan Jaff 2025-04-16 18:05:32 -07:00
parent 54aa100b47
commit cd4e923b42

View file

@ -23,21 +23,25 @@ class RouteChecks:
""" """
Raises Exception if Virtual Key is not allowed to call the route Raises Exception if Virtual Key is not allowed to call the route
""" """
if (
valid_token.allowed_routes
and isinstance(valid_token.allowed_routes, list)
and len(valid_token.allowed_routes) > 0
):
# explicit check for allowed routes
if route in valid_token.allowed_routes:
return True
# check if wildcard pattern is allowed # Only check if valid_token.allowed_routes is set and is a list with at least one item
for allowed_route in valid_token.allowed_routes: if valid_token.allowed_routes is None:
if RouteChecks._route_matches_wildcard_pattern( return True
route=route, pattern=allowed_route if not isinstance(valid_token.allowed_routes, list):
): return True
return True if len(valid_token.allowed_routes) == 0:
return True
# explicit check for allowed routes
if route in valid_token.allowed_routes:
return True
# check if wildcard pattern is allowed
for allowed_route in valid_token.allowed_routes:
if RouteChecks._route_matches_wildcard_pattern(
route=route, pattern=allowed_route
):
return True
raise Exception( raise Exception(
f"Virtual key is not allowed to call this route. Only allowed to call routes: {valid_token.allowed_routes}. Tried to call route: {route}" f"Virtual key is not allowed to call this route. Only allowed to call routes: {valid_token.allowed_routes}. Tried to call route: {route}"