mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
fix(proxy): extract request method helper to satisfy typing gates
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
c504ca954e
commit
5c2fc1c99d
2 changed files with 11 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from collections.abc import Mapping, Sequence
|
||||
from typing import Final, Literal
|
||||
|
||||
from fastapi import Request
|
||||
from pydantic import TypeAdapter
|
||||
from typing_extensions import ReadOnly, TypedDict, assert_never
|
||||
|
||||
|
|
@ -115,6 +116,14 @@ def stored_credentials_present() -> bool:
|
|||
return any((d.get("model_info") or {}).get("db_model") is True for d in deployments)
|
||||
|
||||
|
||||
def request_http_method(request: Request) -> str:
|
||||
try:
|
||||
method: Final = request.method
|
||||
except (KeyError, AttributeError):
|
||||
return ""
|
||||
return method if isinstance(method, str) else ""
|
||||
|
||||
|
||||
def master_key_lockout_action(
|
||||
route: str,
|
||||
method: str,
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ from litellm.proxy.auth.master_key_policy import (
|
|||
insecure_master_key_reason,
|
||||
master_key_lockout_action,
|
||||
master_key_lockout_exception,
|
||||
request_http_method,
|
||||
stored_credentials_present,
|
||||
)
|
||||
from litellm.proxy.auth.network import TrustedProxyConfig, resolve_network_context
|
||||
|
|
@ -1362,15 +1363,11 @@ async def _user_api_key_auth_builder(
|
|||
_lockout_reason: Final = insecure_master_key_reason(
|
||||
master_key, alternative_auth_enabled=alternative_auth_enabled(general_settings)
|
||||
)
|
||||
try:
|
||||
_request_method: Final = request.method
|
||||
except (KeyError, AttributeError):
|
||||
_request_method = ""
|
||||
if (
|
||||
_lockout_reason is not None
|
||||
and master_key_lockout_action(
|
||||
route=route,
|
||||
method=_request_method if isinstance(_request_method, str) else "",
|
||||
method=request_http_method(request),
|
||||
reason=_lockout_reason,
|
||||
stored_credentials_present=stored_credentials_present(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue