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 click_opt_wrap = option_wrapper() # Needed or pylint blows a fuse

12

13

14@click.command()

15@click_opt_wrap(*cli_opts('dry-run', settings=CLICK_DRYRUN))

16@click_opt_wrap(*cli_opts('tracking-index', settings=CLICK_TRACKING))

17@click.argument('redactions_file', type=click.Path(exists=True), nargs=1)

18@click.pass_context

19 def file_based(ctx, dry_run, redactions_file, tracking_index):

20 """Redact from YAML config file"""

21 logger = logging.getLogger(__name__)

22 for loog in logging.Logger.manager.loggerDict.keys():

23 click.echo(f'Logger: {loog}')

24 click.echo(f'Logger: {logging.Logger.manager.loggerDict[loog]}')

25 logger.debug('File-based redaction starting...')

26 try:

27 client = get_client(configdict=ctx.obj['configdict'])

28 except Exception as exc:

29 logger.critical('Error attempting to get client connection: %s', exc.args[0])

30 raise FatalError(

31 'Unable to establish connection to Elasticsearch!', exc

32 ) from exc

33 try:

34 main = PiiTool(

35 client, tracking_index, redaction_file=redactions_file, dry_run=dry_run

36 )

37 main.run()

38 except Exception as exc:

39 logger.error('Exception: %s', exc)

40 raise exc