summaryrefslogtreecommitdiffstats
path: root/client/bug_delete.py
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-10-05 01:30:14 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2014-10-05 01:30:14 +0200
commit99f748ed7f445c5dfb019b6327d119e08f00cad4 (patch)
tree6310abef82613afc1fa6b23b4a3855a4e519f1eb /client/bug_delete.py
parent571976cb2780ab0272b95b05bff860a3b8f04cc9 (diff)
downloadtbt-master.tar.xz
another massive commitHEADmaster
all of this should be squashed later.. at least most of it works now, I think... I should add some tests probably.
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']))