Files
kite/backend/storage/cloud_backend_factory.py
T
curo1305 ff33439f0a feat(12-02): normalize all four providers into CloudResourceAdapter contract
- GoogleDriveBackend: list_folder with full pagination, native doc size=None, get_capabilities
- OneDriveBackend: list_folder with @odata.nextLink pagination, get_capabilities
- WebDAVBackend: list_folder via PROPFIND with SSRF re-validation, get_capabilities
- NextcloudBackend: inherits CloudResourceAdapter from WebDAVBackend
- build_cloud_resource_adapter() added to factory
- 22 new contract/behavior/pagination/no-byte-download tests (51 total pass)
2026-06-18 22:45:09 +02:00

56 lines
1.9 KiB
Python

"""Factory for user-scoped cloud storage backends."""
from __future__ import annotations
from storage.cloud_base import CloudResourceAdapter
def build_cloud_backend(provider: str, credentials: dict):
if provider == "google_drive":
from storage.google_drive_backend import GoogleDriveBackend # lazy import
return GoogleDriveBackend(credentials)
if provider == "onedrive":
from storage.onedrive_backend import OneDriveBackend # lazy import
return OneDriveBackend(credentials)
if provider == "nextcloud":
from storage.nextcloud_backend import NextcloudBackend # lazy import
return NextcloudBackend(
credentials["server_url"],
credentials["username"],
credentials["password"],
)
if provider == "webdav":
from storage.webdav_backend import WebDAVBackend # lazy import
return WebDAVBackend(
credentials["server_url"],
credentials["username"],
credentials["password"],
)
raise ValueError(f"Unknown provider: {provider}")
def build_cloud_resource_adapter(provider: str, credentials: dict) -> CloudResourceAdapter:
"""Build a CloudResourceAdapter for the given provider and credentials.
Returns a provider instance that implements the CloudResourceAdapter read-only
interface (list_folder, get_capabilities, merge_item_capabilities). All four
supported providers implement CloudResourceAdapter as a mixin alongside
their StorageBackend interface.
Raises:
ValueError: If provider is not one of the four supported cloud providers.
"""
backend = build_cloud_backend(provider, credentials)
if not isinstance(backend, CloudResourceAdapter):
raise ValueError(
f"Provider {provider!r} backend does not implement CloudResourceAdapter"
)
return backend