]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/feedback.py
import ceph quincy 17.2.6
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / feedback.py
CommitLineData
20effc67
TL
1# # -*- coding: utf-8 -*-
2
3from .. import mgr
4from ..exceptions import DashboardException
5from ..security import Scope
6from . import APIDoc, APIRouter, BaseController, Endpoint, ReadPermission, RESTController, UIRouter
7from ._version import APIVersion
8
9
10@APIRouter('/feedback', Scope.CONFIG_OPT)
11@APIDoc("Feedback API", "Report")
12class FeedbackController(RESTController):
13
14 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
15 def list(self):
16 """
17 List all issues details.
18 """
19 try:
20 response = mgr.remote('feedback', 'get_issues')
21 except RuntimeError as error:
22 raise DashboardException(msg=f'Error in fetching issue list: {str(error)}',
23 http_status_code=error.status_code,
24 component='feedback')
25 return response
26
27 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
28 def create(self, project, tracker, subject, description, api_key=None):
29 """
30 Create an issue.
31 :param project: The affected ceph component.
32 :param tracker: The tracker type.
33 :param subject: The title of the issue.
34 :param description: The description of the issue.
35 :param api_key: Ceph tracker api key.
36 """
37 try:
38 response = mgr.remote('feedback', 'validate_and_create_issue',
39 project, tracker, subject, description, api_key)
40 except RuntimeError as error:
41 if "Invalid issue tracker API key" in str(error):
42 raise DashboardException(msg='Error in creating tracker issue: Invalid API key',
43 component='feedback')
44 if "KeyError" in str(error):
45 raise DashboardException(msg=f'Error in creating tracker issue: {error}',
46 component='feedback')
47 raise DashboardException(msg=f'{error}',
48 http_status_code=500,
49 component='feedback')
50
51 return response
52
53
54@APIRouter('/feedback/api_key', Scope.CONFIG_OPT)
55@APIDoc(group="Report")
56class FeedbackApiController(RESTController):
57
58 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
59 def list(self):
60 """
61 Returns Ceph tracker API key.
62 """
63 try:
64 api_key = mgr.remote('feedback', 'get_api_key')
65 except ImportError:
66 raise DashboardException(msg='Feedback module not found.',
67 http_status_code=404,
68 component='feedback')
69 except RuntimeError as error:
70 raise DashboardException(msg=f'{error}',
71 http_status_code=500,
72 component='feedback')
73 if api_key is None:
74 raise DashboardException(msg='Issue tracker API key is not set',
75 component='feedback')
76 return api_key
77
78 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
79 def create(self, api_key):
80 """
81 Sets Ceph tracker API key.
82 :param api_key: The Ceph tracker API key.
83 """
84 try:
85 response = mgr.remote('feedback', 'set_api_key', api_key)
86 except RuntimeError as error:
87 raise DashboardException(msg=f'{error}',
88 component='feedback')
89 return response
90
91 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
92 def bulk_delete(self):
93 """
94 Deletes Ceph tracker API key.
95 """
96 try:
97 response = mgr.remote('feedback', 'delete_api_key')
98 except RuntimeError as error:
99 raise DashboardException(msg=f'{error}',
100 http_status_code=500,
101 component='feedback')
102 return response
103
104
105@UIRouter('/feedback/api_key', Scope.CONFIG_OPT)
106class FeedbackUiController(BaseController):
107 @Endpoint()
108 @ReadPermission
109 def exist(self):
110 """
111 Checks if Ceph tracker API key is stored.
112 """
113 try:
114 response = mgr.remote('feedback', 'is_api_key_set')
115 except RuntimeError:
116 raise DashboardException(msg='Feedback module is not enabled',
117 http_status_code=404,
118 component='feedback')
119
120 return response