-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdelete_events.py
More file actions
executable file
·60 lines (47 loc) · 1.66 KB
/
Copy pathdelete_events.py
File metadata and controls
executable file
·60 lines (47 loc) · 1.66 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
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
import sys
import json
import urllib2
import base64
import os
__all__ = [ 'main', ]
# Use environment variables if set other set to empty
API_KEY=os.environ['BOUNDARY_API_KEY']
ORG_ID=os.environ['BOUNDARY_ORG_ID']
API_URL="https://api.boundary.com/" + ORG_ID + "/events"
def encode_bn_auth():
b64_auth = base64.encodestring( ':'.join([API_KEY, ''])).replace('\n', '')
return ' '.join(['Basic', b64_auth])
#Query ORG for Events
def get_events(auth_header):
#url = '/'.join([API_URL, ORG_ID, E_QUERY])
#print "query url >>>" + url + "<<<"
#print "API_URL >>>" + API_URL + "<<<"
req = urllib2.Request(API_URL)
req.add_header('Authorization',auth_header)
response = urllib2.urlopen(req)
events = json.load(response)
return events
def delete_event(eventid):
os.system("/usr/bin/curl -X DELETE -i -u " + API_KEY + ": " + API_URL + "/" + eventid)
print "Event matching id >>>" + eventid + "<<< has been DELETED"
#url = API_URL + "/" + eventid
#req = urllib2.Request(url, {'Content-type': 'application/json'})
#req.add_header('Authorization', auth_header)
#response = urllib2.urlopen(req)
#Loop through events and delete each one
def main():
bn_auth_header = encode_bn_auth()
#get_events(bn_auth_header)
events = get_events(bn_auth_header)
eventcount = events["total"]
print "Event count is >>>" + str(eventcount) + "<<<"
while eventcount > 0:
for event in events["results"]:
eventid = str(event["id"])
delete_event(eventid)
events = get_events(bn_auth_header)
eventcount = events["total"]
print "Event count is >>>" + str(eventcount) + "<<<"
if __name__ == "__main__":
main()