##// END OF EJS Templates
ops: add better name for anonymous ops/ping calls.
marcink -
r3340:bd620f63 default
parent child Browse files
Show More
@@ -1,85 +1,89 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2018 RhodeCode GmbH
3 # Copyright (C) 2016-2018 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 from pyramid.view import view_config
24 from pyramid.view import view_config
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
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32
32
33 class OpsView(BaseAppView):
33 class OpsView(BaseAppView):
34
34
35 def load_default_context(self):
35 def load_default_context(self):
36 c = self._get_local_tmpl_context()
36 c = self._get_local_tmpl_context()
37 c.user = c.auth_user.get_instance()
37 c.user = c.auth_user.get_instance()
38
38
39 return c
39 return c
40
40
41 @view_config(
41 @view_config(
42 route_name='ops_ping', request_method='GET',
42 route_name='ops_ping', request_method='GET',
43 renderer='json_ext')
43 renderer='json_ext')
44 @view_config(
44 @view_config(
45 route_name='ops_ping_legacy', request_method='GET',
45 route_name='ops_ping_legacy', request_method='GET',
46 renderer='json_ext')
46 renderer='json_ext')
47 def ops_ping(self):
47 def ops_ping(self):
48 data = {
48 data = {
49 'instance': self.request.registry.settings.get('instance_id'),
49 'instance': self.request.registry.settings.get('instance_id'),
50 }
50 }
51 if getattr(self.request, 'user'):
51 if getattr(self.request, 'user'):
52 caller_name = 'anonymous'
53 if self.request.user.user_id:
54 caller_name = self.request.user.username
55
52 data.update({
56 data.update({
53 'caller_ip': self.request.user.ip_addr,
57 'caller_ip': self.request.user.ip_addr,
54 'caller_name': self.request.user.username,
58 'caller_name': caller_name,
55 })
59 })
56 return {'ok': data}
60 return {'ok': data}
57
61
58 @view_config(
62 @view_config(
59 route_name='ops_error_test', request_method='GET',
63 route_name='ops_error_test', request_method='GET',
60 renderer='json_ext')
64 renderer='json_ext')
61 @view_config(
65 @view_config(
62 route_name='ops_error_test_legacy', request_method='GET',
66 route_name='ops_error_test_legacy', request_method='GET',
63 renderer='json_ext')
67 renderer='json_ext')
64 def ops_error_test(self):
68 def ops_error_test(self):
65 """
69 """
66 Test exception handling and emails on errors
70 Test exception handling and emails on errors
67 """
71 """
68
72
69 class TestException(Exception):
73 class TestException(Exception):
70 pass
74 pass
71 # add timeout so we add some sort of rate limiter
75 # add timeout so we add some sort of rate limiter
72 time.sleep(2)
76 time.sleep(2)
73 msg = ('RhodeCode Enterprise test exception. '
77 msg = ('RhodeCode Enterprise test exception. '
74 'Client:{}. Generation time: {}.'.format(self.request.user, time.time()))
78 'Client:{}. Generation time: {}.'.format(self.request.user, time.time()))
75 raise TestException(msg)
79 raise TestException(msg)
76
80
77 @view_config(
81 @view_config(
78 route_name='ops_redirect_test', request_method='GET',
82 route_name='ops_redirect_test', request_method='GET',
79 renderer='json_ext')
83 renderer='json_ext')
80 def ops_redirect_test(self):
84 def ops_redirect_test(self):
81 """
85 """
82 Test redirect handling
86 Test redirect handling
83 """
87 """
84 redirect_to = self.request.GET.get('to') or h.route_path('home')
88 redirect_to = self.request.GET.get('to') or h.route_path('home')
85 raise HTTPFound(redirect_to)
89 raise HTTPFound(redirect_to)
General Comments 0
You need to be logged in to leave comments. Login now