mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
Refactor tag management for premium users
Refactor tag handling for key management to ensure only premium users can add tags. Adjust logic to manage tags in metadata appropriately.
This commit is contained in:
parent
f1795e6d44
commit
2292b6530c
1 changed files with 14 additions and 7 deletions
|
|
@ -1667,16 +1667,23 @@ async def _common_key_generation_helper(
|
|||
if "tags" in data_json:
|
||||
from litellm.proxy.proxy_server import premium_user
|
||||
|
||||
if premium_user is not True and data_json["tags"] is not None:
|
||||
raise ValueError(f"Only premium users can add tags to keys. {CommonProxyErrors.not_premium_user.value}")
|
||||
tags = data_json.get("tags")
|
||||
if premium_user is not True and isinstance(tags, list) and len(tags) > 0:
|
||||
raise ValueError(
|
||||
f"Only premium users can add tags to keys. {CommonProxyErrors.not_premium_user.value}"
|
||||
)
|
||||
|
||||
_metadata: Final = data_json.get("metadata")
|
||||
if not _metadata:
|
||||
data_json["metadata"] = {"tags": data_json["tags"]}
|
||||
if tags is None:
|
||||
if isinstance(_metadata, dict):
|
||||
_metadata.pop("tags", None)
|
||||
data_json.pop("tags", None)
|
||||
else:
|
||||
data_json["metadata"]["tags"] = data_json["tags"]
|
||||
|
||||
data_json.pop("tags")
|
||||
if not _metadata:
|
||||
data_json["metadata"] = {"tags": tags}
|
||||
else:
|
||||
data_json["metadata"]["tags"] = tags
|
||||
data_json.pop("tags")
|
||||
|
||||
# Validate MCP servers in object_permission are within team scope
|
||||
_is_proxy_admin_caller: Final = user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN.value
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue