Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Convert config template to pydantic model #1364

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

.idea
config/*
!config/config_template.yaml
.history
**/__pycache__/
.vscode
Expand Down
5 changes: 0 additions & 5 deletions backend/capellacollab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@

from importlib import metadata

from capellacollab import config as config_module

try:
__version__ = metadata.version("capellacollab-backend")
except metadata.PackageNotFoundError:
__version__ = "0.0.0+unknown"
del metadata


config_module.validate_schema()
6 changes: 3 additions & 3 deletions backend/capellacollab/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@
stream_handler.setFormatter(core_logging.CustomFormatter())

timed_rotating_file_handler = core_logging.CustomTimedRotatingFileHandler(
str(config["logging"]["logPath"]) + "backend.log"
str(config.logging.log_path) + "backend.log"
)
timed_rotating_file_handler.setFormatter(
core_logging.CustomFormatter(colored_output=False)
)

logging.basicConfig(
level=config["logging"]["level"],
level=config.logging.level,
handlers=[stream_handler, timed_rotating_file_handler],
)


async def startup():
migration.migrate_db(engine, config["database"]["url"])
migration.migrate_db(engine, config.database.url)

Check warning on line 68 in backend/capellacollab/__main__.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/__main__.py#L68

Added line #L68 was not covered by tests
logging.info("Migrations done - Server is running")

# This is needed to load the Kubernetes configuration at startup
Expand Down
4 changes: 2 additions & 2 deletions backend/capellacollab/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# access to the values within the .ini file in use.
config = context.config

logging.basicConfig(level=cfg["logging"]["level"])
logging.basicConfig(level=cfg.logging.level)
if os.getenv("ALEMBIC_CONFIGURE_LOGGER", "true") != "false":
logging.getLogger("capellacollab").setLevel("WARNING")

Expand All @@ -25,7 +25,7 @@
# this will overwrite the ini-file sqlalchemy.url path
# with the path given in the config of the main code
if not config.get_main_option("sqlalchemy.url"):
config.set_main_option("sqlalchemy.url", cfg["database"]["url"])
config.set_main_option("sqlalchemy.url", cfg.database.url)

# Import models

Expand Down
21 changes: 4 additions & 17 deletions backend/capellacollab/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

from . import generate, loader, models

import logging
if not loader.does_config_exist():
generate.write_config()

import jsonschema
MoritzWeber0 marked this conversation as resolved.
Show resolved Hide resolved
import jsonschema.exceptions

from . import exceptions, loader

log = logging.getLogger(__name__)
config = loader.load_yaml()


def validate_schema():
config_schema = loader.load_config_schema()
try:
jsonschema.validate(config, config_schema)
except jsonschema.exceptions.ValidationError as error:
raise exceptions.InvalidConfigurationError(
f"{error.__class__.__name__}: {error.message}",
) from None
config = models.AppConfig(**loader.load_yaml())
304 changes: 0 additions & 304 deletions backend/capellacollab/config/config_schema.yaml

This file was deleted.

Loading
Loading