diff --git a/litellm/llms/github_copilot/per_user_auth.py b/litellm/llms/github_copilot/per_user_auth.py index 10e5e12dec3..3dc8c12fe06 100644 --- a/litellm/llms/github_copilot/per_user_auth.py +++ b/litellm/llms/github_copilot/per_user_auth.py @@ -328,7 +328,7 @@ def _new_async_github_client() -> _AsyncGitHubClient: return cast( # cast-ok: pins the untyped litellm client factory to the local Protocol Callable[[str], _AsyncGitHubClient], - getattr(http_handler, "get_async_httpx_client"), # noqa: B009 # untyped factory + http_handler.get_async_httpx_client, )(_LLM_PROVIDER) @@ -548,13 +548,7 @@ def github_copilot_auth_mode(litellm_credential_name: object, auth_type_value: o credential: Final = CredentialAccessor.find_credential(litellm_credential_name) if credential is not None: - values: Final[object] = getattr(credential, "credential_values", None) - return isinstance(values, Mapping) and ( - cast( # cast-ok: value is Mapping-checked or dict-shaped at runtime - Mapping[object, object], values - ).get(GITHUB_COPILOT_AUTH_TYPE_KEY) - == GITHUB_COPILOT_PER_USER_AUTH_TYPE - ) + return credential.credential_values.get(GITHUB_COPILOT_AUTH_TYPE_KEY) == GITHUB_COPILOT_PER_USER_AUTH_TYPE return auth_type_value == GITHUB_COPILOT_PER_USER_AUTH_TYPE if auth_type_value == GITHUB_COPILOT_PER_USER_AUTH_TYPE: raise BadRequestError( diff --git a/litellm/proxy/credential_endpoints/endpoints.py b/litellm/proxy/credential_endpoints/endpoints.py index 1584b12fd68..f51d71a4c20 100644 --- a/litellm/proxy/credential_endpoints/endpoints.py +++ b/litellm/proxy/credential_endpoints/endpoints.py @@ -5,7 +5,6 @@ CRUD endpoints for storing reusable credentials. import time import unicodedata from collections.abc import Mapping -from datetime import datetime from typing import ( Annotated, Final, @@ -563,17 +562,12 @@ async def list_user_connections( detail={"error": CommonProxyErrors.db_not_connected_error.value}, ) rows: Final = await list_user_provider_credentials(prisma_client, user_id) - github_logins: Final[dict[str, str]] = {} # mutable-ok: accumulates one entry per credential row - connected_at: Final[dict[str, str]] = {} # mutable-ok: accumulates one entry per credential row - for row in rows: - if row.provider != _GITHUB_COPILOT_PROVIDER: - continue - payload = decode_user_provider_credential(row.credential_b64) - if payload is not None: - github_logins[row.credential_name] = payload.github_login - updated = getattr(row, "updated_at", None) - if isinstance(updated, datetime): - connected_at[row.credential_name] = updated.isoformat() + copilot_rows: Final = tuple(row for row in rows if row.provider == _GITHUB_COPILOT_PROVIDER) + payloads: Final = { + row.credential_name: decode_user_provider_credential(row.credential_b64) for row in copilot_rows + } + github_logins: Final = {name: payload.github_login for name, payload in payloads.items() if payload is not None} + connected_at: Final = {row.credential_name: row.updated_at.isoformat() for row in copilot_rows} return UserProviderConnectionsResponse( connections=[ UserProviderConnection( diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index fdc2e6d94b8..2f7f15fcca2 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -2728,11 +2728,7 @@ def _per_user_oauth_configured() -> bool: ) return any( - isinstance(values := getattr(credential, "credential_values", None), Mapping) - and cast("Mapping[object, object]", values).get( # cast-ok: credential_values is a plain dict at runtime - GITHUB_COPILOT_AUTH_TYPE_KEY - ) - == GITHUB_COPILOT_PER_USER_AUTH_TYPE + credential.credential_values.get(GITHUB_COPILOT_AUTH_TYPE_KEY) == GITHUB_COPILOT_PER_USER_AUTH_TYPE for credential in (litellm.credential_list or ()) ) @@ -2749,12 +2745,8 @@ def _all_per_user_credential_names() -> tuple[str, ...]: return tuple( credential.credential_name for credential in (litellm.credential_list or ()) - if getattr(credential, "credential_name", None) - and isinstance(values := getattr(credential, "credential_values", None), Mapping) - and cast("Mapping[object, object]", values).get( # cast-ok: credential_values is a plain dict at runtime - GITHUB_COPILOT_AUTH_TYPE_KEY - ) - == GITHUB_COPILOT_PER_USER_AUTH_TYPE + if credential.credential_name + and credential.credential_values.get(GITHUB_COPILOT_AUTH_TYPE_KEY) == GITHUB_COPILOT_PER_USER_AUTH_TYPE )