mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(keys): keep organization_id on archived key records and /key/info
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
9541b0734b
commit
3e8566d878
2 changed files with 20 additions and 0 deletions
|
|
@ -69,6 +69,7 @@ class LiteLLM_DeletedVerificationToken(LiteLLM_VerificationToken):
|
|||
"""Audit record for deleted keys; mirrors the token plus deletion metadata."""
|
||||
|
||||
id: str | None = None
|
||||
organization_id: str | None = None
|
||||
deleted_at: datetime | None = None
|
||||
deleted_by: str | None = None
|
||||
deleted_by_api_key: str | None = None
|
||||
|
|
|
|||
|
|
@ -4919,6 +4919,23 @@ def test_transform_verification_tokens_to_deleted_records():
|
|||
assert json.loads(record2["budget_fallbacks"]) == {"gpt-4": ["gpt-4o-mini"]}
|
||||
|
||||
|
||||
def test_transform_verification_tokens_to_deleted_records_keeps_organization_id():
|
||||
live_row = MagicMock()
|
||||
live_row.model_dump.return_value = {
|
||||
"token": "hashed-token-org",
|
||||
"user_id": "user-123",
|
||||
"team_id": None,
|
||||
"organization_id": "org-finops",
|
||||
}
|
||||
|
||||
records = _transform_verification_tokens_to_deleted_records(
|
||||
keys=[live_row],
|
||||
user_api_key_dict=UserAPIKeyAuth(user_id="admin-1", api_key="sk-admin"),
|
||||
)
|
||||
|
||||
assert records[0]["organization_id"] == "org-finops"
|
||||
|
||||
|
||||
def test_transform_verification_tokens_to_deleted_records_empty_list():
|
||||
user_api_key_dict = UserAPIKeyAuth(
|
||||
user_id="user-123",
|
||||
|
|
@ -6135,6 +6152,7 @@ def _archived_key_row(token: str, user_id: str) -> MagicMock:
|
|||
"key_alias": "finops-2024",
|
||||
"user_id": user_id,
|
||||
"team_id": None,
|
||||
"organization_id": "org-finops",
|
||||
"blocked": None,
|
||||
"deleted_at": datetime(2024, 11, 15, 10, 0, tzinfo=timezone.utc),
|
||||
"deleted_by": "admin-1",
|
||||
|
|
@ -6166,6 +6184,7 @@ async def test_info_key_fn_serves_deleted_key_from_archive(monkeypatch):
|
|||
info = result["info"]
|
||||
assert info["status"] == "deleted"
|
||||
assert info["key_alias"] == "finops-2024"
|
||||
assert info["organization_id"] == "org-finops"
|
||||
assert info["deleted_by"] == "admin-1"
|
||||
assert info["deleted_at"] is not None
|
||||
assert "token" not in info
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue