cowbird.config

Attributes

LOGGER

MULTI_TOKEN

BIDIRECTIONAL_ARROW

RIGHT_ARROW

LEFT_ARROW

PERMISSION_REGEX

PERMISSIONS_REGEX

DIRECTION_REGEX

MAPPING_REGEX

NAMED_TOKEN_REGEX

Exceptions

ConfigError

Generic error during configuration loading.

ConfigErrorInvalidTokens

Config error specific to invalid SINGLE_TOKEN or MULTI_TOKEN tokens.

ConfigErrorInvalidServiceKey

Config error for invalid service keys.

ConfigErrorInvalidResourceKey

Config error for invalid resource keys.

Functions

_load_config(→ cowbird.typedefs.ConfigDict)

Loads a file path or dictionary as YAML/JSON configuration.

get_all_configs(…)

Loads all configuration files specified by the path (if a directory), a single configuration (if a file) or directly

_expand_all(→ cowbird.typedefs.ConfigDict)

Applies environment variable expansion recursively to all applicable fields of a configuration definition.

validate_handlers_config_schema(→ None)

Validates the schema of the handlers section found in the config.

validate_sync_perm_config_schema(→ None)

Validates the schema of the sync_permissions section found in the config.

validate_and_get_resource_info(...)

Validates a resource_key and its related info from the config and returns some resource info relevant to the config

validate_bidirectional_mapping(→ None)

Validates if both resources of a bidirectional mapping respect validation rules.

validate_unidirectional_mapping(→ None)

Validates if both source and target resource of a unidirectional mapping respect validation rules.

get_mapping_info(→ Tuple[Union[str, Any], Ellipsis])

Obtain the different info found in a mapping string from the config.

get_permissions_from_str(→ List[str])

Returns a tuple of all permissions found in a string.

validate_sync_mapping_config(→ None)

Validates if mappings in the config have valid resource keys and use tokens properly.

validate_sync_config(→ None)

validate_sync_config_services(→ None)

Validates if all services used in the sync config are actual available services.

Module Contents

cowbird.config.LOGGER[source]
cowbird.config.MULTI_TOKEN = '**'[source]
cowbird.config.BIDIRECTIONAL_ARROW = '<->'[source]
cowbird.config.RIGHT_ARROW = '->'[source]
cowbird.config.LEFT_ARROW = '<-'[source]
cowbird.config.PERMISSION_REGEX = '[\\w-]+'[source]
cowbird.config.PERMISSIONS_REGEX[source]
cowbird.config.DIRECTION_REGEX[source]
cowbird.config.MAPPING_REGEX[source]
cowbird.config.NAMED_TOKEN_REGEX = '^\\{\\s*(\\w+)\\s*\\}$'[source]
exception cowbird.config.ConfigError[source]

Bases: RuntimeError

Generic error during configuration loading.

Initialize self. See help(type(self)) for accurate signature.

exception cowbird.config.ConfigErrorInvalidTokens[source]

Bases: ConfigError

Config error specific to invalid SINGLE_TOKEN or MULTI_TOKEN tokens.

Initialize self. See help(type(self)) for accurate signature.

exception cowbird.config.ConfigErrorInvalidServiceKey[source]

Bases: ConfigError

Config error for invalid service keys.

Initialize self. See help(type(self)) for accurate signature.

exception cowbird.config.ConfigErrorInvalidResourceKey[source]

Bases: ConfigError

Config error for invalid resource keys.

Initialize self. See help(type(self)) for accurate signature.

cowbird.config._load_config(path_or_dict: str | cowbird.typedefs.ConfigDict, section: str, allow_missing: bool = False) cowbird.typedefs.ConfigDict[source]

Loads a file path or dictionary as YAML/JSON configuration.

cowbird.config.get_all_configs(path_or_dict: str | cowbird.typedefs.ConfigDict, section: Literal['handlers'], allow_missing: bool = False) List[Dict[str, cowbird.typedefs.HandlerConfig]][source]
cowbird.config.get_all_configs(path_or_dict: str | cowbird.typedefs.ConfigDict, section: Literal['sync_permissions'], allow_missing: bool = False) List[cowbird.typedefs.SyncPointConfig]

Loads all configuration files specified by the path (if a directory), a single configuration (if a file) or directly returns the specified dictionary section (if a configuration dictionary).

Returns:

  • list of configurations loaded if input was a directory path

  • list of single configuration if input was a file path

  • list of single configuration if input was a JSON dict

  • empty list if none of the other cases where matched

Note

Order of file loading will be resolved by alphabetically sorted filename if specifying a directory path.

cowbird.config._expand_all(config: cowbird.typedefs.ConfigDict) cowbird.typedefs.ConfigDict[source]

Applies environment variable expansion recursively to all applicable fields of a configuration definition.

cowbird.config.validate_handlers_config_schema(handlers_cfg: Dict[str, cowbird.typedefs.HandlerConfig]) None[source]

Validates the schema of the handlers section found in the config.

cowbird.config.validate_sync_perm_config_schema(sync_cfg: cowbird.typedefs.SyncPointConfig) None[source]

Validates the schema of the sync_permissions section found in the config.

cowbird.config.validate_and_get_resource_info(res_key: str, segments: List[cowbird.typedefs.ConfigSegment]) cowbird.typedefs.ConfigResTokenInfo[source]

Validates a resource_key and its related info from the config and returns some resource info relevant to the config mapping validation.

Returned info contains the following: - if the resource uses a MULTI_TOKEN in its resource_path - the list of named tokens found in the resource_path

cowbird.config.validate_bidirectional_mapping(mapping: str, res_info: Dict[str, cowbird.typedefs.ConfigResTokenInfo], res_key1: str, res_key2: str) None[source]

Validates if both resources of a bidirectional mapping respect validation rules.

Both should either use MULTI_TOKEN or not use it and both should use exactly the same named tokens.

cowbird.config.validate_unidirectional_mapping(mapping: str, src_info: cowbird.typedefs.ConfigResTokenInfo, tgt_info: cowbird.typedefs.ConfigResTokenInfo) None[source]

Validates if both source and target resource of a unidirectional mapping respect validation rules.

Source resource should use MULTI_TOKEN if target uses it, and source resource should include all named tokens found in the target resource.

cowbird.config.get_mapping_info(mapping: str) Tuple[str | Any, Ellipsis][source]

Obtain the different info found in a mapping string from the config.

Returns the following matching groups : (res_key1, permission1, direction, res_key2, permission2)

cowbird.config.get_permissions_from_str(permissions: str) List[str][source]

Returns a tuple of all permissions found in a string.

Used for permission strings found in the config, which can either be a single permission or a list of permissions.

cowbird.config.validate_sync_mapping_config(sync_cfg: cowbird.typedefs.SyncPermissionConfig, res_info: Dict[str, cowbird.typedefs.ConfigResTokenInfo]) None[source]

Validates if mappings in the config have valid resource keys and use tokens properly.

cowbird.config.validate_sync_config(sync_cfg: cowbird.typedefs.SyncPermissionConfig) None[source]
cowbird.config.validate_sync_config_services(sync_cfg: cowbird.typedefs.SyncPermissionConfig, available_services: List[str]) None[source]

Validates if all services used in the sync config are actual available services.

All services should correspond to actual services available in Magpie.