Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/pii/lib/python3.12/site-packages/es_pii_tool/commands/from_yaml.py: 0%
26 statements
« prev ^ index » next coverage.py v7.5.0, created at 2025-01-29 19:21 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2025-01-29 19:21 -0700
1"""Click decorated function for Redacting from YAML file"""
3import logging
4import click
5from es_client.helpers.config import cli_opts, get_client
6from es_client.helpers.utils import option_wrapper
7from es_pii_tool.defaults import CLICK_DRYRUN, CLICK_TRACKING
8from es_pii_tool.exceptions import FatalError
9from es_pii_tool.base import PiiTool
11logger = logging.getLogger(__name__)
13click_opt_wrap = option_wrapper() # Needed or pylint blows a fuse
16@click.command()
17@click_opt_wrap(*cli_opts('dry-run', settings=CLICK_DRYRUN))
18@click_opt_wrap(*cli_opts('tracking-index', settings=CLICK_TRACKING))
19@click.argument('redactions_file', type=click.Path(exists=True), nargs=1)
20@click.pass_context
21def file_based(ctx, dry_run, redactions_file, tracking_index):
22 """Redact from YAML config file"""
23 try:
24 client = get_client(configdict=ctx.obj['configdict'])
25 except Exception as exc:
26 logger.critical('Error attempting to get client connection: %s', exc.args[0])
27 raise FatalError(
28 'Unable to establish connection to Elasticsearch!', exc
29 ) from exc
30 try:
31 main = PiiTool(
32 client, tracking_index, redaction_file=redactions_file, dry_run=dry_run
33 )
34 main.run()
35 except Exception as exc:
36 logger.error('Exception: %s', exc)
37 raise exc