Show More
@@ -1,104 +1,107 b'' | |||||
1 | # Copyright (C) 2010-2023 RhodeCode GmbH |
|
1 | # Copyright (C) 2010-2023 RhodeCode GmbH | |
2 | # |
|
2 | # | |
3 | # This program is free software: you can redistribute it and/or modify |
|
3 | # This program is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
5 | # (only), as published by the Free Software Foundation. |
|
5 | # (only), as published by the Free Software Foundation. | |
6 | # |
|
6 | # | |
7 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
11 | # |
|
11 | # | |
12 | # You should have received a copy of the GNU Affero General Public License |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | # |
|
14 | # | |
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import os |
|
19 | import os | |
20 | import platform |
|
20 | import platform | |
21 |
|
21 | |||
|
22 | DEFAULT_USER = 'default' | |||
|
23 | ||||
22 |
|
24 | |||
23 | def configure_vcs(config): |
|
25 | def configure_vcs(config): | |
24 | """ |
|
26 | """ | |
25 | Patch VCS config with some RhodeCode specific stuff |
|
27 | Patch VCS config with some RhodeCode specific stuff | |
26 | """ |
|
28 | """ | |
27 | from rhodecode.lib.vcs import conf |
|
29 | from rhodecode.lib.vcs import conf | |
28 | import rhodecode.lib.vcs.conf.settings |
|
30 | import rhodecode.lib.vcs.conf.settings | |
29 |
|
31 | |||
30 | conf.settings.BACKENDS = { |
|
32 | conf.settings.BACKENDS = { | |
31 | 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository', |
|
33 | 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository', | |
32 | 'git': 'rhodecode.lib.vcs.backends.git.GitRepository', |
|
34 | 'git': 'rhodecode.lib.vcs.backends.git.GitRepository', | |
33 | 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository', |
|
35 | 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository', | |
34 | } |
|
36 | } | |
35 |
|
37 | |||
36 | conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol'] |
|
38 | conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol'] | |
37 | conf.settings.HOOKS_HOST = config['vcs.hooks.host'] |
|
39 | conf.settings.HOOKS_HOST = config['vcs.hooks.host'] | |
38 | conf.settings.DEFAULT_ENCODINGS = config['default_encoding'] |
|
40 | conf.settings.DEFAULT_ENCODINGS = config['default_encoding'] | |
39 | conf.settings.ALIASES[:] = config['vcs.backends'] |
|
41 | conf.settings.ALIASES[:] = config['vcs.backends'] | |
40 | conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version'] |
|
42 | conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version'] | |
41 |
|
43 | |||
42 |
|
44 | |||
43 | def initialize_database(config): |
|
45 | def initialize_database(config): | |
44 | from rhodecode.lib.utils2 import engine_from_config, get_encryption_key |
|
46 | from rhodecode.lib.utils2 import engine_from_config, get_encryption_key | |
45 | from rhodecode.model import init_model |
|
47 | from rhodecode.model import init_model | |
46 | engine = engine_from_config(config, 'sqlalchemy.db1.') |
|
48 | engine = engine_from_config(config, 'sqlalchemy.db1.') | |
47 | init_model(engine, encryption_key=get_encryption_key(config)) |
|
49 | init_model(engine, encryption_key=get_encryption_key(config)) | |
48 |
|
50 | |||
49 |
|
51 | |||
50 | def initialize_test_environment(settings, test_env=None): |
|
52 | def initialize_test_environment(settings, test_env=None): | |
51 | if test_env is None: |
|
53 | if test_env is None: | |
52 | test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) |
|
54 | test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) | |
53 |
|
55 | |||
54 | from rhodecode.lib.utils import ( |
|
56 | from rhodecode.lib.utils import ( | |
55 | create_test_directory, create_test_database, create_test_repositories, |
|
57 | create_test_directory, create_test_database, create_test_repositories, | |
56 | create_test_index) |
|
58 | create_test_index) | |
57 | from rhodecode.tests import TESTS_TMP_PATH |
|
59 | from rhodecode.tests import TESTS_TMP_PATH | |
58 | from rhodecode.lib.vcs.backends.hg import largefiles_store |
|
60 | from rhodecode.lib.vcs.backends.hg import largefiles_store | |
59 | from rhodecode.lib.vcs.backends.git import lfs_store |
|
61 | from rhodecode.lib.vcs.backends.git import lfs_store | |
60 |
|
62 | |||
61 | # test repos |
|
63 | # test repos | |
62 | if test_env: |
|
64 | if test_env: | |
63 | create_test_directory(TESTS_TMP_PATH) |
|
65 | create_test_directory(TESTS_TMP_PATH) | |
64 | # large object stores |
|
66 | # large object stores | |
65 | create_test_directory(largefiles_store(TESTS_TMP_PATH)) |
|
67 | create_test_directory(largefiles_store(TESTS_TMP_PATH)) | |
66 | create_test_directory(lfs_store(TESTS_TMP_PATH)) |
|
68 | create_test_directory(lfs_store(TESTS_TMP_PATH)) | |
67 |
|
69 | |||
68 | create_test_database(TESTS_TMP_PATH, settings) |
|
70 | create_test_database(TESTS_TMP_PATH, settings) | |
69 | create_test_repositories(TESTS_TMP_PATH, settings) |
|
71 | create_test_repositories(TESTS_TMP_PATH, settings) | |
70 | create_test_index(TESTS_TMP_PATH, settings) |
|
72 | create_test_index(TESTS_TMP_PATH, settings) | |
71 |
|
73 | |||
72 |
|
74 | |||
73 | def get_vcs_server_protocol(config): |
|
75 | def get_vcs_server_protocol(config): | |
74 | return config['vcs.server.protocol'] |
|
76 | return config['vcs.server.protocol'] | |
75 |
|
77 | |||
76 |
|
78 | |||
77 | def set_instance_id(config): |
|
79 | def set_instance_id(config): | |
78 | """ |
|
80 | """ | |
79 | Sets a dynamic generated config['instance_id'] if missing or '*' |
|
81 | Sets a dynamic generated config['instance_id'] if missing or '*' | |
80 | E.g instance_id = *cluster-1 or instance_id = * |
|
82 | E.g instance_id = *cluster-1 or instance_id = * | |
81 | """ |
|
83 | """ | |
82 |
|
84 | |||
83 | config['instance_id'] = config.get('instance_id') or '' |
|
85 | config['instance_id'] = config.get('instance_id') or '' | |
84 | instance_id = config['instance_id'] |
|
86 | instance_id = config['instance_id'] | |
85 | if instance_id.startswith('*') or not instance_id: |
|
87 | if instance_id.startswith('*') or not instance_id: | |
86 | prefix = instance_id.lstrip('*') |
|
88 | prefix = instance_id.lstrip('*') | |
87 | _platform_id = platform.uname()[1] or 'instance' |
|
89 | _platform_id = platform.uname()[1] or 'instance' | |
88 | config['instance_id'] = '{prefix}uname:{platform}-pid:{pid}'.format( |
|
90 | config['instance_id'] = '{prefix}uname:{platform}-pid:{pid}'.format( | |
89 | prefix=prefix, |
|
91 | prefix=prefix, | |
90 | platform=_platform_id, |
|
92 | platform=_platform_id, | |
91 | pid=os.getpid()) |
|
93 | pid=os.getpid()) | |
92 |
|
94 | |||
93 |
|
95 | |||
94 | def get_default_user_id(): |
|
96 | def get_default_user_id(): | |
95 | DEFAULT_USER = 'default' |
|
|||
96 | from sqlalchemy import text |
|
97 | from sqlalchemy import text | |
97 | from rhodecode.model import meta |
|
98 | from rhodecode.model import meta | |
98 |
|
99 | |||
99 | engine = meta.get_engine() |
|
100 | engine = meta.get_engine() | |
100 | with meta.SA_Session(engine) as session: |
|
101 | with meta.SA_Session(engine) as session: | |
101 | result = session.execute(text("SELECT user_id from users where username = :uname"), {'uname': DEFAULT_USER}) |
|
102 | result = session.execute(text( | |
|
103 | "SELECT user_id from users where username = :uname" | |||
|
104 | ), {'uname': DEFAULT_USER}) | |||
102 | user_id = result.first()[0] |
|
105 | user_id = result.first()[0] | |
103 |
|
106 | |||
104 | return user_id |
|
107 | return user_id |
@@ -1,57 +1,53 b'' | |||||
1 |
|
1 | |||
2 |
|
2 | |||
3 | # Copyright (C) 2016-2023 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2023 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 os |
|
21 | import os | |
22 | import configparser |
|
|||
23 |
|
22 | |||
24 | from rhodecode.lib.config_utils import get_config |
|
|||
25 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover |
|
23 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover | |
26 | from pyramid.threadlocal import get_current_request as pyramid_current_request |
|
24 | from pyramid.threadlocal import get_current_request as pyramid_current_request | |
27 |
|
25 | |||
28 |
|
26 | |||
29 | def bootstrap(config_uri, options=None, env=None): |
|
27 | def bootstrap(config_uri, options=None, env=None): | |
|
28 | from rhodecode.config.utils import DEFAULT_USER | |||
|
29 | from rhodecode.lib.config_utils import get_app_config_lightweight | |||
30 | from rhodecode.lib.utils2 import AttributeDict |
|
30 | from rhodecode.lib.utils2 import AttributeDict | |
31 | from rhodecode.lib.request import Request |
|
31 | from rhodecode.lib.request import Request | |
32 |
|
32 | |||
33 | if env: |
|
33 | if env: | |
34 | os.environ.update(env) |
|
34 | os.environ.update(env) | |
35 |
|
35 | |||
36 | config = get_config(config_uri) |
|
36 | config = get_app_config_lightweight(config_uri) | |
37 | base_url = 'http://rhodecode.local' |
|
37 | base_url = config['app.base_url'] | |
38 | try: |
|
|||
39 | base_url = config.get('app:main', 'app.base_url') |
|
|||
40 | except (configparser.NoSectionError, configparser.NoOptionError): |
|
|||
41 | pass |
|
|||
42 |
|
38 | |||
43 | request = Request.blank('/', base_url=base_url) |
|
39 | request = Request.blank('/', base_url=base_url) | |
44 | # fake inject a running user for bootstrap request ! |
|
40 | # fake inject a running user for bootstrap request ! | |
45 |
request.user = AttributeDict({'username': |
|
41 | request.user = AttributeDict({'username': DEFAULT_USER, | |
46 | 'user_id': 1, |
|
42 | 'user_id': 1, | |
47 | 'ip_addr': '127.0.0.1'}) |
|
43 | 'ip_addr': '127.0.0.1'}) | |
48 | return pyramid_bootstrap(config_uri, request=request, options=options) |
|
44 | return pyramid_bootstrap(config_uri, request=request, options=options) | |
49 |
|
45 | |||
50 |
|
46 | |||
51 | def get_current_request(): |
|
47 | def get_current_request(): | |
52 | pyramid_req = pyramid_current_request() |
|
48 | pyramid_req = pyramid_current_request() | |
53 | if not pyramid_req: |
|
49 | if not pyramid_req: | |
54 | # maybe we're in celery context and need to get the PYRAMID_REQUEST |
|
50 | # maybe we're in celery context and need to get the PYRAMID_REQUEST | |
55 | from rhodecode.lib.celerylib.loader import celery_app |
|
51 | from rhodecode.lib.celerylib.loader import celery_app | |
56 | pyramid_req = celery_app.conf['PYRAMID_REQUEST'] |
|
52 | pyramid_req = celery_app.conf['PYRAMID_REQUEST'] | |
57 | return pyramid_req |
|
53 | return pyramid_req |
General Comments 0
You need to be logged in to leave comments.
Login now