forked from carbonblack/cbapi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbapi
More file actions
48 lines (35 loc) · 1.33 KB
/
cbapi
File metadata and controls
48 lines (35 loc) · 1.33 KB
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
#!/usr/bin/env python
import argparse
import contextlib
from cbapi.six import iteritems
import sys
from cbapi.connection import check_python_tls_compatibility
def check_tls(opts):
print("Newest TLS version supported by this platform is: {0}.".format(check_python_tls_compatibility()))
command_map = {
"check-tls": {
"extra_args": {},
"help": "Return the latest version of TLS supported by this version of Python and OpenSSL. "
"Cb Response versions 6.1+ now require TLSv1.2 support.",
"method": check_tls
}
}
def main(args):
parser = argparse.ArgumentParser()
commands = parser.add_subparsers(dest="command_name", help="CbAPI subcommand")
for cmd_name, cmd_config in iteritems(command_map):
cmd_parser = commands.add_parser(cmd_name, help=cmd_config.get("help", None))
for cmd_arg_name, cmd_arg_config in iteritems(cmd_config.get("extra_args", {})):
cmd_parser.add_argument(cmd_arg_name, **cmd_arg_config)
opts = parser.parse_args(args)
command = command_map.get(opts.command_name)
if not command:
parser.print_usage()
return
command_method = command.get("method", None)
if command_method:
return command_method(opts)
else:
parser.print_usage()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))