hooks: made the callback host configurable.
- This allows easier docker container seperation
This commit is contained in:
parent
5b6f79f166
commit
225757aaf3
14 changed files with 36 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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(ThreadedHookCallbackDaemon):
|
|||
|
||||
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, protocol, use_direct_calls, txn_id=None):
|
|||
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.')
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ ARCHIVE_SPECS = {
|
|||
|
||||
HOOKS_PROTOCOL = None
|
||||
HOOKS_DIRECT_CALLS = False
|
||||
HOOKS_HOST = '127.0.0.1'
|
||||
|
||||
|
||||
def available_aliases():
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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'])
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -177,6 +177,7 @@ def ini_config(request, tmpdir_factory, rcserver_port, vcsserver_port):
|
|||
'vcs.server.protocol': 'http',
|
||||
'vcs.scm_app_implementation': 'http',
|
||||
'vcs.hooks.protocol': 'http',
|
||||
'vcs.hooks.host': '127.0.0.1',
|
||||
}},
|
||||
|
||||
{'handler_console': {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue