Skip to content

InfDBConfig Class

Read and resolve tool-specific YAML config with optional InfDB base merge.

__init__(tool_name: str, config_path: str, host: str = None) -> None

Initializes the configuration for a tool.

Parameters:

Name Type Description Default
tool_name str

The tool identifier (used to select the YAML file and section).

required
config_path str

Path to the configuration file.

required
host str

The host address for the database connection.

None

__str__() -> str

Returns a string representation of the InfdbConfig.

get_config() -> Dict[str, Any]

Returns the fully merged and resolved configuration dictionary.

get_value(keys: List[str]) -> Any

Safely traverses nested keys; returns None if the path is missing.

Parameters:

Name Type Description Default
keys List[str]

Ordered key path within the configuration.

required

Returns:

Type Description
Any

The value at the specified path, or None if any segment is missing.

Raises:

Type Description
ValueError

If keys is empty.

get_path(keys: List[str], type: str) -> str

Resolves a path from config and maps it to a filesystem location.

Parameters:

Name Type Description Default
keys List[str]

Ordered key path within the configuration.

required
type str

One of {'loader', 'heat', 'package', 'setup'} controlling base dir.

required

Returns:

Type Description
str

Absolute filesystem path derived from the config value.

get_root_path() -> str staticmethod

Returns the project root path (two levels up from this file).

get_db_parameters(db_name: str = 'postgres') -> Dict[str, str]

Retrieve database connection parameters for a specified service.

Reads database configuration from the config-choose-a-name.yml file and merges it with environment variables. Environment variables take precedence if set, otherwise config file values are used. The host defaults to "host.docker.internal" if not specified.

Environment variables are expected in the format: SERVICES_{DB_NAME}_{PARAMETER} (e.g., SERVICES_POSTGRES_PORT, SERVICES_POSTGRES_USER)

db_name: Name of the database service section in the config file.
        Defaults to "postgres".

Dictionary containing database connection parameters with keys:
- host: Database host address (defaults to "host.docker.internal")
- port: Database port number
- user: Username for authentication
- password: Password for authentication
- dbname: Database name
- epsg: EPSG code for the database spatial reference system
Note
  • Config file values with "None" string are ignored in favor of environment variables
  • If neither environment variable nor config file value exists, key will be None

get_env_parameters(key) -> Optional[str]

Returns a dictionary of environment variables for this tool.

Parameters:

Name Type Description Default
key

Environment variable name (case-insensitive).

required
infdb

An InfDB object used for logging.

required

Returns:

Type Description
Optional[str]

A dictionary of environment variables.

Raises:

Type Description
ValueError

If the environment variable key.upper() is not set.