forked from sysdiglabs/sysdig-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_policy.py
executable file
·61 lines (51 loc) · 1.21 KB
/
delete_policy.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
#!/usr/bin/env python
#
# Delete a policy, by either id or name.
#
import os
import sys
import json
import getopt
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdSecureClient
def usage():
print 'usage: %s [-i|--id <id>] [-n|--name <name>] <sysdig-token>' % sys.argv[0]
print '-i|--id: the id of the policy to delete'
print '-n|--name: the name of the policy to delete'
print 'You can find your token at https://secure.sysdig.com/#/settings/user'
sys.exit(1)
#
# Parse arguments
#
try:
opts, args = getopt.getopt(sys.argv[1:],"i:n:",["id=","name="])
except getopt.GetoptError:
usage()
id = ""
name = ""
for opt, arg in opts:
if opt in ("-i", "--id"):
id = arg
elif opt in ("-n", "--name"):
name = arg
if len(id) + len(name) == 0:
usage()
if len(args) < 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdSecureClient(sdc_token, 'https://secure.sysdig.com')
if len(id) > 0:
res = sdclient.delete_policy_id(id)
else:
res = sdclient.delete_policy_name(name)
#
# Return the result
#
if res[0]:
print json.dumps(res[1], indent=2)
else:
print res[1]
sys.exit(1)