devops.config.base

Base configuration utilities.

Functions

get_bool(mapping, key, *[, default])

Get a boolean value from a mapping.

get_str(mapping, key[, default])

Get a string value from a mapping.

get_str_enum(mapping, key, enum_type[, default])

Get a string enum value from a mapping.

get_str_list(mapping, key[, default])

Get a list of strings from a mapping.

get_str_or_str_list(mapping, key[, default])

Get a string or list of strings from a mapping.

get_table(mapping, key)

Get a sub-table from a mapping.

Exceptions

ConfigError(message)

Custom exception for configuration-related errors.

exception devops.config.base.ConfigError(message)[source]

Bases: Exception

Custom exception for configuration-related errors.

Parameters:

message (str)

Return type:

None

devops.config.base.get_table(mapping, key)[source]

Get a sub-table from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the sub-table from.

  • key (str) – The key of the sub-table.

Returns:

dict[str, Any] – The extracted sub-table or an empty dictionary if the key is not found.

Raises:

ConfigError – If the value associated with the key is not a dictionary.

Return type:

dict[str, Any]

devops.config.base.get_bool(mapping, key, *, default=None)[source]

Get a boolean value from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the boolean from.

  • key (str) – The key of the boolean.

  • default (bool | None) – The default value to return if the key is not found.

Returns:

bool | None – The extracted boolean value or None if the key is not found.

Return type:

bool | None

devops.config.base.get_str(mapping, key, default=None)[source]

Get a string value from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the string from.

  • key (str) – The key of the string.

  • default (str | None) – The default value to return if the key is not found.

Returns:

str | None – The extracted string value or None if the key is not found.

Return type:

str | None

devops.config.base.get_str_or_str_list(mapping, key, default=None)[source]

Get a string or list of strings from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the value from.

  • key (str) – The key of the value.

  • default (str | list[str] | None) – The default value to return if the key is not found.

Returns:

str | list[str] | None – The extracted string or list of strings value or None if the key is not found.

Return type:

str | list[str] | None

devops.config.base.get_str_enum(mapping, key, enum_type, default=None)[source]

Get a string enum value from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the enum value from.

  • key (str) – The key of the enum value.

  • enum_type (type) – The enum type to validate against.

  • default (str) – The default value to return if the key is not found.

Returns:

StrEnum | None – The extracted enum value or None if the key is not found.

Raises:

ConfigError – If the value associated with the key is not a valid enum value.

Return type:

StrEnum | None

devops.config.base.get_str_list(mapping, key, default=None)[source]

Get a list of strings from a mapping.

Parameters:
  • mapping (dict[str, Any]) – The mapping to extract the list from.

  • key (str) – The key of the list.

  • default (list[str] | None) – The default value to return if the key is not found. Defaults to None.

Returns:

list[str] – The extracted list of strings or an empty list if the key is not found.

Raises:

ConfigError – If the value associated with the key is not a list of strings.

Return type:

list[str]