Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/pii/lib/python3.12/site-packages/es_pii_tool/commands/from_yaml.py: 0%

1"""Click decorated function for Redacting from YAML file"""

2

3 import logging

4 import click

5 from es_client.helpers.config import cli_opts, get_client

6 from es_client.helpers.utils import option_wrapper

7 from es_pii_tool.defaults import CLICK_DRYRUN, CLICK_TRACKING

8 from es_pii_tool.exceptions import FatalError

9 from es_pii_tool.base import PiiTool

10

11 logger = logging.getLogger(__name__)

12

13 click_opt_wrap = option_wrapper() # Needed or pylint blows a fuse

14

15

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

21 def 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