mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
(fix) proxy - clear cache after /key/delete
This commit is contained in:
parent
4d6ffe4400
commit
9852462d1f
1 changed files with 27 additions and 6 deletions
|
@ -527,7 +527,7 @@ async def user_api_key_auth(
|
|||
)
|
||||
|
||||
# Token passed all checks
|
||||
api_key = valid_token.token
|
||||
api_key = hash_token(valid_token.token)
|
||||
|
||||
# Add hashed token to cache
|
||||
user_api_key_cache.set_cache(key=api_key, value=valid_token, ttl=60)
|
||||
|
@ -1445,11 +1445,13 @@ async def generate_key_helper_fn(
|
|||
saved_token["expires"], datetime
|
||||
):
|
||||
saved_token["expires"] = saved_token["expires"].isoformat()
|
||||
user_api_key_cache.set_cache(
|
||||
key=key_data["token"],
|
||||
value=LiteLLM_VerificationToken(**saved_token), # type: ignore
|
||||
ttl=60,
|
||||
)
|
||||
if key_data["token"] is not None and isinstance(key_data["token"], str):
|
||||
hashed_token = hash_token(key_data["token"])
|
||||
user_api_key_cache.set_cache(
|
||||
key=hashed_token,
|
||||
value=LiteLLM_VerificationToken(**saved_token), # type: ignore
|
||||
ttl=60,
|
||||
)
|
||||
if prisma_client is not None:
|
||||
## CREATE USER (If necessary)
|
||||
verbose_proxy_logger.debug(f"prisma_client: Creating User={user_data}")
|
||||
|
@ -2665,13 +2667,32 @@ async def delete_key_fn(data: DeleteKeyRequest):
|
|||
HTTPException: If an error occurs during key deletion.
|
||||
"""
|
||||
try:
|
||||
global user_api_key_cache
|
||||
keys = data.keys
|
||||
if len(keys) == 0:
|
||||
raise ProxyException(
|
||||
message=f"No keys provided, passed in: keys={keys}",
|
||||
type="auth_error",
|
||||
param="keys",
|
||||
code=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
result = await delete_verification_token(tokens=keys)
|
||||
verbose_proxy_logger.debug("/key/delete - deleted_keys=", result)
|
||||
|
||||
number_deleted_keys = len(result["deleted_keys"])
|
||||
assert len(keys) == number_deleted_keys
|
||||
|
||||
for key in keys:
|
||||
user_api_key_cache.delete_cache(key)
|
||||
# remove hash token from cache
|
||||
hashed_token = hash_token(key)
|
||||
user_api_key_cache.delete_cache(hashed_token)
|
||||
|
||||
verbose_proxy_logger.debug(
|
||||
f"/keys/delete - cache after delete: {user_api_key_cache.in_memory_cache.cache_dict}"
|
||||
)
|
||||
|
||||
return {"deleted_keys": keys}
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPException):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue