fix: add missing Credentials import and host-scoped credential check

- Import Credentials type from backend.data.model
- Add host-scoped credential matching to find_matching_credential
  (consistent with match_user_credentials_to_graph)
This commit is contained in:
Otto
2026-02-09 00:31:06 +00:00
parent 2067b969bc
commit 9da7efd17c

View File

@@ -8,6 +8,7 @@ from backend.api.features.library import model as library_model
from backend.api.features.store import db as store_db
from backend.data.graph import GraphModel
from backend.data.model import (
Credentials,
CredentialsFieldInfo,
CredentialsMetaInput,
HostScopedCredentials,
@@ -288,13 +289,15 @@ def find_matching_credential(
available_creds: list[Credentials],
field_info: CredentialsFieldInfo,
) -> Credentials | None:
"""Find a credential that matches the required provider, type, and scopes."""
"""Find a credential that matches the required provider, type, scopes, and host."""
for cred in available_creds:
if cred.provider not in field_info.provider:
continue
if cred.type not in field_info.supported_types:
continue
if not _credential_has_required_scopes(cred, field_info):
if cred.type == "oauth2" and not _credential_has_required_scopes(cred, field_info):
continue
if cred.type == "host_scoped" and not _credential_is_for_host(cred, field_info):
continue
return cred
return None