##// END OF EJS Templates
vcs: reduce sql queries used during pull/push operations.
marcink -
r2140:61a36530 default
parent child Browse files
Show More
@@ -31,6 +31,7 b' import warnings'
31 31 import functools
32 32
33 33 from pyramid.threadlocal import get_current_registry
34 from zope.cachedescriptors.property import Lazy as LazyProperty
34 35
35 36 from rhodecode.authentication.interface import IAuthnPluginRegistry
36 37 from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase
@@ -168,6 +169,11 b' class RhodeCodeAuthPluginBase(object):'
168 169 db_type = '{}.encrypted'.format(db_type)
169 170 return db_type
170 171
172 @LazyProperty
173 def plugin_settings(self):
174 settings = SettingsModel().get_all_settings()
175 return settings
176
171 177 def is_enabled(self):
172 178 """
173 179 Returns true if this plugin is enabled. An enabled plugin can be
@@ -206,9 +212,10 b' class RhodeCodeAuthPluginBase(object):'
206 212 """
207 213 Returns a plugin setting by name.
208 214 """
209 full_name = self._get_setting_full_name(name)
210 db_setting = SettingsModel().get_setting_by_name(full_name)
211 return db_setting.app_settings_value if db_setting else default
215 full_name = 'rhodecode_{}'.format(self._get_setting_full_name(name))
216 plugin_settings = self.plugin_settings
217
218 return plugin_settings.get(full_name) or default
212 219
213 220 def create_or_update_setting(self, name, value):
214 221 """
@@ -68,7 +68,7 b' class AuthenticationPluginRegistry(objec'
68 68 plugins = []
69 69
70 70 # Add all enabled and active plugins to the list. We iterate over the
71 # auth_plugins setting from DB beacuse it also represents the ordering.
71 # auth_plugins setting from DB because it also represents the ordering.
72 72 enabled_plugins = SettingsModel().get_auth_plugins()
73 73 for plugin_id in enabled_plugins:
74 74 plugin = self.get_plugin(plugin_id)
@@ -45,7 +45,7 b' from rhodecode.lib.utils import ('
45 45 get_repo_slug, set_rhodecode_config, password_changed,
46 46 get_enabled_hook_classes)
47 47 from rhodecode.lib.utils2 import (
48 str2bool, safe_unicode, AttributeDict, safe_int, md5, aslist)
48 str2bool, safe_unicode, AttributeDict, safe_int, md5, aslist, safe_str)
49 49 from rhodecode.model import meta
50 50 from rhodecode.model.db import Repository, User, ChangesetComment
51 51 from rhodecode.model.notification import NotificationModel
@@ -252,6 +252,9 b' class BasicAuth(AuthBasicAuthenticator):'
252 252 log.exception('Failed to fetch response for code %s' % http_code)
253 253 return HTTPForbidden
254 254
255 def get_rc_realm(self):
256 return safe_str(self.registry.rhodecode_settings.get('rhodecode_realm'))
257
255 258 def build_authentication(self):
256 259 head = WWW_AUTHENTICATE.tuples('Basic realm="%s"' % self.realm)
257 260 if self._rc_auth_http_code and not self.initial_call:
@@ -45,7 +45,7 b' from rhodecode.lib.hooks_daemon import p'
45 45 from rhodecode.lib.middleware import appenlight
46 46 from rhodecode.lib.middleware.utils import scm_app_http
47 47 from rhodecode.lib.utils import (
48 is_valid_repo, get_rhodecode_realm, get_rhodecode_base_path, SLUG_RE)
48 is_valid_repo, get_rhodecode_base_path, SLUG_RE)
49 49 from rhodecode.lib.utils2 import safe_str, fix_PATH, str2bool, safe_unicode
50 50 from rhodecode.lib.vcs.conf import settings as vcs_settings
51 51 from rhodecode.lib.vcs.backends import base
@@ -53,7 +53,7 b' from rhodecode.model import meta'
53 53 from rhodecode.model.db import User, Repository, PullRequest
54 54 from rhodecode.model.scm import ScmModel
55 55 from rhodecode.model.pull_request import PullRequestModel
56
56 from rhodecode.model.settings import SettingsModel
57 57
58 58 log = logging.getLogger(__name__)
59 59
@@ -107,9 +107,9 b' class SimpleVCS(object):'
107 107 self.config = config
108 108 # re-populated by specialized middleware
109 109 self.repo_vcs_config = base.Config()
110
111 # base path of repo locations
112 self.basepath = get_rhodecode_base_path()
110 self.rhodecode_settings = SettingsModel().get_all_settings(cache=True)
111 self.basepath = rhodecode.CONFIG['base_path']
112 registry.rhodecode_settings = self.rhodecode_settings
113 113 # authenticate this VCS request using authfunc
114 114 auth_ret_code_detection = \
115 115 str2bool(self.config.get('auth_ret_code_detection', False))
@@ -381,7 +381,7 b' class SimpleVCS(object):'
381 381 # before inject the calling repo_name for special scope checks
382 382 self.authenticate.acl_repo_name = self.acl_repo_name
383 383 if not username:
384 self.authenticate.realm = get_rhodecode_realm()
384 self.authenticate.realm = self.authenticate.get_rc_realm()
385 385
386 386 try:
387 387 result = self.authenticate(environ)
@@ -73,10 +73,10 b' def get_environ(url, request_method):'
73 73 ('/info/lfs/info/lfs/objects/batch', 'pull', 'POST'),
74 74
75 75 ])
76 def test_get_action(url, expected_action, request_method, pylonsapp):
76 def test_get_action(url, expected_action, request_method, pylonsapp, request_stub):
77 77 app = simplegit.SimpleGit(application=None,
78 78 config={'auth_ret_code': '', 'base_path': ''},
79 registry=None)
79 registry=request_stub.registry)
80 80 assert expected_action == app._get_action(get_environ(url, request_method))
81 81
82 82
@@ -102,19 +102,19 b' def test_get_action(url, expected_action'
102 102 ('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'POST'),
103 103
104 104 ])
105 def test_get_repository_name(url, expected_repo_name, request_method, pylonsapp):
105 def test_get_repository_name(url, expected_repo_name, request_method, pylonsapp, request_stub):
106 106 app = simplegit.SimpleGit(application=None,
107 107 config={'auth_ret_code': '', 'base_path': ''},
108 registry=None)
108 registry=request_stub.registry)
109 109 assert expected_repo_name == app._get_repository_name(
110 110 get_environ(url, request_method))
111 111
112 112
113 def test_get_config(pylonsapp, user_util):
113 def test_get_config(user_util, pylonsapp, request_stub):
114 114 repo = user_util.create_repo(repo_type='git')
115 115 app = simplegit.SimpleGit(application=None,
116 116 config={'auth_ret_code': '', 'base_path': ''},
117 registry=None)
117 registry=request_stub.registry)
118 118 extras = {'foo': 'FOO', 'bar': 'BAR'}
119 119
120 120 # We copy the extras as the method below will change the contents.
@@ -130,13 +130,13 b' def test_get_config(pylonsapp, user_util'
130 130 assert git_config == expected_config
131 131
132 132
133 def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp):
133 def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp, request_stub):
134 134 config = {
135 135 'auth_ret_code': '',
136 136 'base_path': '',
137 137 'vcs.scm_app_implementation':
138 138 'rhodecode.tests.lib.middleware.mock_scm_app',
139 139 }
140 app = simplegit.SimpleGit(application=None, config=config, registry=None)
140 app = simplegit.SimpleGit(application=None, config=config, registry=request_stub.registry)
141 141 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
142 142 assert wsgi_app is mock_scm_app.mock_git_wsgi
@@ -53,10 +53,10 b' def get_environ(url):'
53 53 # Edge case: not cmd argument
54 54 ('/foo/bar?key=tip', 'pull'),
55 55 ])
56 def test_get_action(url, expected_action):
56 def test_get_action(url, expected_action, request_stub):
57 57 app = simplehg.SimpleHg(application=None,
58 58 config={'auth_ret_code': '', 'base_path': ''},
59 registry=None)
59 registry=request_stub.registry)
60 60 assert expected_action == app._get_action(get_environ(url))
61 61
62 62
@@ -71,18 +71,18 b' def test_get_action(url, expected_action'
71 71 ('/foo/bar/?cmd=pushkey&key=tip', 'foo/bar'),
72 72 ('/foo/bar/baz/?cmd=listkeys&key=tip', 'foo/bar/baz'),
73 73 ])
74 def test_get_repository_name(url, expected_repo_name):
74 def test_get_repository_name(url, expected_repo_name, request_stub):
75 75 app = simplehg.SimpleHg(application=None,
76 76 config={'auth_ret_code': '', 'base_path': ''},
77 registry=None)
77 registry=request_stub.registry)
78 78 assert expected_repo_name == app._get_repository_name(get_environ(url))
79 79
80 80
81 def test_get_config(pylonsapp, user_util):
81 def test_get_config(user_util, pylonsapp, request_stub):
82 82 repo = user_util.create_repo(repo_type='git')
83 83 app = simplehg.SimpleHg(application=None,
84 84 config={'auth_ret_code': '', 'base_path': ''},
85 registry=None)
85 registry=request_stub.registry)
86 86 extras = [('foo', 'FOO', 'bar', 'BAR')]
87 87
88 88 hg_config = app._create_config(extras, repo_name=repo.repo_name)
@@ -116,13 +116,14 b' def test_get_config(pylonsapp, user_util'
116 116 assert entry in hg_config
117 117
118 118
119 def test_create_wsgi_app_uses_scm_app_from_simplevcs():
119 def test_create_wsgi_app_uses_scm_app_from_simplevcs(request_stub):
120 120 config = {
121 121 'auth_ret_code': '',
122 122 'base_path': '',
123 123 'vcs.scm_app_implementation':
124 124 'rhodecode.tests.lib.middleware.mock_scm_app',
125 125 }
126 app = simplehg.SimpleHg(application=None, config=config, registry=None)
126 app = simplehg.SimpleHg(
127 application=None, config=config, registry=request_stub.registry)
127 128 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
128 129 assert wsgi_app is mock_scm_app.mock_hg_wsgi
@@ -29,12 +29,12 b' from rhodecode.lib.middleware.simplesvn '
29 29
30 30 class TestSimpleSvn(object):
31 31 @pytest.fixture(autouse=True)
32 def simple_svn(self, pylonsapp):
32 def simple_svn(self, pylonsapp, request_stub):
33 33 self.app = SimpleSvn(
34 34 application='None',
35 35 config={'auth_ret_code': '',
36 36 'base_path': rhodecode.CONFIG['base_path']},
37 registry=None)
37 registry=request_stub.registry)
38 38
39 39 def test_get_config(self):
40 40 extras = {'foo': 'FOO', 'bar': 'BAR'}
@@ -23,6 +23,7 b' import base64'
23 23 import mock
24 24 import pytest
25 25
26 from rhodecode.lib.utils2 import AttributeDict
26 27 from rhodecode.tests.utils import CustomTestApp
27 28
28 29 from rhodecode.lib.caching_query import FromCache
@@ -73,12 +74,12 b' class StubVCSController(simplevcs.Simple'
73 74
74 75
75 76 @pytest.fixture
76 def vcscontroller(pylonsapp, config_stub):
77 def vcscontroller(pylonsapp, config_stub, request_stub):
77 78 config_stub.testing_securitypolicy()
78 79 config_stub.include('rhodecode.authentication')
79 80
80 #set_anonymous_access(True)
81 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
81 controller = StubVCSController(
82 pylonsapp, pylonsapp.config, request_stub.registry)
82 83 app = HttpsFixup(controller, pylonsapp.config)
83 84 app = CustomTestApp(app)
84 85
@@ -134,7 +135,8 b' class StubFailVCSController(simplevcs.Si'
134 135
135 136 @pytest.fixture(scope='module')
136 137 def fail_controller(pylonsapp):
137 controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
138 controller = StubFailVCSController(
139 pylonsapp, pylonsapp.config, pylonsapp.config)
138 140 controller = HttpsFixup(controller, pylonsapp.config)
139 141 controller = CustomTestApp(controller)
140 142 return controller
@@ -150,16 +152,18 b' def test_provides_traceback_for_appenlig'
150 152 assert 'appenlight.__traceback' in response.request.environ
151 153
152 154
153 def test_provides_utils_scm_app_as_scm_app_by_default(pylonsapp):
154 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
155 def test_provides_utils_scm_app_as_scm_app_by_default(pylonsapp, request_stub):
156 controller = StubVCSController(
157 pylonsapp, pylonsapp.config, request_stub.registry)
155 158 assert controller.scm_app is scm_app_http
156 159
157 160
158 def test_allows_to_override_scm_app_via_config(pylonsapp):
161 def test_allows_to_override_scm_app_via_config(pylonsapp, request_stub):
159 162 config = pylonsapp.config.copy()
160 163 config['vcs.scm_app_implementation'] = (
161 164 'rhodecode.tests.lib.middleware.mock_scm_app')
162 controller = StubVCSController(pylonsapp, config, None)
165 controller = StubVCSController(
166 pylonsapp, config, request_stub.registry)
163 167 assert controller.scm_app is mock_scm_app
164 168
165 169
@@ -214,12 +218,14 b' class TestShadowRepoRegularExpression(ob'
214 218 @pytest.mark.backends('git', 'hg')
215 219 class TestShadowRepoExposure(object):
216 220
217 def test_pull_on_shadow_repo_propagates_to_wsgi_app(self, pylonsapp):
221 def test_pull_on_shadow_repo_propagates_to_wsgi_app(
222 self, pylonsapp, request_stub):
218 223 """
219 224 Check that a pull action to a shadow repo is propagated to the
220 225 underlying wsgi app.
221 226 """
222 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
227 controller = StubVCSController(
228 pylonsapp, pylonsapp.config, request_stub.registry)
223 229 controller._check_ssl = mock.Mock()
224 230 controller.is_shadow_repo = True
225 231 controller._action = 'pull'
@@ -238,12 +244,13 b' class TestShadowRepoExposure(object):'
238 244 # Assert that we got the response from the wsgi app.
239 245 assert response_body == controller.stub_response_body
240 246
241 def test_pull_on_shadow_repo_that_is_missing(self, pylonsapp):
247 def test_pull_on_shadow_repo_that_is_missing(self, pylonsapp, request_stub):
242 248 """
243 249 Check that a pull action to a shadow repo is propagated to the
244 250 underlying wsgi app.
245 251 """
246 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
252 controller = StubVCSController(
253 pylonsapp, pylonsapp.config, request_stub.registry)
247 254 controller._check_ssl = mock.Mock()
248 255 controller.is_shadow_repo = True
249 256 controller._action = 'pull'
@@ -262,11 +269,12 b' class TestShadowRepoExposure(object):'
262 269 # Assert that we got the response from the wsgi app.
263 270 assert '404 Not Found' in response_body
264 271
265 def test_push_on_shadow_repo_raises(self, pylonsapp):
272 def test_push_on_shadow_repo_raises(self, pylonsapp, request_stub):
266 273 """
267 274 Check that a push action to a shadow repo is aborted.
268 275 """
269 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
276 controller = StubVCSController(
277 pylonsapp, pylonsapp.config, request_stub.registry)
270 278 controller._check_ssl = mock.Mock()
271 279 controller.is_shadow_repo = True
272 280 controller._action = 'push'
@@ -285,13 +293,14 b' class TestShadowRepoExposure(object):'
285 293 # Assert that a 406 error is returned.
286 294 assert '406 Not Acceptable' in response_body
287 295
288 def test_set_repo_names_no_shadow(self, pylonsapp):
296 def test_set_repo_names_no_shadow(self, pylonsapp, request_stub):
289 297 """
290 298 Check that the set_repo_names method sets all names to the one returned
291 299 by the _get_repository_name method on a request to a non shadow repo.
292 300 """
293 301 environ_stub = {}
294 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
302 controller = StubVCSController(
303 pylonsapp, pylonsapp.config, request_stub.registry)
295 304 controller._name = 'RepoGroup/MyRepo'
296 305 controller.set_repo_names(environ_stub)
297 306 assert not controller.is_shadow_repo
@@ -300,7 +309,8 b' class TestShadowRepoExposure(object):'
300 309 controller.vcs_repo_name ==
301 310 controller._get_repository_name(environ_stub))
302 311
303 def test_set_repo_names_with_shadow(self, pylonsapp, pr_util, config_stub):
312 def test_set_repo_names_with_shadow(
313 self, pylonsapp, pr_util, config_stub, request_stub):
304 314 """
305 315 Check that the set_repo_names method sets correct names on a request
306 316 to a shadow repo.
@@ -313,7 +323,8 b' class TestShadowRepoExposure(object):'
313 323 pr_id=pull_request.pull_request_id,
314 324 pr_segment=TestShadowRepoRegularExpression.pr_segment,
315 325 shadow_segment=TestShadowRepoRegularExpression.shadow_segment)
316 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
326 controller = StubVCSController(
327 pylonsapp, pylonsapp.config, request_stub.registry)
317 328 controller._name = shadow_url
318 329 controller.set_repo_names({})
319 330
@@ -329,7 +340,7 b' class TestShadowRepoExposure(object):'
329 340 assert controller.is_shadow_repo
330 341
331 342 def test_set_repo_names_with_shadow_but_missing_pr(
332 self, pylonsapp, pr_util, config_stub):
343 self, pylonsapp, pr_util, config_stub, request_stub):
333 344 """
334 345 Checks that the set_repo_names method enforces matching target repos
335 346 and pull request IDs.
@@ -340,7 +351,8 b' class TestShadowRepoExposure(object):'
340 351 pr_id=999999999,
341 352 pr_segment=TestShadowRepoRegularExpression.pr_segment,
342 353 shadow_segment=TestShadowRepoRegularExpression.shadow_segment)
343 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
354 controller = StubVCSController(
355 pylonsapp, pylonsapp.config, request_stub.registry)
344 356 controller._name = shadow_url
345 357 controller.set_repo_names({})
346 358
@@ -416,7 +428,8 b' class TestGenerateVcsResponse(object):'
416 428 'vcs.hooks.protocol': 'http',
417 429 'vcs.hooks.direct_calls': False,
418 430 }
419 controller = StubVCSController(None, settings, None)
431 registry = AttributeDict()
432 controller = StubVCSController(None, settings, registry)
420 433 controller._invalidate_cache = mock.Mock()
421 434 controller.stub_response_body = response_body
422 435 self.start_response = mock.Mock()
@@ -465,11 +478,11 b' class TestInitializeGenerator(object):'
465 478
466 479
467 480 class TestPrepareHooksDaemon(object):
468 def test_calls_imported_prepare_callback_daemon(self, app_settings):
481 def test_calls_imported_prepare_callback_daemon(self, app_settings, request_stub):
469 482 expected_extras = {'extra1': 'value1'}
470 483 daemon = DummyHooksCallbackDaemon()
471 484
472 controller = StubVCSController(None, app_settings, None)
485 controller = StubVCSController(None, app_settings, request_stub.registry)
473 486 prepare_patcher = mock.patch.object(
474 487 simplevcs, 'prepare_callback_daemon',
475 488 return_value=(daemon, expected_extras))
General Comments 0
You need to be logged in to leave comments. Login now