diff --git a/configs/development.ini b/configs/development.ini --- a/configs/development.ini +++ b/configs/development.ini @@ -551,6 +551,10 @@ vcs.scm_app_implementation = http ## `http` - use http-rpc backend (default) vcs.hooks.protocol = http +## Host on which this instance is listening for hooks. If vcsserver is in other location +## this should be adjusted. +vcs.hooks.host = 127.0.0.1 + vcs.server.log_level = debug ## Start VCSServer with this instance as a subprocess, usefull for development vcs.start_server = false diff --git a/configs/production.ini b/configs/production.ini --- a/configs/production.ini +++ b/configs/production.ini @@ -520,6 +520,9 @@ vcs.scm_app_implementation = http ## Push/Pull operations hooks protocol, available options are: ## `http` - use http-rpc backend (default) vcs.hooks.protocol = http +## Host on which this instance is listening for hooks. If vcsserver is in other location +## this should be adjusted. +vcs.hooks.host = 127.0.0.1 vcs.server.log_level = info ## Start VCSServer with this instance as a subprocess, usefull for development diff --git a/rhodecode/apps/ssh_support/lib/backends/base.py b/rhodecode/apps/ssh_support/lib/backends/base.py --- a/rhodecode/apps/ssh_support/lib/backends/base.py +++ b/rhodecode/apps/ssh_support/lib/backends/base.py @@ -139,6 +139,7 @@ class VcsServer(object): callback_daemon, extras = prepare_callback_daemon( extras, protocol=vcs_settings.HOOKS_PROTOCOL, + host=vcs_settings.HOOKS_HOST, use_direct_calls=False) with callback_daemon: diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -401,6 +401,7 @@ def _sanitize_vcs_settings(settings): _string_setting(settings, 'vcs.svn.compatible_version', '') _string_setting(settings, 'git_rev_filter', '--all') _string_setting(settings, 'vcs.hooks.protocol', 'http') + _string_setting(settings, 'vcs.hooks.host', '127.0.0.1') _string_setting(settings, 'vcs.scm_app_implementation', 'http') _string_setting(settings, 'vcs.server', '') _string_setting(settings, 'vcs.server.log_level', 'debug') diff --git a/rhodecode/config/utils.py b/rhodecode/config/utils.py --- a/rhodecode/config/utils.py +++ b/rhodecode/config/utils.py @@ -25,12 +25,13 @@ import platform from rhodecode.model import init_model - def configure_vcs(config): """ Patch VCS config with some RhodeCode specific stuff """ from rhodecode.lib.vcs import conf + import rhodecode.lib.vcs.conf.settings + conf.settings.BACKENDS = { 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository', 'git': 'rhodecode.lib.vcs.backends.git.GitRepository', @@ -38,6 +39,7 @@ def configure_vcs(config): } conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol'] + conf.settings.HOOKS_HOST = config['vcs.hooks.host'] conf.settings.HOOKS_DIRECT_CALLS = config['vcs.hooks.direct_calls'] conf.settings.GIT_REV_FILTER = shlex.split(config['git_rev_filter']) conf.settings.DEFAULT_ENCODINGS = config['default_encoding'] diff --git a/rhodecode/lib/hooks_daemon.py b/rhodecode/lib/hooks_daemon.py --- a/rhodecode/lib/hooks_daemon.py +++ b/rhodecode/lib/hooks_daemon.py @@ -119,8 +119,8 @@ class ThreadedHookCallbackDaemon(object) _daemon = None _done = False - def __init__(self, txn_id=None, port=None): - self._prepare(txn_id=txn_id, port=port) + def __init__(self, txn_id=None, host=None, port=None): + self._prepare(txn_id=txn_id, host=None, port=port) def __enter__(self): self._run() @@ -130,7 +130,7 @@ class ThreadedHookCallbackDaemon(object) log.debug('Callback daemon exiting now...') self._stop() - def _prepare(self, txn_id=None, port=None): + def _prepare(self, txn_id=None, host=None, port=None): raise NotImplementedError() def _run(self): @@ -147,17 +147,16 @@ class HttpHooksCallbackDaemon(ThreadedHo hooks_uri = None - IP_ADDRESS = '127.0.0.1' - # From Python docs: Polling reduces our responsiveness to a shutdown # request and wastes cpu at all other times. POLL_INTERVAL = 0.01 - def _prepare(self, txn_id=None, port=None): + def _prepare(self, txn_id=None, host=None, port=None): + host = host or '127.0.0.1' self._done = False - self._daemon = TCPServer((self.IP_ADDRESS, port or 0), HooksHttpHandler) + self._daemon = TCPServer((host, port or 0), HooksHttpHandler) _, port = self._daemon.server_address - self.hooks_uri = '{}:{}'.format(self.IP_ADDRESS, port) + self.hooks_uri = '{}:{}'.format(host, port) self.txn_id = txn_id # inject transaction_id for later verification self._daemon.txn_id = self.txn_id @@ -220,7 +219,7 @@ def get_txn_id_from_store(txn_id): return {} -def prepare_callback_daemon(extras, protocol, use_direct_calls, txn_id=None): +def prepare_callback_daemon(extras, protocol, host, use_direct_calls, txn_id=None): txn_details = get_txn_id_from_store(txn_id) port = txn_details.get('port', 0) if use_direct_calls: @@ -228,7 +227,8 @@ def prepare_callback_daemon(extras, prot extras['hooks_module'] = callback_daemon.hooks_module else: if protocol == 'http': - callback_daemon = HttpHooksCallbackDaemon(txn_id=txn_id, port=port) + callback_daemon = HttpHooksCallbackDaemon( + txn_id=txn_id, host=host, port=port) else: log.error('Unsupported callback daemon protocol "%s"', protocol) raise Exception('Unsupported callback daemon protocol.') diff --git a/rhodecode/lib/middleware/simplevcs.py b/rhodecode/lib/middleware/simplevcs.py --- a/rhodecode/lib/middleware/simplevcs.py +++ b/rhodecode/lib/middleware/simplevcs.py @@ -663,7 +663,7 @@ class SimpleVCS(object): return prepare_callback_daemon( extras, protocol=vcs_settings.HOOKS_PROTOCOL, - use_direct_calls=direct_calls, txn_id=txn_id) + host=vcs_settings.HOOKS_HOST, use_direct_calls=direct_calls, txn_id=txn_id) def _should_check_locking(query_string): diff --git a/rhodecode/lib/vcs/conf/settings.py b/rhodecode/lib/vcs/conf/settings.py --- a/rhodecode/lib/vcs/conf/settings.py +++ b/rhodecode/lib/vcs/conf/settings.py @@ -51,6 +51,7 @@ ARCHIVE_SPECS = { HOOKS_PROTOCOL = None HOOKS_DIRECT_CALLS = False +HOOKS_HOST = '127.0.0.1' def available_aliases(): diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -622,6 +622,7 @@ class PullRequestModel(BaseModel): callback_daemon, extras = prepare_callback_daemon( extras, protocol=vcs_settings.HOOKS_PROTOCOL, + host=vcs_settings.HOOKS_HOST, use_direct_calls=vcs_settings.HOOKS_DIRECT_CALLS) with callback_daemon: diff --git a/rhodecode/tests/config/test_sanitize_settings.py b/rhodecode/tests/config/test_sanitize_settings.py --- a/rhodecode/tests/config/test_sanitize_settings.py +++ b/rhodecode/tests/config/test_sanitize_settings.py @@ -117,6 +117,7 @@ class TestSanitizeVcsSettings(object): ('vcs.svn.compatible_version', ''), ('git_rev_filter', '--all'), ('vcs.hooks.protocol', 'http'), + ('vcs.hooks.host', '127.0.0.1'), ('vcs.scm_app_implementation', 'http'), ('vcs.server', ''), ('vcs.server.log_level', 'debug'), diff --git a/rhodecode/tests/lib/middleware/test_simplevcs.py b/rhodecode/tests/lib/middleware/test_simplevcs.py --- a/rhodecode/tests/lib/middleware/test_simplevcs.py +++ b/rhodecode/tests/lib/middleware/test_simplevcs.py @@ -465,6 +465,7 @@ class TestPrepareHooksDaemon(object): prepare_mock.assert_called_once_with( expected_extras, protocol=app_settings['vcs.hooks.protocol'], + host=app_settings['vcs.hooks.host'], txn_id=None, use_direct_calls=app_settings['vcs.hooks.direct_calls']) diff --git a/rhodecode/tests/lib/test_hooks_daemon.py b/rhodecode/tests/lib/test_hooks_daemon.py --- a/rhodecode/tests/lib/test_hooks_daemon.py +++ b/rhodecode/tests/lib/test_hooks_daemon.py @@ -180,7 +180,7 @@ class TestHttpHooksCallbackDaemon(object assert daemon._daemon == tcp_server _, port = tcp_server.server_address - expected_uri = '{}:{}'.format(daemon.IP_ADDRESS, port) + expected_uri = '{}:{}'.format('127.0.0.1', port) msg = 'Preparing HTTP callback daemon at `{}` and ' \ 'registering hook object'.format(expected_uri) assert_message_in_log( @@ -192,7 +192,7 @@ class TestHttpHooksCallbackDaemon(object daemon = hooks_daemon.HttpHooksCallbackDaemon() _, port = tcp_server.server_address - expected_uri = '{}:{}'.format(daemon.IP_ADDRESS, port) + expected_uri = '{}:{}'.format('127.0.0.1', port) assert daemon.hooks_uri == expected_uri msg = 'Preparing HTTP callback daemon at `{}` and ' \ @@ -264,7 +264,8 @@ class TestPrepareHooksDaemon(object): self, protocol): expected_extras = {'extra1': 'value1'} callback, extras = hooks_daemon.prepare_callback_daemon( - expected_extras.copy(), protocol=protocol, use_direct_calls=True) + expected_extras.copy(), protocol=protocol, + host='127.0.0.1', use_direct_calls=True) assert isinstance(callback, hooks_daemon.DummyHooksCallbackDaemon) expected_extras['hooks_module'] = 'rhodecode.lib.hooks_daemon' expected_extras['time'] = extras['time'] @@ -281,7 +282,8 @@ class TestPrepareHooksDaemon(object): 'hooks_protocol': protocol.lower() } callback, extras = hooks_daemon.prepare_callback_daemon( - expected_extras.copy(), protocol=protocol, use_direct_calls=False, + expected_extras.copy(), protocol=protocol, host='127.0.0.1', + use_direct_calls=False, txn_id='txnid2') assert isinstance(callback, expected_class) extras.pop('hooks_uri') @@ -301,7 +303,7 @@ class TestPrepareHooksDaemon(object): with pytest.raises(Exception): callback, extras = hooks_daemon.prepare_callback_daemon( expected_extras.copy(), - protocol=protocol, + protocol=protocol, host='127.0.0.1', use_direct_calls=False) diff --git a/rhodecode/tests/pylons_plugin.py b/rhodecode/tests/pylons_plugin.py --- a/rhodecode/tests/pylons_plugin.py +++ b/rhodecode/tests/pylons_plugin.py @@ -177,6 +177,7 @@ def ini_config(request, tmpdir_factory, 'vcs.server.protocol': 'http', 'vcs.scm_app_implementation': 'http', 'vcs.hooks.protocol': 'http', + 'vcs.hooks.host': '127.0.0.1', }}, {'handler_console': { diff --git a/rhodecode/tests/rhodecode.ini b/rhodecode/tests/rhodecode.ini --- a/rhodecode/tests/rhodecode.ini +++ b/rhodecode/tests/rhodecode.ini @@ -521,6 +521,7 @@ vcs.scm_app_implementation = http ## Push/Pull operations hooks protocol, available options are: ## `http` - use http-rpc backend (default) vcs.hooks.protocol = http +vcs.hooks.host = 127.0.0.1 vcs.server.log_level = debug ## Start VCSServer with this instance as a subprocess, usefull for development