summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/feedback/service.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/pybind/mgr/feedback/service.py
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/feedback/service.py')
-rw-r--r--src/pybind/mgr/feedback/service.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pybind/mgr/feedback/service.py b/src/pybind/mgr/feedback/service.py
new file mode 100644
index 000000000..dc8c6b64a
--- /dev/null
+++ b/src/pybind/mgr/feedback/service.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+import json
+import requests
+from requests.exceptions import RequestException
+
+from .model import Feedback
+
+class config:
+ url = 'tracker.ceph.com'
+ port = 443
+
+class CephTrackerClient():
+
+ def list_issues(self):
+ '''
+ Fetch an issue from the Ceph Issue tracker
+ '''
+ headers = {
+ 'Content-Type': 'application/json',
+ }
+ response = requests.get(
+ f'https://{config.url}/issues.json', headers=headers)
+ if not response.ok:
+ if response.status_code == 404:
+ raise FileNotFoundError
+ raise RequestException(response.status_code)
+ return {"message": response.json()}
+
+ def create_issue(self, feedback: Feedback, api_key: str):
+ '''
+ Create an issue in the Ceph Issue tracker
+ '''
+ try:
+ headers = {
+ 'Content-Type': 'application/json',
+ 'X-Redmine-API-Key': api_key,
+ }
+ except KeyError:
+ raise Exception("Ceph Tracker API Key not set")
+ data = json.dumps(feedback.as_dict())
+ response = requests.post(
+ f'https://{config.url}/projects/{feedback.project_id}/issues.json',
+ headers=headers, data=data)
+ if not response.ok:
+ if response.status_code == 401:
+ raise RequestException("Unauthorized. Invalid issue tracker API key")
+ raise RequestException(response.reason)
+ return {"message": response.json()}