# Copyright 2025–2026 European Union
# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
# SPDX-License-Identifier: EUPL-1.2
"""
Standalone utility helpers for the Processor package.
This module provides validation helpers that are used across the processor
sub-package but do not belong to any specific class. Currently it contains
:func:`validate_database_conf`, which checks that a steering-file database
section carries the minimum required fields before a database connection
is attempted.
.. versionadded:: 2.3
Extracted from the monolithic ``processor.py`` module for improved
maintainability and focused testing.
"""
from __future__ import annotations
from typing import Any
[docs]
def validate_database_conf(database_conf: dict[str, Any] | None = None) -> dict[str, Any] | None:
"""
Validate the database configuration dictionary.
This function is called during processor initialisation to ensure that
the supplied database configuration contains the minimum required fields
(currently just ``URL``). If the configuration is a full steering file,
the ``DBConfiguration`` section is extracted automatically.
:param database_conf: The input database configuration. Defaults to None.
:type database_conf: dict, Optional
:return: Either the validated database configuration or None if it is invalid.
:rtype: dict, None
"""
if database_conf is None:
return None
# dict is mutable — work on a shallow copy to avoid side effects on the caller's data.
conf = database_conf.copy()
if 'DBConfiguration' in conf:
# The caller passed the entire steering file; extract just the DB section.
conf = conf['DBConfiguration']
# A valid database configuration must contain at least a connection URL.
required_fields = ['URL']
if all(field in conf for field in required_fields):
return database_conf
else:
return None