This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.py
50 lines (44 loc) · 1.69 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright: [DAudit] - See LICENSE for details.
# Authors: Shou Chaofan (@shouc),
import argparse
import modules
import utils
DIR_HELP = 'the dir of configuration files, leave blank if you' \
' wish the program to automatically detect it. (e.g. --dir /etc/)'
def main():
parser = argparse.ArgumentParser(
description="This is a tool for detecting configuration issues of Redis, MongoDB, etc!")
subparsers = parser.add_subparsers(help='commands')
for i in modules.SUPPORTED_DB:
name = i["name"]
custom_args = i["custom_args"]
fragment_func_args = ""
for arg in custom_args:
if arg == "--dir":
fragment_func_args += "dir=utils.abs_path_from_args(args),"
continue
elif arg == "--file":
fragment_func_args += "file=utils.file_from_args(args),"
continue
else:
arg = arg.replace("--", "")
fragment_func_args += f"{arg}=args.{arg},"
exec(f"""def __{name}(args):
from modules.{name} import {name.capitalize()}
r = {name.capitalize()}(
{fragment_func_args}
)
r.check_conf()
""")
setting_check_parser = subparsers.add_parser(name, help=f'Check configurations of {name}')
for arg in custom_args:
setting_check_parser.add_argument(arg, dest=arg.replace("--", ""), action='store',
help=custom_args[arg])
setting_check_parser.set_defaults(func=eval(f"__{name}"))
args = parser.parse_args()
if len(args.__dict__) <= 1:
parser.print_help()
parser.exit()
args.func(args)
if __name__ == '__main__':
main()