Skip to content

Commit

Permalink
Merge pull request #1364 from DSD-DBS/pydantic-config-template
Browse files Browse the repository at this point in the history
feat: Convert config template to pydantic model
  • Loading branch information
MoritzWeber0 authored Mar 22, 2024
2 parents d6decd0 + 66728d2 commit ec23dae
Show file tree
Hide file tree
Showing 45 changed files with 694 additions and 708 deletions.
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)
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
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

0 comments on commit ec23dae

Please sign in to comment.