forked from phoenix/litellm-mirror
(feat) /key/info without using key in query param
This commit is contained in:
parent
0988a4694c
commit
ec3f497db8
1 changed files with 10 additions and 2 deletions
|
@ -522,7 +522,10 @@ async def user_api_key_auth(
|
||||||
# check if user can access this route
|
# check if user can access this route
|
||||||
query_params = request.query_params
|
query_params = request.query_params
|
||||||
key = query_params.get("key")
|
key = query_params.get("key")
|
||||||
if prisma_client.hash_token(token=key) != api_key:
|
if (
|
||||||
|
key is not None
|
||||||
|
and prisma_client.hash_token(token=key) != api_key
|
||||||
|
):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
detail="user not allowed to access this key's info",
|
detail="user not allowed to access this key's info",
|
||||||
|
@ -2496,7 +2499,10 @@ async def delete_key_fn(data: DeleteKeyRequest):
|
||||||
"/key/info", tags=["key management"], dependencies=[Depends(user_api_key_auth)]
|
"/key/info", tags=["key management"], dependencies=[Depends(user_api_key_auth)]
|
||||||
)
|
)
|
||||||
async def info_key_fn(
|
async def info_key_fn(
|
||||||
key: str = fastapi.Query(..., description="Key in the request parameters"),
|
key: Optional[str] = fastapi.Query(
|
||||||
|
default=None, description="Key in the request parameters"
|
||||||
|
),
|
||||||
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
):
|
):
|
||||||
global prisma_client
|
global prisma_client
|
||||||
try:
|
try:
|
||||||
|
@ -2504,6 +2510,8 @@ async def info_key_fn(
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys"
|
f"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys"
|
||||||
)
|
)
|
||||||
|
if key == None:
|
||||||
|
key = user_api_key_dict.api_key
|
||||||
key_info = await prisma_client.get_data(token=key)
|
key_info = await prisma_client.get_data(token=key)
|
||||||
## REMOVE HASHED TOKEN INFO BEFORE RETURNING ##
|
## REMOVE HASHED TOKEN INFO BEFORE RETURNING ##
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue