##// END OF EJS Templates
feat(repo_path-config): moved main storage location path into ini file. Fixes: RCCE-61
ilin.s -
r5356:99a91100 default
parent child Browse files
Show More
@@ -261,8 +261,8 b' auth_ret_code_detection = false'
261 261 ; codes don't break the transactions while 4XX codes do
262 262 lock_ret_code = 423
263 263
264 ; allows to change the repository location in settings page
265 allow_repo_location_change = true
264 ; Filesystem location were repositories should be stored
265 repo_store.path = /var/opt/rhodecode_repo_store
266 266
267 267 ; allows to setup custom hooks in settings page
268 268 allow_custom_hooks_settings = true
@@ -212,8 +212,8 b' auth_ret_code_detection = false'
212 212 ; codes don't break the transactions while 4XX codes do
213 213 lock_ret_code = 423
214 214
215 ; allows to change the repository location in settings page
216 allow_repo_location_change = true
215 ; Filesystem location were repositories should be stored
216 repo_store.path = /var/opt/rhodecode_repo_store
217 217
218 218 ; allows to setup custom hooks in settings page
219 219 allow_custom_hooks_settings = true
@@ -25,7 +25,7 b' from rhodecode.api import ('
25 25
26 26 from rhodecode.api.utils import (
27 27 Optional, OAttr, has_superadmin_permission, get_user_or_error)
28 from rhodecode.lib.utils import repo2db_mapper
28 from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_repo_store_path
29 29 from rhodecode.lib import system_info
30 30 from rhodecode.lib import user_sessions
31 31 from rhodecode.lib import exc_tracking
@@ -33,7 +33,6 b' from rhodecode.lib.ext_json import json'
33 33 from rhodecode.lib.utils2 import safe_int
34 34 from rhodecode.model.db import UserIpMap
35 35 from rhodecode.model.scm import ScmModel
36 from rhodecode.model.settings import VcsSettingsModel
37 36 from rhodecode.apps.file_store import utils
38 37 from rhodecode.apps.file_store.exceptions import FileNotAllowedException, \
39 38 FileOverSizeException
@@ -103,7 +102,7 b' def get_repo_store(request, apiuser):'
103 102 if not has_superadmin_permission(apiuser):
104 103 raise JSONRPCForbidden()
105 104
106 path = VcsSettingsModel().get_repos_location()
105 path = get_rhodecode_repo_store_path()
107 106 return {"path": path}
108 107
109 108
@@ -38,7 +38,7 b' from rhodecode.lib.auth import ('
38 38 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
39 39 from rhodecode.lib.celerylib import tasks, run_task
40 40 from rhodecode.lib.str_utils import safe_str
41 from rhodecode.lib.utils import repo2db_mapper
41 from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_repo_store_path
42 42 from rhodecode.lib.utils2 import str2bool, AttributeDict
43 43 from rhodecode.lib.index import searcher_from_config
44 44
@@ -167,9 +167,6 b' class AdminSettingsView(BaseAppView):'
167 167 return Response(html)
168 168
169 169 try:
170 if c.visual.allow_repo_location_change:
171 model.update_global_path_setting(form_result['paths_root_path'])
172
173 170 model.update_global_ssl_setting(form_result['web_push_ssl'])
174 171 model.update_global_hook_settings(form_result)
175 172
@@ -217,7 +214,7 b' class AdminSettingsView(BaseAppView):'
217 214 def settings_mapping(self):
218 215 c = self.load_default_context()
219 216 c.active = 'mapping'
220 c.storage_path = VcsSettingsModel().get_repos_location()
217 c.storage_path = get_rhodecode_repo_store_path()
221 218 data = render('rhodecode:templates/admin/settings/settings.mako',
222 219 self._get_template_context(c), self.request)
223 220 html = formencode.htmlfill.render(
@@ -22,7 +22,7 b' import os'
22 22 from pyramid.renderers import render
23 23
24 24 from rhodecode.events import trigger
25 from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
25 from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_repo_store_path
26 26 from rhodecode.lib.utils2 import str2bool
27 27 from rhodecode.model.db import RepoGroup
28 28
@@ -38,7 +38,7 b' def write_mod_dav_svn_config(settings):'
38 38 file_path = settings[config_keys.config_file_path]
39 39 config = _render_mod_dav_svn_config(
40 40 use_ssl=use_ssl,
41 parent_path_root=get_rhodecode_base_path(),
41 parent_path_root=get_rhodecode_repo_store_path(),
42 42 list_parent_path=settings[config_keys.list_parent_path],
43 43 location_root=settings[config_keys.location_root],
44 44 repo_groups=RepoGroup.get_all_repo_groups(),
@@ -117,6 +117,8 b' def sanitize_settings_and_apply_defaults'
117 117
118 118 settings_maker.make_setting('vcs.methods.cache', True, parser='bool')
119 119
120 # repo_store path
121 settings_maker.make_setting('repo_store.path', '/var/opt/rhodecode_repo_store')
120 122 # Support legacy values of vcs.scm_app_implementation. Legacy
121 123 # configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or
122 124 # disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'.
@@ -81,7 +81,6 b' def load_pyramid_environment(global_conf'
81 81 rhodecode.PYRAMID_SETTINGS = settings_merged
82 82 rhodecode.CONFIG = settings_merged
83 83 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
84 rhodecode.CONFIG['default_base_path'] = utils.get_default_base_path()
85 84
86 85 if vcs_server_enabled:
87 86 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
@@ -102,15 +102,3 b' def get_default_user_id():'
102 102 user_id = result.first()[0]
103 103
104 104 return user_id
105
106
107 def get_default_base_path():
108 from sqlalchemy import text
109 from rhodecode.model import meta
110
111 engine = meta.get_engine()
112 with meta.SA_Session(engine) as session:
113 result = session.execute(text("SELECT ui_value from rhodecode_ui where ui_key = '/'"))
114 base_path = result.first()[0]
115
116 return base_path
@@ -347,8 +347,6 b' def attach_context_attributes(context, r'
347 347 context.ssh_key_generator_enabled = str2bool(
348 348 config.get('ssh.enable_ui_key_generator', 'true'))
349 349
350 context.visual.allow_repo_location_change = str2bool(
351 config.get('allow_repo_location_change', True))
352 350 context.visual.allow_custom_hooks_settings = str2bool(
353 351 config.get('allow_custom_hooks_settings', True))
354 352 context.debug_style = str2bool(config.get('debug_style', False))
@@ -156,17 +156,10 b' class SimpleVCS(object):'
156 156
157 157 @property
158 158 def base_path(self):
159 settings_path = self.repo_vcs_config.get(*VcsSettingsModel.PATH_SETTING)
160
161 if not settings_path:
162 settings_path = self.global_vcs_config.get(*VcsSettingsModel.PATH_SETTING)
159 settings_path = self.config.get('repo_store.path')
163 160
164 161 if not settings_path:
165 # try, maybe we passed in explicitly as config option
166 settings_path = self.config.get('base_path')
167
168 if not settings_path:
169 raise ValueError('FATAL: base_path is empty')
162 raise ValueError('FATAL: repo_store.path is empty')
170 163 return settings_path
171 164
172 165 def set_repo_names(self, environ):
@@ -331,8 +331,8 b' def cpu():'
331 331 @register_sysinfo
332 332 def storage():
333 333 from rhodecode.lib.helpers import format_byte_size_binary
334 from rhodecode.model.settings import VcsSettingsModel
335 path = VcsSettingsModel().get_repos_location()
334 from rhodecode.lib.utils import get_rhodecode_repo_store_path
335 path = get_rhodecode_repo_store_path()
336 336
337 337 value = dict(percent=0, used=0, total=0, path=path, text='')
338 338 state = STATE_OK_DEFAULT
@@ -364,8 +364,8 b' def storage():'
364 364
365 365 @register_sysinfo
366 366 def storage_inodes():
367 from rhodecode.model.settings import VcsSettingsModel
368 path = VcsSettingsModel().get_repos_location()
367 from rhodecode.lib.utils import get_rhodecode_repo_store_path
368 path = get_rhodecode_repo_store_path()
369 369
370 370 value = dict(percent=0.0, free=0, used=0, total=0, path=path, text='')
371 371 state = STATE_OK_DEFAULT
@@ -442,11 +442,10 b' def storage_archives():'
442 442 @register_sysinfo
443 443 def storage_gist():
444 444 from rhodecode.model.gist import GIST_STORE_LOC
445 from rhodecode.model.settings import VcsSettingsModel
446 from rhodecode.lib.utils import safe_str
445 from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
447 446 from rhodecode.lib.helpers import format_byte_size_binary
448 447 path = safe_str(os.path.join(
449 VcsSettingsModel().get_repos_location(), GIST_STORE_LOC))
448 get_rhodecode_repo_store_path(), GIST_STORE_LOC))
450 449
451 450 # gist storage
452 451 value = dict(percent=0, used=0, total=0, items=0, path=path, text='')
@@ -472,14 +472,14 b' def get_rhodecode_realm():'
472 472 return safe_str(realm.app_settings_value)
473 473
474 474
475 def get_rhodecode_base_path():
475 def get_rhodecode_repo_store_path():
476 476 """
477 477 Returns the base path. The base path is the filesystem path which points
478 478 to the repository store.
479 479 """
480 480
481 481 import rhodecode
482 return rhodecode.CONFIG['default_base_path']
482 return rhodecode.CONFIG['repo_store.path']
483 483
484 484
485 485 def map_groups(path):
@@ -21,6 +21,7 b' import logging'
21 21
22 22 import rhodecode
23 23 from rhodecode.model import meta, db
24 from rhodecode.lib.utils import get_rhodecode_repo_store_path
24 25 from rhodecode.lib.utils2 import obfuscate_url_pw, get_encryption_key
25 26
26 27 log = logging.getLogger(__name__)
@@ -138,3 +139,11 b' class BaseModel(object):'
138 139 Returns all instances of what is defined in `cls` class variable
139 140 """
140 141 return cls.cls.getAll()
142
143 @property
144 def repos_path(self):
145 """
146 Gets the repositories root path from *ini file
147 """
148
149 return get_rhodecode_repo_store_path()
@@ -1942,8 +1942,8 b' class Repository(Base, BaseModel):'
1942 1942
1943 1943 :param cls:
1944 1944 """
1945 from rhodecode.lib.utils import get_rhodecode_base_path
1946 return get_rhodecode_base_path()
1945 from rhodecode.lib.utils import get_rhodecode_repo_store_path
1946 return get_rhodecode_repo_store_path()
1947 1947
1948 1948 @classmethod
1949 1949 def get_all_repos(cls, user_id=Optional(None), group_id=Optional(None),
@@ -2009,16 +2009,13 b' class Repository(Base, BaseModel):'
2009 2009 def groups_and_repo(self):
2010 2010 return self.groups_with_parents, self
2011 2011
2012 @LazyProperty
2012 @property
2013 2013 def repo_path(self):
2014 2014 """
2015 2015 Returns base full path for that repository means where it actually
2016 2016 exists on a filesystem
2017 2017 """
2018 q = Session().query(RhodeCodeUi).filter(
2019 RhodeCodeUi.ui_key == self.NAME_SEP)
2020 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
2021 return q.one().ui_value
2018 return self.base_path()
2022 2019
2023 2020 @property
2024 2021 def repo_full_path(self):
@@ -434,10 +434,6 b' def ApplicationUiSettingsForm(localizer)'
434 434
435 435 class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
436 436 web_push_ssl = v.StringBoolean(if_missing=False)
437 paths_root_path = All(
438 v.ValidPath(localizer),
439 v.UnicodeString(strip=True, min=1, not_empty=True)
440 )
441 437 largefiles_usercache = All(
442 438 v.ValidPath(localizer),
443 439 v.UnicodeString(strip=True, min=2, not_empty=True))
@@ -83,14 +83,6 b' class RepoModel(BaseModel):'
83 83
84 84 return repo_to_perm
85 85
86 @LazyProperty
87 def repos_path(self):
88 """
89 Gets the repositories root path from database
90 """
91 settings_model = VcsSettingsModel(sa=self.sa)
92 return settings_model.get_repos_location()
93
94 86 def get(self, repo_id):
95 87 repo = self.sa.query(Repository) \
96 88 .filter(Repository.repo_id == repo_id)
@@ -62,15 +62,6 b' class RepoGroupModel(BaseModel):'
62 62 def get_repo_group(self, repo_group):
63 63 return self._get_repo_group(repo_group)
64 64
65 @LazyProperty
66 def repos_path(self):
67 """
68 Gets the repositories root path from database
69 """
70
71 settings_model = VcsSettingsModel(sa=self.sa)
72 return settings_model.get_repos_location()
73
74 65 def get_by_group_name(self, repo_group_name, cache=None):
75 66 repo = self.sa.query(RepoGroup) \
76 67 .filter(RepoGroup.group_name == repo_group_name)
@@ -189,15 +189,6 b' class ScmModel(BaseModel):'
189 189 Generic Scm Model
190 190 """
191 191
192 @LazyProperty
193 def repos_path(self):
194 """
195 Gets the repositories root path from database
196 """
197
198 settings_model = VcsSettingsModel(sa=self.sa)
199 return settings_model.get_repos_location()
200
201 192 def repo_scan(self, repos_path=None):
202 193 """
203 194 Listing of repositories in given path. This path should not be a
@@ -811,9 +811,6 b' class VcsSettingsModel(object):'
811 811 else:
812 812 return self.get_repo_general_settings()
813 813
814 def get_repos_location(self):
815 return self.global_settings.get_ui_by_key('/').ui_value
816
817 814 def _filter_ui_settings(self, settings):
818 815 filtered_settings = [
819 816 s for s in settings if self._should_keep_setting(s)]
@@ -116,8 +116,9 b' def scan_repositories_if_enabled(event):'
116 116 import_on_startup = settings['startup.import_repos']
117 117 if vcs_server_enabled and import_on_startup:
118 118 from rhodecode.model.scm import ScmModel
119 from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_base_path
120 repositories = ScmModel().repo_scan(get_rhodecode_base_path())
119 from rhodecode.lib.utils import repo2db_mapper
120 scm = ScmModel()
121 repositories = scm.repo_scan(scm.repos_path)
121 122 repo2db_mapper(repositories, remove_obsolete=False)
122 123
123 124
@@ -6,8 +6,7 b''
6 6 suffix='',
7 7 svn_tag_patterns=c.svn_tag_patterns,
8 8 svn_branch_patterns=c.svn_branch_patterns,
9 display_globals=True,
10 allow_repo_location_change=c.visual.allow_repo_location_change
9 display_globals=True
11 10 )}
12 11 <div class="buttons">
13 12 ${h.submit('save',_('Save settings'),class_="btn")}
@@ -3,7 +3,7 b''
3 3 ## <%namespace name="vcss" file="/base/vcssettings.mako"/>
4 4 ## ${vcss.vcs_settings_fields()}
5 5
6 <%def name="vcs_settings_fields(suffix='', svn_branch_patterns=None, svn_tag_patterns=None, repo_type=None, display_globals=False, allow_repo_location_change=False, **kwargs)">
6 <%def name="vcs_settings_fields(suffix='', svn_branch_patterns=None, svn_tag_patterns=None, repo_type=None, display_globals=False, **kwargs)">
7 7 % if display_globals:
8 8 <div class="panel panel-default">
9 9 <div class="panel-heading" id="general">
@@ -23,34 +23,6 b''
23 23 </div>
24 24 % endif
25 25
26 % if display_globals:
27 <div class="panel panel-default">
28 <div class="panel-heading" id="vcs-storage-options">
29 <h3 class="panel-title">${_('Main Storage Location')}<a class="permalink" href="#vcs-storage-options"></a></h3>
30 </div>
31 <div class="panel-body">
32 <div class="field">
33 <div class="inputx locked_input">
34 %if allow_repo_location_change:
35 ${h.text('paths_root_path',size=59,readonly="readonly", class_="disabled")}
36 <span id="path_unlock" class="tooltip"
37 title="${h.tooltip(_('Click to unlock. You must restart RhodeCode in order to make this setting take effect.'))}">
38 <div class="btn btn-default lock_input_button"><i id="path_unlock_icon" class="icon-lock"></i></div>
39 </span>
40 %else:
41 ${_('Repository location change is disabled. You can enable this by changing the `allow_repo_location_change` inside .ini file.')}
42 ## form still requires this but we cannot internally change it anyway
43 ${h.hidden('paths_root_path',size=30,readonly="readonly", class_="disabled")}
44 %endif
45 </div>
46 </div>
47 <div class="label">
48 <span class="help-block">${_('Filesystem location where repositories should be stored. After changing this value a restart and rescan of the repository folder are required.')}</span>
49 </div>
50 </div>
51 </div>
52 % endif
53
54 26 % if display_globals or repo_type in ['git', 'hg']:
55 27 <div class="panel panel-default">
56 28 <div class="panel-heading" id="vcs-hooks-options">
@@ -27,6 +27,7 b' import urllib.parse'
27 27
28 28 import pytest
29 29
30 import rhodecode
30 31 from rhodecode.model.db import User
31 32 from rhodecode.lib import auth
32 33 from rhodecode.lib import helpers as h
@@ -53,8 +54,11 b' log = logging.getLogger(__name__)'
53 54
54 55 # SOME GLOBALS FOR TESTS
55 56 TEST_DIR = tempfile.gettempdir()
57 if os.getenv("RC_TEST"):
58 rhodecode.CONFIG['repo_store.path'] = TEST_DIR
56 59
57 TESTS_TMP_PATH = jn(TEST_DIR, 'rc_test_{}'.format(next(tempfile._RandomNameSequence())))
60 # Once repo_store.path in test config will be changed update TEST_TMP_PATH accordingly
61 TESTS_TMP_PATH = jn(TEST_DIR, 'rc_test_a0hmmrva')
58 62 TEST_USER_ADMIN_LOGIN = 'test_admin'
59 63 TEST_USER_ADMIN_PASS = 'test12'
60 64 TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com'
@@ -111,7 +115,7 b' def get_new_dir(title):'
111 115 hex_str = sha1_safe(f'{os.getpid()} {time.time()}')
112 116 name_parts.append(hex_str)
113 117 name = '-'.join(name_parts)
114 path = os.path.join(TEST_DIR, name)
118 path = jn(TEST_DIR, name)
115 119 return get_normalized_path(path)
116 120
117 121
@@ -23,16 +23,16 b' import pytest'
23 23 from unittest.mock import patch, Mock, MagicMock
24 24
25 25 from rhodecode.lib.middleware.simplesvn import SimpleSvn, SimpleSvnApp
26 from rhodecode.lib.utils import get_rhodecode_base_path
26 from rhodecode.lib.utils import get_rhodecode_repo_store_path
27 27 from rhodecode.tests import SVN_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
28 28
29 29
30 30 class TestSimpleSvn(object):
31 31 @pytest.fixture(autouse=True)
32 32 def simple_svn(self, baseapp, request_stub):
33 base_path = get_rhodecode_base_path()
33 base_path = get_rhodecode_repo_store_path()
34 34 self.app = SimpleSvn(
35 config={'auth_ret_code': '', 'base_path': base_path},
35 config={'auth_ret_code': '', 'repo_store.path': base_path},
36 36 registry=request_stub.registry)
37 37
38 38 def test_get_config(self):
@@ -126,7 +126,7 b' class TestSimpleSvnApp(object):'
126 126 def setup_method(self, method):
127 127 # note(marcink): this is hostname from docker compose used for testing...
128 128 self.host = 'http://svn:8090'
129 base_path = get_rhodecode_base_path()
129 base_path = get_rhodecode_repo_store_path()
130 130 self.app = SimpleSvnApp(
131 131 config={'subversion_http_server_url': self.host,
132 132 'base_path': base_path})
@@ -1004,21 +1004,6 b' class TestGetSvnPatterns(object):'
1004 1004 settings_mock.assert_called_once_with(*args)
1005 1005
1006 1006
1007 class TestGetReposLocation(object):
1008 def test_returns_repos_location(self, repo_stub):
1009 model = VcsSettingsModel()
1010
1011 result_mock = mock.Mock()
1012 result_mock.ui_value = '/tmp'
1013
1014 with mock.patch.object(model, 'global_settings') as settings_mock:
1015 settings_mock.get_ui_by_key.return_value = result_mock
1016 result = model.get_repos_location()
1017
1018 settings_mock.get_ui_by_key.assert_called_once_with('/')
1019 assert result == '/tmp'
1020
1021
1022 1007 class TestCreateOrUpdateRepoSettings(object):
1023 1008 FORM_DATA = {
1024 1009 'inherit_global_settings': False,
@@ -121,20 +121,20 b' class TestRepoModel(object):'
121 121 def test_create_filesystem_repo_installs_hooks(self, tmpdir, backend):
122 122 repo = backend.create_repo()
123 123 repo_name = repo.repo_name
124 model = RepoModel()
125 repo_location = tempfile.mkdtemp()
126 model.repos_path = repo_location
127 repo = model._create_filesystem_repo(
128 repo_name, backend.alias, repo_group='', clone_uri=None)
124 with mock.patch('rhodecode.model.repo.RepoModel.repos_path',
125 new_callable=mock.PropertyMock) as mocked_models_property:
126 mocked_models_property.return_value = tempfile.mkdtemp()
127 repo = RepoModel()._create_filesystem_repo(
128 repo_name, backend.alias, repo_group='', clone_uri=None)
129 129
130 hooks = {
131 'svn': ('pre-commit', 'post-commit'),
132 'git': ('pre-receive', 'post-receive'),
133 }
134 for hook in hooks[backend.alias]:
135 with open(os.path.join(repo.path, 'hooks', hook)) as f:
136 data = f.read()
137 assert 'RC_HOOK_VER' in data
130 hooks = {
131 'svn': ('pre-commit', 'post-commit'),
132 'git': ('pre-receive', 'post-receive'),
133 }
134 for hook in hooks[backend.alias]:
135 with open(os.path.join(repo.path, 'hooks', hook)) as f:
136 data = f.read()
137 assert 'RC_HOOK_VER' in data
138 138
139 139 @pytest.mark.parametrize("use_global_config, repo_name_passed", [
140 140 (True, False),
@@ -207,9 +207,6 b' auth_ret_code_detection = false'
207 207 ; codes don't break the transactions while 4XX codes do
208 208 lock_ret_code = 423
209 209
210 ; allows to change the repository location in settings page
211 allow_repo_location_change = true
212
213 210 ; allows to setup custom hooks in settings page
214 211 allow_custom_hooks_settings = true
215 212
General Comments 0
You need to be logged in to leave comments. Login now