-
Notifications
You must be signed in to change notification settings - Fork 3
/
main
executable file
·33 lines (30 loc) · 1.17 KB
/
main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import click
import logging
from src import consul
from src import logger
@click.command()
@click.option('--backup', is_flag=True, default=False, help='Performs a backup - Default mode')
@click.option('--restore', help='Performs a restore')
@click.option('--port', default=8500, help='Consul Port')
@click.option('--secure', is_flag=True, help='Enables TLS connection')
@click.option('--token', help='ACL token')
@click.argument('address')
def consulidator(backup, restore, port, secure, token, address):
consul_api = consul.Consul(address, port, secure, token)
if (backup is True and restore is not None) or (backup is False and restore is None):
logging.error("Must chose '--backup' or '--restore'")
elif restore is None:
logging.info("Performing backup")
consul_api.backup_kv()
else:
logging.info("Performing restore")
consul_api.restore_kv(restore)
if __name__ == '__main__':
try:
logger.initialize_logger()
consulidator()
except Exception as e:
logger = logging.getLogger("consulere")
logging.critical("Unhandled exception: {}".format(e), exc_info=True)
raise