summaryrefslogtreecommitdiffstats
path: root/client/bug_delete.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/bug_delete.py')
-rwxr-xr-xclient/bug_delete.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/client/bug_delete.py b/client/bug_delete.py
index bcce88e..393225e 100755
--- a/client/bug_delete.py
+++ b/client/bug_delete.py
@@ -10,24 +10,37 @@ required.
-i, --ticket-id ID of the ticket to delete
"""
from docopt import docopt
-import json, requests
+import json, requests, sys
+import configparser
if __name__ == '__main__':
print(docopt(__doc__))
-def call(args):
+def entrypoint(args):
print(args)
- api_endpoint = args['--uri'] + '/api/1.0/ticket/'
+ c = configparser.ConfigParser()
+ c.read('config')
+ config = c[args['--uri']]
+ access_token = config['access_token']
- req = requests.delete(api_endpoint + args['<ticket_id>'])
+ uri = args['--uri'] + '/api/1.0/ticket/' + args['<ticket_id>']
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'Access-Token': access_token,
+ }
+
+ req = requests.delete(uri, headers=headers, verify=False)
res = json.loads(req.text)
- if req.status_code == 404:
- print("Ticket with ID '{}' could not be deleted: {}".format(args['<ticket_id>'], res['error']))
+ if req.status_code == (401 or 404):
+ sys.exit("Ticket with ID '{}' could not be deleted: {}".format(args['<ticket_id>'], res['error']))
+
elif req.status_code == 200:
- print("Ticket with ID '{}' deleted successfully.".format(args['<ticket_id>']))
+ sys.exit("Ticket with ID '{}' deleted successfully.".format(args['<ticket_id>']))
+
else:
- exit("ALERT ALERT ALERT")
+ sys.exit("ALERT ALERT ALERT")
#print("{} {}\n {}".format(t['id'], t['title'], t['uri']))