in src/es_pii_tool/helpers/utils.py [0:0]
def get_redactions(file: str = '', data: t.Union[t.Dict, None] = None) -> 'Schema':
"""
Return valid dictionary of redactions from either ``file`` or from ``data``
after checking Schema
:param file: YAML file with redactions to check
:param data: Configuration data in dictinoary format
:type file: str
:type data: dict
:rtype: dict
:returns: Redactions configuration data
"""
if data is None:
data = {}
logger.debug('Getting redactions data...')
if file:
try:
config = get_yaml(file)
except esc_ConfigError as exc:
msg = f'Unable to read and/or parse YAML REDACTIONS_FILE: {file} Exiting.'
logger.critical(msg)
raise e.ConfigError(msg, exc)
elif data:
config = data
else:
raise e.FatalError('No configuration file or dictionary provided.', Exception())
logger.debug('Performing redaction schema check...')
try:
return SchemaCheck(
config, redaction_schema(), 'Redaction Configuration', 'redactions'
).result()
except Exception as exc:
msg = f'Redaction configuration schema check failed: {exc} -- Exiting.'
logger.critical(msg)
raise exc