cowbird.config ============== .. py:module:: cowbird.config Attributes ---------- .. autoapisummary:: cowbird.config.LOGGER cowbird.config.MULTI_TOKEN cowbird.config.BIDIRECTIONAL_ARROW cowbird.config.RIGHT_ARROW cowbird.config.LEFT_ARROW cowbird.config.PERMISSION_REGEX cowbird.config.PERMISSIONS_REGEX cowbird.config.DIRECTION_REGEX cowbird.config.MAPPING_REGEX cowbird.config.NAMED_TOKEN_REGEX Exceptions ---------- .. autoapisummary:: cowbird.config.ConfigError cowbird.config.ConfigErrorInvalidTokens cowbird.config.ConfigErrorInvalidServiceKey cowbird.config.ConfigErrorInvalidResourceKey Functions --------- .. autoapisummary:: cowbird.config._load_config cowbird.config.get_all_configs cowbird.config._expand_all cowbird.config.validate_handlers_config_schema cowbird.config.validate_sync_perm_config_schema cowbird.config.validate_and_get_resource_info cowbird.config.validate_bidirectional_mapping cowbird.config.validate_unidirectional_mapping cowbird.config.get_mapping_info cowbird.config.get_permissions_from_str cowbird.config.validate_sync_mapping_config cowbird.config.validate_sync_config cowbird.config.validate_sync_config_services Module Contents --------------- .. py:data:: LOGGER .. py:data:: MULTI_TOKEN :value: '**' .. py:data:: BIDIRECTIONAL_ARROW :value: '<->' .. py:data:: RIGHT_ARROW :value: '->' .. py:data:: LEFT_ARROW :value: '<-' .. py:data:: PERMISSION_REGEX :value: '[\\w-]+' .. py:data:: PERMISSIONS_REGEX .. py:data:: DIRECTION_REGEX .. py:data:: MAPPING_REGEX .. py:data:: NAMED_TOKEN_REGEX :value: '^\\{\\s*(\\w+)\\s*\\}$' .. py:exception:: ConfigError Bases: :py:obj:`RuntimeError` Generic error during configuration loading. Initialize self. See help(type(self)) for accurate signature. .. py:exception:: ConfigErrorInvalidTokens Bases: :py:obj:`ConfigError` Config error specific to invalid SINGLE_TOKEN or MULTI_TOKEN tokens. Initialize self. See help(type(self)) for accurate signature. .. py:exception:: ConfigErrorInvalidServiceKey Bases: :py:obj:`ConfigError` Config error for invalid service keys. Initialize self. See help(type(self)) for accurate signature. .. py:exception:: ConfigErrorInvalidResourceKey Bases: :py:obj:`ConfigError` Config error for invalid resource keys. Initialize self. See help(type(self)) for accurate signature. .. py:function:: _load_config(path_or_dict: Union[str, cowbird.typedefs.ConfigDict], section: str, allow_missing: bool = False) -> cowbird.typedefs.ConfigDict Loads a file path or dictionary as YAML/JSON configuration. .. py:function:: get_all_configs(path_or_dict: Union[str, cowbird.typedefs.ConfigDict], section: Literal['handlers'], allow_missing: bool = False) -> List[Dict[str, cowbird.typedefs.HandlerConfig]] get_all_configs(path_or_dict: Union[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. .. py:function:: _expand_all(config: cowbird.typedefs.ConfigDict) -> cowbird.typedefs.ConfigDict Applies environment variable expansion recursively to all applicable fields of a configuration definition. .. py:function:: validate_handlers_config_schema(handlers_cfg: Dict[str, cowbird.typedefs.HandlerConfig]) -> None Validates the schema of the `handlers` section found in the config. .. py:function:: validate_sync_perm_config_schema(sync_cfg: cowbird.typedefs.SyncPointConfig) -> None Validates the schema of the `sync_permissions` section found in the config. .. py:function:: validate_and_get_resource_info(res_key: str, segments: List[cowbird.typedefs.ConfigSegment]) -> cowbird.typedefs.ConfigResTokenInfo 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 .. py:function:: validate_bidirectional_mapping(mapping: str, res_info: Dict[str, cowbird.typedefs.ConfigResTokenInfo], res_key1: str, res_key2: str) -> None 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. .. py:function:: validate_unidirectional_mapping(mapping: str, src_info: cowbird.typedefs.ConfigResTokenInfo, tgt_info: cowbird.typedefs.ConfigResTokenInfo) -> None 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. .. py:function:: get_mapping_info(mapping: str) -> Tuple[Union[str, Any], Ellipsis] Obtain the different info found in a mapping string from the config. Returns the following matching groups : (res_key1, permission1, direction, res_key2, permission2) .. py:function:: get_permissions_from_str(permissions: str) -> List[str] 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. .. py:function:: validate_sync_mapping_config(sync_cfg: cowbird.typedefs.SyncPermissionConfig, res_info: Dict[str, cowbird.typedefs.ConfigResTokenInfo]) -> None Validates if mappings in the config have valid resource keys and use tokens properly. .. py:function:: validate_sync_config(sync_cfg: cowbird.typedefs.SyncPermissionConfig) -> None .. py:function:: validate_sync_config_services(sync_cfg: cowbird.typedefs.SyncPermissionConfig, available_services: List[str]) -> None Validates if all services used in the sync config are actual available services. All services should correspond to actual services available in Magpie.