##// END OF EJS Templates
healthcheck: Added authentication because we expose DB information
super-admin -
r4737:77c100d1 stable
parent child Browse files
Show More
@@ -1,94 +1,97 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2020 RhodeCode GmbH
3 # Copyright (C) 2016-2020 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import time
21 import time
22 import logging
22 import logging
23
23
24
24
25 from pyramid.httpexceptions import HTTPFound
25 from pyramid.httpexceptions import HTTPFound
26
26
27 from rhodecode.apps._base import BaseAppView
27 from rhodecode.apps._base import BaseAppView
28 from rhodecode.lib import helpers as h
28 from rhodecode.lib import helpers as h
29 from rhodecode.lib.auth import LoginRequired
30 from rhodecode.model.db import UserApiKeys
29
31
30 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
31
33
32
34
33 class OpsView(BaseAppView):
35 class OpsView(BaseAppView):
34
36
35 def load_default_context(self):
37 def load_default_context(self):
36 c = self._get_local_tmpl_context()
38 c = self._get_local_tmpl_context()
37 c.user = c.auth_user.get_instance()
39 c.user = c.auth_user.get_instance()
38
40
39 return c
41 return c
40
42
41 def ops_ping(self):
43 def ops_ping(self):
42 data = {
44 data = {
43 'instance': self.request.registry.settings.get('instance_id'),
45 'instance': self.request.registry.settings.get('instance_id'),
44 }
46 }
45 if getattr(self.request, 'user'):
47 if getattr(self.request, 'user'):
46 caller_name = 'anonymous'
48 caller_name = 'anonymous'
47 if self.request.user.user_id:
49 if self.request.user.user_id:
48 caller_name = self.request.user.username
50 caller_name = self.request.user.username
49
51
50 data.update({
52 data.update({
51 'caller_ip': self.request.user.ip_addr,
53 'caller_ip': self.request.user.ip_addr,
52 'caller_name': caller_name,
54 'caller_name': caller_name,
53 })
55 })
54 return {'ok': data}
56 return {'ok': data}
55
57
56 def ops_error_test(self):
58 def ops_error_test(self):
57 """
59 """
58 Test exception handling and emails on errors
60 Test exception handling and emails on errors
59 """
61 """
60
62
61 class TestException(Exception):
63 class TestException(Exception):
62 pass
64 pass
63 # add timeout so we add some sort of rate limiter
65 # add timeout so we add some sort of rate limiter
64 time.sleep(2)
66 time.sleep(2)
65 msg = ('RhodeCode Enterprise test exception. '
67 msg = ('RhodeCode Enterprise test exception. '
66 'Client:{}. Generation time: {}.'.format(self.request.user, time.time()))
68 'Client:{}. Generation time: {}.'.format(self.request.user, time.time()))
67 raise TestException(msg)
69 raise TestException(msg)
68
70
69 def ops_redirect_test(self):
71 def ops_redirect_test(self):
70 """
72 """
71 Test redirect handling
73 Test redirect handling
72 """
74 """
73 redirect_to = self.request.GET.get('to') or h.route_path('home')
75 redirect_to = self.request.GET.get('to') or h.route_path('home')
74 raise HTTPFound(redirect_to)
76 raise HTTPFound(redirect_to)
75
77
78 @LoginRequired(auth_token_access=[UserApiKeys.ROLE_HTTP])
76 def ops_healthcheck(self):
79 def ops_healthcheck(self):
77 from rhodecode.lib.system_info import load_system_info
80 from rhodecode.lib.system_info import load_system_info
78
81
79 vcsserver_info = load_system_info('vcs_server')
82 vcsserver_info = load_system_info('vcs_server')
80 if vcsserver_info:
83 if vcsserver_info:
81 vcsserver_info = vcsserver_info['human_value']
84 vcsserver_info = vcsserver_info['human_value']
82
85
83 db_info = load_system_info('database_info')
86 db_info = load_system_info('database_info')
84 if db_info:
87 if db_info:
85 db_info = db_info['human_value']
88 db_info = db_info['human_value']
86
89
87 health_spec = {
90 health_spec = {
88 'caller_ip': self.request.user.ip_addr,
91 'caller_ip': self.request.user.ip_addr,
89 'vcsserver': vcsserver_info,
92 'vcsserver': vcsserver_info,
90 'db': db_info,
93 'db': db_info,
91 }
94 }
92
95
93 return {'healthcheck': health_spec}
96 return {'healthcheck': health_spec}
94
97
General Comments 0
You need to be logged in to leave comments. Login now