from __future__ import annotations from ingestion.common.gcp import list_objects as _gcs_list from ingestion.common.sql import sql_string from .config import LoadConfig class GcsStorage: """StorageAdapter for the shared external loader: lists GCS objects and builds the Databend gcs:// external stage. Databend addresses GCS with the ``gcs://`` scheme (not Google's ``gs://``) and authenticates with a base64 service-account key.""" def __init__(self, config: LoadConfig) -> None: self._config = config def list_objects(self, uri: str) -> list[dict]: return _gcs_list(uri) def create_stage_sql(self, stage_name: str, uri: str) -> str: databend_uri = "gcs://" + uri.removeprefix("gs://") return ( f"CREATE OR REPLACE STAGE {stage_name} " f"URL = {sql_string(databend_uri)} " f"CONNECTION = (CREDENTIAL = {sql_string(self._config.gcs_credential)})" ) def credential_env_names(self) -> list[str]: return self._config.gcs_credential_env_names