mirror of
https://github.com/open-webui/open-webui.git
synced 2025-10-10 21:03:02 +02:00
enh: configurable api key endpoint restrictions
This commit is contained in:
@@ -96,11 +96,13 @@ def get_current_user(
|
||||
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
|
||||
)
|
||||
|
||||
allowed_paths = ["/api/models", "/api/chat/completions"]
|
||||
if request.url.path not in allowed_paths:
|
||||
raise HTTPException(
|
||||
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
|
||||
)
|
||||
if request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS:
|
||||
allowed_paths = str(request.app.state.API_KEY_ALLOWED_ENDPOINTS).split(",")
|
||||
|
||||
if request.url.path not in allowed_paths:
|
||||
raise HTTPException(
|
||||
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
|
||||
)
|
||||
|
||||
return get_current_user_by_api_key(token)
|
||||
|
||||
|
Reference in New Issue
Block a user