Skip to content

Commit

Permalink
Merge pull request #1025 from Aiven-Open/jjaakola-aiven-revert-backup…
Browse files Browse the repository at this point in the history
…-tool-config-to-json-file

fix: backup tool shall still use the JSON config file
  • Loading branch information
nosahama authored Jan 21, 2025
2 parents 469458c + 117ea08 commit 0b76ba6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
36 changes: 34 additions & 2 deletions src/karapace/backup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/backup/test_v3_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0b76ba6

Please sign in to comment.