-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathset_policy_order_v1.py
executable file
·63 lines (48 loc) · 1.27 KB
/
set_policy_order_v1.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
#!/usr/bin/env python
#
# Change the evaluation order of policies to match the provided json.
#
import json
import sys
from sdcclient import SdSecureClientV1
def usage():
print(('usage: %s <sysdig-token>' % sys.argv[0]))
print('Reads json representing new policy evaluation order from standard input')
print('You can find your token at https://secure.sysdig.com/#/settings/user')
sys.exit(1)
#
# Parse arguments
#
if len(sys.argv) != 2:
usage()
sdc_token = sys.argv[1]
priorities_json = sys.stdin.read()
try:
priorities_obj = json.loads(priorities_json)
except Exception as e:
print(("priorities json is not valid json: {}".format(str(e))))
sys.exit(1)
#
# Instantiate the SDC client
#
sdclient = SdSecureClientV1(sdc_token, 'https://secure.sysdig.com')
#
# The argument to /api/policies/priorities is the list of ids wrapped
# in an object containing a version and dates. So fetch the list of
# priorities, update the list in-place and set it.
#
ok, res = sdclient.get_policy_priorities()
if not ok:
print(res)
sys.exit(1)
obj = res
obj['priorities']['policyIds'] = priorities_obj
ok, res = sdclient.set_policy_priorities(json.dumps(obj))
#
# Return the result
#
if ok:
print((json.dumps(res, indent=2)))
else:
print(res)
sys.exit(1)