-
Notifications
You must be signed in to change notification settings - Fork 44
/
get_secure_default_falco_rules_files.py
executable file
·70 lines (58 loc) · 1.51 KB
/
get_secure_default_falco_rules_files.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
#
# Get the sysdig secure default rules files.
#
# The _files programs and endpoints are a replacement for the
# system_file endpoints and allow for publishing multiple files
# instead of a single file as well as publishing multiple variants of
# a given file that are compatible with different agent versions.
#
import getopt
import pprint
import sys
from sdcclient import SdSecureClient
#
# Parse arguments
#
def usage():
print(('usage: %s [-s|--save <path>] <sysdig-token>' % sys.argv[0]))
print('-s|--save: save the retrieved files to a set of files below <path> using save_default_rules_files().')
print('You can find your token at https://secure.sysdig.com/#/settings/user')
sys.exit(1)
try:
opts, args = getopt.getopt(sys.argv[1:], "s:", ["save="])
except getopt.GetoptError:
usage()
save_dir = ""
for opt, arg in opts:
if opt in ("-s", "--save"):
save_dir = arg
#
# Parse arguments
#
if len(args) != 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdSecureClient(sdc_token, 'https://secure.sysdig.com')
#
# Get the configuration
#
ok, res = sdclient.get_default_falco_rules_files()
#
# Return the result
#
if ok:
if save_dir == "":
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(res)
else:
print(("Saving falco rules files below {}...".format(save_dir)))
ok, sres = sdclient.save_default_falco_rules_files(res, save_dir)
if not ok:
print(sres)
else:
print(res)
sys.exit(1)