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