diff --git a/src/karapace/backup/cli.py b/src/karapace/backup/cli.py index 47c9290ec..cc01c5130 100644 --- a/src/karapace/backup/cli.py +++ b/src/karapace/backup/cli.py @@ -13,7 +13,9 @@ from aiokafka.errors import BrokerResponseError from collections.abc import Iterator from karapace.backup.api import VerifyLevel -from karapace.config import Config, read_env_file +from karapace.config import Config +from pydantic_settings import BaseSettings, JsonConfigSettingsSource, PydanticBaseSettingsSource +from typing import Type import argparse import contextlib @@ -90,7 +92,37 @@ def parse_args() -> argparse.Namespace: def get_config(args: argparse.Namespace) -> Config: - return read_env_file(args.config) + """Returns config for Backup tool + + Karapace uses environment variables, but Backup Tool still relies on the JSON + configuration file. + """ + + class BackupCLIConfig(Config): + @classmethod + def settings_customise_sources( + cls, + settings_cls: Type[BaseSettings], + init_settings: PydanticBaseSettingsSource, + env_settings: PydanticBaseSettingsSource, + dotenv_settings: PydanticBaseSettingsSource, + file_secret_settings: PydanticBaseSettingsSource, + ) -> tuple[ + JsonConfigSettingsSource, + PydanticBaseSettingsSource, + PydanticBaseSettingsSource, + PydanticBaseSettingsSource, + PydanticBaseSettingsSource, + ]: + return ( + JsonConfigSettingsSource(settings_cls=settings_cls, json_file=args.config), + init_settings, + env_settings, + dotenv_settings, + file_secret_settings, + ) + + return BackupCLIConfig() def dispatch(args: argparse.Namespace) -> None: diff --git a/tests/integration/backup/test_v3_backup.py b/tests/integration/backup/test_v3_backup.py index 0bf4b53cf..df689c5e0 100644 --- a/tests/integration/backup/test_v3_backup.py +++ b/tests/integration/backup/test_v3_backup.py @@ -66,10 +66,7 @@ def config_file_fixture( file_path = directory_path / "config.json" try: file_path.write_text( - f"""\ - BOOTSTRAP_URI={kafka_servers.bootstrap_servers[0]} - TOPIC_NAME={registry_cluster.schemas_topic} - """ + json.dumps({"bootstrap_uri": kafka_servers.bootstrap_servers[0], "topic_name": registry_cluster.schemas_topic}) ) yield file_path finally: