##// END OF EJS Templates
fix(bootstrap): fixed issues that lead to leaving rhodecode.local as a default setting which is now explicitly read from .ini config
super-admin -
r5430:2f6a1e33 default
parent child Browse files
Show More
@@ -1,104 +1,107 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 DEFAULT_USER = 'default'
23
22 24
23 25 def configure_vcs(config):
24 26 """
25 27 Patch VCS config with some RhodeCode specific stuff
26 28 """
27 29 from rhodecode.lib.vcs import conf
28 30 import rhodecode.lib.vcs.conf.settings
29 31
30 32 conf.settings.BACKENDS = {
31 33 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository',
32 34 'git': 'rhodecode.lib.vcs.backends.git.GitRepository',
33 35 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository',
34 36 }
35 37
36 38 conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol']
37 39 conf.settings.HOOKS_HOST = config['vcs.hooks.host']
38 40 conf.settings.DEFAULT_ENCODINGS = config['default_encoding']
39 41 conf.settings.ALIASES[:] = config['vcs.backends']
40 42 conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version']
41 43
42 44
43 45 def initialize_database(config):
44 46 from rhodecode.lib.utils2 import engine_from_config, get_encryption_key
45 47 from rhodecode.model import init_model
46 48 engine = engine_from_config(config, 'sqlalchemy.db1.')
47 49 init_model(engine, encryption_key=get_encryption_key(config))
48 50
49 51
50 52 def initialize_test_environment(settings, test_env=None):
51 53 if test_env is None:
52 54 test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0))
53 55
54 56 from rhodecode.lib.utils import (
55 57 create_test_directory, create_test_database, create_test_repositories,
56 58 create_test_index)
57 59 from rhodecode.tests import TESTS_TMP_PATH
58 60 from rhodecode.lib.vcs.backends.hg import largefiles_store
59 61 from rhodecode.lib.vcs.backends.git import lfs_store
60 62
61 63 # test repos
62 64 if test_env:
63 65 create_test_directory(TESTS_TMP_PATH)
64 66 # large object stores
65 67 create_test_directory(largefiles_store(TESTS_TMP_PATH))
66 68 create_test_directory(lfs_store(TESTS_TMP_PATH))
67 69
68 70 create_test_database(TESTS_TMP_PATH, settings)
69 71 create_test_repositories(TESTS_TMP_PATH, settings)
70 72 create_test_index(TESTS_TMP_PATH, settings)
71 73
72 74
73 75 def get_vcs_server_protocol(config):
74 76 return config['vcs.server.protocol']
75 77
76 78
77 79 def set_instance_id(config):
78 80 """
79 81 Sets a dynamic generated config['instance_id'] if missing or '*'
80 82 E.g instance_id = *cluster-1 or instance_id = *
81 83 """
82 84
83 85 config['instance_id'] = config.get('instance_id') or ''
84 86 instance_id = config['instance_id']
85 87 if instance_id.startswith('*') or not instance_id:
86 88 prefix = instance_id.lstrip('*')
87 89 _platform_id = platform.uname()[1] or 'instance'
88 90 config['instance_id'] = '{prefix}uname:{platform}-pid:{pid}'.format(
89 91 prefix=prefix,
90 92 platform=_platform_id,
91 93 pid=os.getpid())
92 94
93 95
94 96 def get_default_user_id():
95 DEFAULT_USER = 'default'
96 97 from sqlalchemy import text
97 98 from rhodecode.model import meta
98 99
99 100 engine = meta.get_engine()
100 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 105 user_id = result.first()[0]
103 106
104 107 return user_id
@@ -1,57 +1,53 b''
1 1
2 2
3 3 # Copyright (C) 2016-2023 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 import configparser
23 22
24 from rhodecode.lib.config_utils import get_config
25 23 from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover
26 24 from pyramid.threadlocal import get_current_request as pyramid_current_request
27 25
28 26
29 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 30 from rhodecode.lib.utils2 import AttributeDict
31 31 from rhodecode.lib.request import Request
32 32
33 33 if env:
34 34 os.environ.update(env)
35 35
36 config = get_config(config_uri)
37 base_url = 'http://rhodecode.local'
38 try:
39 base_url = config.get('app:main', 'app.base_url')
40 except (configparser.NoSectionError, configparser.NoOptionError):
41 pass
36 config = get_app_config_lightweight(config_uri)
37 base_url = config['app.base_url']
42 38
43 39 request = Request.blank('/', base_url=base_url)
44 40 # fake inject a running user for bootstrap request !
45 request.user = AttributeDict({'username': 'bootstrap-user',
41 request.user = AttributeDict({'username': DEFAULT_USER,
46 42 'user_id': 1,
47 43 'ip_addr': '127.0.0.1'})
48 44 return pyramid_bootstrap(config_uri, request=request, options=options)
49 45
50 46
51 47 def get_current_request():
52 48 pyramid_req = pyramid_current_request()
53 49 if not pyramid_req:
54 50 # maybe we're in celery context and need to get the PYRAMID_REQUEST
55 51 from rhodecode.lib.celerylib.loader import celery_app
56 52 pyramid_req = celery_app.conf['PYRAMID_REQUEST']
57 53 return pyramid_req
General Comments 0
You need to be logged in to leave comments. Login now