Show More
@@ -1,97 +1,96 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import time |
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | from pyramid.httpexceptions import HTTPFound |
|
26 | 26 | |
|
27 | 27 | from rhodecode.apps._base import BaseAppView |
|
28 | 28 | from rhodecode.lib import helpers as h |
|
29 | 29 | from rhodecode.lib.auth import LoginRequired |
|
30 | from rhodecode.lib.compat import OrderedDict | |
|
30 | 31 | from rhodecode.model.db import UserApiKeys |
|
31 | 32 | |
|
32 | 33 | log = logging.getLogger(__name__) |
|
33 | 34 | |
|
34 | 35 | |
|
35 | 36 | class OpsView(BaseAppView): |
|
36 | 37 | |
|
37 | 38 | def load_default_context(self): |
|
38 | 39 | c = self._get_local_tmpl_context() |
|
39 | 40 | c.user = c.auth_user.get_instance() |
|
40 | 41 | |
|
41 | 42 | return c |
|
42 | 43 | |
|
43 | 44 | def ops_ping(self): |
|
44 |
data = |
|
|
45 |
|
|
|
46 | } | |
|
45 | data = OrderedDict() | |
|
46 | data['instance'] = self.request.registry.settings.get('instance_id') | |
|
47 | ||
|
47 | 48 | if getattr(self.request, 'user'): |
|
48 | 49 | caller_name = 'anonymous' |
|
49 | 50 | if self.request.user.user_id: |
|
50 | 51 | caller_name = self.request.user.username |
|
51 | 52 | |
|
52 | data.update({ | |
|
53 | 'caller_ip': self.request.user.ip_addr, | |
|
54 | 'caller_name': caller_name, | |
|
55 | }) | |
|
53 | data['caller_ip'] = self.request.user.ip_addr | |
|
54 | data['caller_name'] = caller_name | |
|
55 | ||
|
56 | 56 | return {'ok': data} |
|
57 | 57 | |
|
58 | 58 | def ops_error_test(self): |
|
59 | 59 | """ |
|
60 | 60 | Test exception handling and emails on errors |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | class TestException(Exception): |
|
64 | 64 | pass |
|
65 | 65 | # add timeout so we add some sort of rate limiter |
|
66 | 66 | time.sleep(2) |
|
67 | 67 | msg = ('RhodeCode Enterprise test exception. ' |
|
68 | 68 | 'Client:{}. Generation time: {}.'.format(self.request.user, time.time())) |
|
69 | 69 | raise TestException(msg) |
|
70 | 70 | |
|
71 | 71 | def ops_redirect_test(self): |
|
72 | 72 | """ |
|
73 | 73 | Test redirect handling |
|
74 | 74 | """ |
|
75 | 75 | redirect_to = self.request.GET.get('to') or h.route_path('home') |
|
76 | 76 | raise HTTPFound(redirect_to) |
|
77 | 77 | |
|
78 | 78 | @LoginRequired(auth_token_access=[UserApiKeys.ROLE_HTTP]) |
|
79 | 79 | def ops_healthcheck(self): |
|
80 | 80 | from rhodecode.lib.system_info import load_system_info |
|
81 | 81 | |
|
82 | 82 | vcsserver_info = load_system_info('vcs_server') |
|
83 | 83 | if vcsserver_info: |
|
84 | 84 | vcsserver_info = vcsserver_info['human_value'] |
|
85 | 85 | |
|
86 | 86 | db_info = load_system_info('database_info') |
|
87 | 87 | if db_info: |
|
88 | 88 | db_info = db_info['human_value'] |
|
89 | 89 | |
|
90 | 90 | health_spec = { |
|
91 | 91 | 'caller_ip': self.request.user.ip_addr, |
|
92 | 92 | 'vcsserver': vcsserver_info, |
|
93 | 93 | 'db': db_info, |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | return {'healthcheck': health_spec} |
|
97 |
@@ -1,101 +1,104 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | import platform |
|
23 | 23 | |
|
24 | 24 | from rhodecode.model import init_model |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | def configure_vcs(config): |
|
28 | 28 | """ |
|
29 | 29 | Patch VCS config with some RhodeCode specific stuff |
|
30 | 30 | """ |
|
31 | 31 | from rhodecode.lib.vcs import conf |
|
32 | 32 | import rhodecode.lib.vcs.conf.settings |
|
33 | 33 | |
|
34 | 34 | conf.settings.BACKENDS = { |
|
35 | 35 | 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository', |
|
36 | 36 | 'git': 'rhodecode.lib.vcs.backends.git.GitRepository', |
|
37 | 37 | 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository', |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol'] |
|
41 | 41 | conf.settings.HOOKS_HOST = config['vcs.hooks.host'] |
|
42 | 42 | conf.settings.HOOKS_DIRECT_CALLS = config['vcs.hooks.direct_calls'] |
|
43 | 43 | conf.settings.DEFAULT_ENCODINGS = config['default_encoding'] |
|
44 | 44 | conf.settings.ALIASES[:] = config['vcs.backends'] |
|
45 | 45 | conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version'] |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def initialize_database(config): |
|
49 | 49 | from rhodecode.lib.utils2 import engine_from_config, get_encryption_key |
|
50 | 50 | engine = engine_from_config(config, 'sqlalchemy.db1.') |
|
51 | 51 | init_model(engine, encryption_key=get_encryption_key(config)) |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | def initialize_test_environment(settings, test_env=None): |
|
55 | 55 | if test_env is None: |
|
56 | 56 | test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) |
|
57 | 57 | |
|
58 | 58 | from rhodecode.lib.utils import ( |
|
59 | 59 | create_test_directory, create_test_database, create_test_repositories, |
|
60 | 60 | create_test_index) |
|
61 | 61 | from rhodecode.tests import TESTS_TMP_PATH |
|
62 | 62 | from rhodecode.lib.vcs.backends.hg import largefiles_store |
|
63 | 63 | from rhodecode.lib.vcs.backends.git import lfs_store |
|
64 | 64 | |
|
65 | 65 | # test repos |
|
66 | 66 | if test_env: |
|
67 | 67 | create_test_directory(TESTS_TMP_PATH) |
|
68 | 68 | # large object stores |
|
69 | 69 | create_test_directory(largefiles_store(TESTS_TMP_PATH)) |
|
70 | 70 | create_test_directory(lfs_store(TESTS_TMP_PATH)) |
|
71 | 71 | |
|
72 | 72 | create_test_database(TESTS_TMP_PATH, settings) |
|
73 | 73 | create_test_repositories(TESTS_TMP_PATH, settings) |
|
74 | 74 | create_test_index(TESTS_TMP_PATH, settings) |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | def get_vcs_server_protocol(config): |
|
78 | 78 | return config['vcs.server.protocol'] |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | def set_instance_id(config): |
|
82 | 82 | """ |
|
83 | 83 | Sets a dynamic generated config['instance_id'] if missing or '*' |
|
84 | 84 | E.g instance_id = *cluster-1 or instance_id = * |
|
85 | 85 | """ |
|
86 | 86 | |
|
87 | 87 | config['instance_id'] = config.get('instance_id') or '' |
|
88 | 88 | instance_id = config['instance_id'] |
|
89 | 89 | if instance_id.startswith('*') or not instance_id: |
|
90 | 90 | prefix = instance_id.lstrip('*') |
|
91 | 91 | _platform_id = platform.uname()[1] or 'instance' |
|
92 |
config['instance_id'] = ' |
|
|
92 | config['instance_id'] = '{prefix}uname:{platform}-pid:{pid}'.format( | |
|
93 | prefix=prefix, | |
|
94 | platform=_platform_id, | |
|
95 | pid=os.getpid()) | |
|
93 | 96 | |
|
94 | 97 | |
|
95 | 98 | def get_default_user_id(): |
|
96 | 99 | from rhodecode.model.db import User, Session |
|
97 | 100 | user_id = Session()\ |
|
98 | 101 | .query(User.user_id)\ |
|
99 | 102 | .filter(User.username == User.DEFAULT_USER)\ |
|
100 | 103 | .scalar() |
|
101 | 104 | return user_id |
General Comments 0
You need to be logged in to leave comments.
Login now