]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/feedback/service.py
import quincy beta 17.1.0
[ceph.git] / ceph / src / pybind / mgr / feedback / service.py
1 # -*- coding: utf-8 -*-
2
3 import json
4 import requests
5 from requests.exceptions import RequestException
6
7 from .model import Feedback
8
9 class config:
10 url = 'tracker.ceph.com'
11 port = 443
12
13 class CephTrackerClient():
14
15 def list_issues(self):
16 '''
17 Fetch an issue from the Ceph Issue tracker
18 '''
19 headers = {
20 'Content-Type': 'application/json',
21 }
22 response = requests.get(
23 f'https://{config.url}/issues.json', headers=headers)
24 if not response.ok:
25 if response.status_code == 404:
26 raise FileNotFoundError
27 raise RequestException(response.status_code)
28 return {"message": response.json()}
29
30 def create_issue(self, feedback: Feedback, api_key: str):
31 '''
32 Create an issue in the Ceph Issue tracker
33 '''
34 try:
35 headers = {
36 'Content-Type': 'application/json',
37 'X-Redmine-API-Key': api_key,
38 }
39 except KeyError:
40 raise Exception("Ceph Tracker API Key not set")
41 data = json.dumps(feedback.as_dict())
42 response = requests.post(
43 f'https://{config.url}/projects/{feedback.project_id}/issues.json',
44 headers=headers, data=data)
45 if not response.ok:
46 if response.status_code == 401:
47 raise RequestException("Unauthorized. Invalid issue tracker API key")
48 raise RequestException(response.reason)
49 return {"message": response.json()}