From e8d2933c9638865c9d1ac8e6173064efdf51480d Mon Sep 17 00:00:00 2001 From: Maciej Stosio <91123695+maciekstosiopronos@users.noreply.github.com> Date: Sun, 21 Nov 2021 23:03:46 +0100 Subject: [PATCH 1/3] ADD JIRA TEMPOIO LOGGING --- aw_server/rest.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/aw_server/rest.py b/aw_server/rest.py index 4184eaff..544ef7c7 100644 --- a/aw_server/rest.py +++ b/aw_server/rest.py @@ -15,7 +15,11 @@ from . import logger from .api import ServerAPI from .exceptions import BadRequest, Unauthorized +from .config import config +import requests +from requests.auth import HTTPBasicAuth +from datetime import datetime def host_header_check(f): """ @@ -200,7 +204,7 @@ def get(self, bucket_id): end = iso8601.parse_date(args["end"]) if "end" in args else None events = current_app.api.get_events( - bucket_id, limit=limit, start=start, end=end + bucket_id, limit=limit, end=end ) return events, 200 @@ -369,3 +373,96 @@ class LogResource(Resource): @copy_doc(ServerAPI.get_log) def get(self): return current_app.api.get_log(), 200 + + +@api.route("/0/tempoio//") +class GetTempoIOData(Resource): + def get(self, start, end): + try: + hed = {'Authorization': 'Bearer {}'.format(config['tempoio']['api_key'])} + response = requests.get('https://api.tempo.io/core/3/worklogs?from={}&to={}'.format(start, end), headers=hed) + + if response.status_code == 200: + return response.json(), 200 + + print('Tempo IO get request failed') + return None, 400 + except KeyError: + return None, 412 + + +@api.route("/0/tempoio/") +class EditTempoIOData(Resource): + def delete(self, id): + try: + hed = { + 'Authorization': 'Bearer {}'.format(config['tempoio']['api_key']), + 'Content-type':'application/json' + } + + response = requests.delete('https://api.tempo.io/core/3/worklogs/{}'.format(id), headers=hed) + + if response.ok: + return None, 200 + + print('Tempo IO delete request failed') + return None, 400 + except KeyError: + return None, 412 + + + def put(self): + try: + body = request.get_json() + body["authorAccountId"] = config['tempoio']['user'] + hed = { + 'Authorization': 'Bearer {}'.format(config['tempoio']['api_key']), + 'Content-type':'application/json' + } + + response = requests.put('https://api.tempo.io/core/3/worklogs/{}'.format(id), headers=hed, json=body) + + if response.status_code == 200: + return response.json(), 200 + + print('Tempo IO post request failed') + return None, 400 + except KeyError: + return None, 412 + +@api.route("/0/tempoio") +class AddTempoIOData(Resource): + def post(self): + try: + body = request.get_json() + body["authorAccountId"] = config['tempoio']['user'] + hed = { + 'Authorization': 'Bearer {}'.format(config['tempoio']['api_key']), + 'Content-type':'application/json' + } + + response = requests.post('https://api.tempo.io/core/3/worklogs', headers=hed, json=body) + + if response.status_code == 200: + return response.json(), 200 + + print('Tempo IO post request failed') + return None, 400 + except KeyError: + return None, 412 + +@api.route("/0/jira") +class GetJiraData(Resource): + def get(self): + try: + url = '{}/rest/api/3/search?jql={}'.format(config['jira']['base_url'], config['jira']['jql']) + response = requests.get(url, verify=False, auth=HTTPBasicAuth(config['jira']['email'], config['jira']['api_key'])) + + if response.status_code == 200: + return response.json(), 200 + + print('Jira request failed') + return None, 400 + except KeyError: + return None, 412 + From 8c62ac6a183ff4c25f4d9bc0fcfc096d1fd205db Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Wed, 17 Aug 2022 15:05:20 +0100 Subject: [PATCH 2/3] Remove veriyfy=false flag --- aw_server/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aw_server/rest.py b/aw_server/rest.py index 544ef7c7..f89d09f6 100644 --- a/aw_server/rest.py +++ b/aw_server/rest.py @@ -456,7 +456,7 @@ class GetJiraData(Resource): def get(self): try: url = '{}/rest/api/3/search?jql={}'.format(config['jira']['base_url'], config['jira']['jql']) - response = requests.get(url, verify=False, auth=HTTPBasicAuth(config['jira']['email'], config['jira']['api_key'])) + response = requests.get(url, auth=HTTPBasicAuth(config['jira']['email'], config['jira']['api_key'])) if response.status_code == 200: return response.json(), 200 From 85afae266b8f778fb454b935d9e3de916e9b9185 Mon Sep 17 00:00:00 2001 From: Maciej Stosio Date: Wed, 17 Aug 2022 15:07:25 +0100 Subject: [PATCH 3/3] Restore changes --- aw_server/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aw_server/rest.py b/aw_server/rest.py index f89d09f6..b6ca7889 100644 --- a/aw_server/rest.py +++ b/aw_server/rest.py @@ -204,7 +204,7 @@ def get(self, bucket_id): end = iso8601.parse_date(args["end"]) if "end" in args else None events = current_app.api.get_events( - bucket_id, limit=limit, end=end + bucket_id, limit=limit, start=start, end=end ) return events, 200