dify/api/services/rag_pipeline/rag_pipeline_manage_service.py
ccl125 d5a8ace1c4
fix(rag-pipeline): mark credential-free datasources as authorized (#39772)
Co-authored-by: ccl125 <ccl125@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: FFXN <31929997+FFXN@users.noreply.github.com>
2026-08-26 05:44:10 +00:00

48 lines
1.8 KiB
Python

import logging
from core.plugin.entities.plugin_daemon import PluginDatasourceProviderEntity
from core.plugin.impl.datasource import PluginDatasourceManager
from services.datasource_provider_service import DatasourceProviderService
logger = logging.getLogger(__name__)
class RagPipelineManageService:
@staticmethod
def list_rag_pipeline_datasources(
tenant_id: str,
) -> list[PluginDatasourceProviderEntity]:
"""
list rag pipeline datasources
"""
# get all builtin providers
manager = PluginDatasourceManager()
datasources = manager.fetch_datasource_providers(tenant_id)
for datasource in datasources:
if not datasource.declaration.credentials_schema and not datasource.declaration.oauth_schema:
# built-in providers that declare neither credentials nor OAuth never require authorization
datasource.is_authorized = True
continue
datasource_provider_service = DatasourceProviderService()
try:
credentials = datasource_provider_service.get_datasource_credentials(
tenant_id=tenant_id,
provider=datasource.provider,
plugin_id=datasource.plugin_id,
)
if credentials:
datasource.is_authorized = True
except Exception:
logger.exception(
"Skipping datasource credentials for provider %s after refresh or decrypt failure",
datasource.provider,
extra={
"tenant_id": tenant_id,
"plugin_id": datasource.plugin_id,
"provider": datasource.provider,
},
)
return datasources