Coverage for curator/singletons.py: 98%

1"""CLI module for curator_cli"""

2 import os

3 import logging

4 import click

5 from curator.defaults import settings

6 from curator.config_utils import test_config, set_logging

7 from curator.utils import test_client_options

8 from curator.cli_singletons.utils import config_override, false_to_none, get_width

9 from curator.cli_singletons.alias import alias

10 from curator.cli_singletons.allocation import allocation

11 from curator.cli_singletons.close import close

12 from curator.cli_singletons.delete import delete_indices, delete_snapshots

13 from curator.cli_singletons.forcemerge import forcemerge

14 from curator.cli_singletons.open_indices import open_indices

15 from curator.cli_singletons.replicas import replicas

16 from curator.cli_singletons.restore import restore

17 from curator.cli_singletons.rollover import rollover

18 from curator.cli_singletons.snapshot import snapshot

19 from curator.cli_singletons.shrink import shrink

20 from curator.cli_singletons.show import show_indices, show_snapshots

21 from curator._version import __version__

22

23@click.group(context_settings=get_width())

24@click.option(

25 '--config', help='Path to configuration file. Default: ~/.curator/curator.yml',

26 type=click.Path(), default=settings.config_file()

27)

28@click.option('--host', help='Elasticsearch host.')

29@click.option('--url_prefix', help='Elasticsearch http url prefix.')

30@click.option('--port', help='Elasticsearch port.')

31@click.option(

32 '--use_ssl', is_flag=True,

33 callback=false_to_none, help='Connect to Elasticsearch through SSL.'

34)

35@click.option('--certificate', help='Path to certificate to use for SSL validation.')

36@click.option(

37 '--client-cert', help='Path to file containing SSL certificate for client auth.', type=str)

38@click.option('--client-key', help='Path to file containing SSL key for client auth.', type=str)

39@click.option(

40 '--ssl-no-validate', is_flag=True,

41 callback=false_to_none, help='Do not validate SSL certificate'

42)

43@click.option(

44 '--http_auth',

45 help='Use Basic Authentication ex: user:pass -- DEPRECATED. Use username and password.'

46)

47@click.option('--username', help='HTTP Basic Authentication username', type=str)

48@click.option('--password', help='HTTP Basic Authentication password', type=str)

49@click.option(

50 '--apikey_auth',

51 help='API Key Authentication encoded in base64 containing `id:api_key`',

52 type=str

53)

54@click.option('--timeout', help='Connection timeout in seconds.', type=int)

55@click.option(

56 '--master-only', is_flag=True, callback=false_to_none,

57 help='Only operate on elected master node.'

58)

59@click.option('--dry-run', is_flag=True, help='Do not perform any changes.')

60@click.option('--loglevel', help='Log level')

61@click.option('--logfile', help='log file')

62@click.option('--logformat', help='Log output format [default|logstash|json|ecs].')

63@click.version_option(version=__version__)

64@click.pass_context

65 def cli(

66 ctx, config, host, url_prefix, port, use_ssl, certificate, client_cert, client_key,

67 ssl_no_validate, http_auth, username, password, apikey_auth, timeout, master_only, dry_run, loglevel,

68 logfile, logformat

69 ):

70 """CLI input"""

71 if os.path.isfile(config):

72 initial_config = test_config(config)

73 else:

74 initial_config = None

75 configuration = config_override(ctx, initial_config)

76 set_logging(configuration['logging'])

77 test_client_options(configuration['client'])

78 ctx.obj['config'] = configuration

79 ctx.obj['dry_run'] = dry_run

80# Add the subcommands

81 cli.add_command(alias)

82 cli.add_command(allocation)

83 cli.add_command(close)

84 cli.add_command(delete_indices)

85 cli.add_command(delete_snapshots)

86 cli.add_command(forcemerge)

87 cli.add_command(open_indices)

88 cli.add_command(replicas)

89 cli.add_command(snapshot)

90 cli.add_command(restore)

91 cli.add_command(rollover)

92 cli.add_command(shrink)

93 cli.add_command(show_indices)

94 cli.add_command(show_snapshots)