##// END OF EJS Templates
hooks: made the callback host configurable....
marcink -
r2833:920dbf8a default
parent child Browse files
Show More
@@ -551,6 +551,10 b' vcs.scm_app_implementation = http'
551 551 ## `http` - use http-rpc backend (default)
552 552 vcs.hooks.protocol = http
553 553
554 ## Host on which this instance is listening for hooks. If vcsserver is in other location
555 ## this should be adjusted.
556 vcs.hooks.host = 127.0.0.1
557
554 558 vcs.server.log_level = debug
555 559 ## Start VCSServer with this instance as a subprocess, usefull for development
556 560 vcs.start_server = false
@@ -520,6 +520,9 b' vcs.scm_app_implementation = http'
520 520 ## Push/Pull operations hooks protocol, available options are:
521 521 ## `http` - use http-rpc backend (default)
522 522 vcs.hooks.protocol = http
523 ## Host on which this instance is listening for hooks. If vcsserver is in other location
524 ## this should be adjusted.
525 vcs.hooks.host = 127.0.0.1
523 526
524 527 vcs.server.log_level = info
525 528 ## Start VCSServer with this instance as a subprocess, usefull for development
@@ -139,6 +139,7 b' class VcsServer(object):'
139 139
140 140 callback_daemon, extras = prepare_callback_daemon(
141 141 extras, protocol=vcs_settings.HOOKS_PROTOCOL,
142 host=vcs_settings.HOOKS_HOST,
142 143 use_direct_calls=False)
143 144
144 145 with callback_daemon:
@@ -401,6 +401,7 b' def _sanitize_vcs_settings(settings):'
401 401 _string_setting(settings, 'vcs.svn.compatible_version', '')
402 402 _string_setting(settings, 'git_rev_filter', '--all')
403 403 _string_setting(settings, 'vcs.hooks.protocol', 'http')
404 _string_setting(settings, 'vcs.hooks.host', '127.0.0.1')
404 405 _string_setting(settings, 'vcs.scm_app_implementation', 'http')
405 406 _string_setting(settings, 'vcs.server', '')
406 407 _string_setting(settings, 'vcs.server.log_level', 'debug')
@@ -25,12 +25,13 b' import platform'
25 25 from rhodecode.model import init_model
26 26
27 27
28
29 28 def configure_vcs(config):
30 29 """
31 30 Patch VCS config with some RhodeCode specific stuff
32 31 """
33 32 from rhodecode.lib.vcs import conf
33 import rhodecode.lib.vcs.conf.settings
34
34 35 conf.settings.BACKENDS = {
35 36 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository',
36 37 'git': 'rhodecode.lib.vcs.backends.git.GitRepository',
@@ -38,6 +39,7 b' def configure_vcs(config):'
38 39 }
39 40
40 41 conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol']
42 conf.settings.HOOKS_HOST = config['vcs.hooks.host']
41 43 conf.settings.HOOKS_DIRECT_CALLS = config['vcs.hooks.direct_calls']
42 44 conf.settings.GIT_REV_FILTER = shlex.split(config['git_rev_filter'])
43 45 conf.settings.DEFAULT_ENCODINGS = config['default_encoding']
@@ -119,8 +119,8 b' class ThreadedHookCallbackDaemon(object)'
119 119 _daemon = None
120 120 _done = False
121 121
122 def __init__(self, txn_id=None, port=None):
123 self._prepare(txn_id=txn_id, port=port)
122 def __init__(self, txn_id=None, host=None, port=None):
123 self._prepare(txn_id=txn_id, host=None, port=port)
124 124
125 125 def __enter__(self):
126 126 self._run()
@@ -130,7 +130,7 b' class ThreadedHookCallbackDaemon(object)'
130 130 log.debug('Callback daemon exiting now...')
131 131 self._stop()
132 132
133 def _prepare(self, txn_id=None, port=None):
133 def _prepare(self, txn_id=None, host=None, port=None):
134 134 raise NotImplementedError()
135 135
136 136 def _run(self):
@@ -147,17 +147,16 b' class HttpHooksCallbackDaemon(ThreadedHo'
147 147
148 148 hooks_uri = None
149 149
150 IP_ADDRESS = '127.0.0.1'
151
152 150 # From Python docs: Polling reduces our responsiveness to a shutdown
153 151 # request and wastes cpu at all other times.
154 152 POLL_INTERVAL = 0.01
155 153
156 def _prepare(self, txn_id=None, port=None):
154 def _prepare(self, txn_id=None, host=None, port=None):
155 host = host or '127.0.0.1'
157 156 self._done = False
158 self._daemon = TCPServer((self.IP_ADDRESS, port or 0), HooksHttpHandler)
157 self._daemon = TCPServer((host, port or 0), HooksHttpHandler)
159 158 _, port = self._daemon.server_address
160 self.hooks_uri = '{}:{}'.format(self.IP_ADDRESS, port)
159 self.hooks_uri = '{}:{}'.format(host, port)
161 160 self.txn_id = txn_id
162 161 # inject transaction_id for later verification
163 162 self._daemon.txn_id = self.txn_id
@@ -220,7 +219,7 b' def get_txn_id_from_store(txn_id):'
220 219 return {}
221 220
222 221
223 def prepare_callback_daemon(extras, protocol, use_direct_calls, txn_id=None):
222 def prepare_callback_daemon(extras, protocol, host, use_direct_calls, txn_id=None):
224 223 txn_details = get_txn_id_from_store(txn_id)
225 224 port = txn_details.get('port', 0)
226 225 if use_direct_calls:
@@ -228,7 +227,8 b' def prepare_callback_daemon(extras, prot'
228 227 extras['hooks_module'] = callback_daemon.hooks_module
229 228 else:
230 229 if protocol == 'http':
231 callback_daemon = HttpHooksCallbackDaemon(txn_id=txn_id, port=port)
230 callback_daemon = HttpHooksCallbackDaemon(
231 txn_id=txn_id, host=host, port=port)
232 232 else:
233 233 log.error('Unsupported callback daemon protocol "%s"', protocol)
234 234 raise Exception('Unsupported callback daemon protocol.')
@@ -663,7 +663,7 b' class SimpleVCS(object):'
663 663
664 664 return prepare_callback_daemon(
665 665 extras, protocol=vcs_settings.HOOKS_PROTOCOL,
666 use_direct_calls=direct_calls, txn_id=txn_id)
666 host=vcs_settings.HOOKS_HOST, use_direct_calls=direct_calls, txn_id=txn_id)
667 667
668 668
669 669 def _should_check_locking(query_string):
@@ -51,6 +51,7 b' ARCHIVE_SPECS = {'
51 51
52 52 HOOKS_PROTOCOL = None
53 53 HOOKS_DIRECT_CALLS = False
54 HOOKS_HOST = '127.0.0.1'
54 55
55 56
56 57 def available_aliases():
@@ -622,6 +622,7 b' class PullRequestModel(BaseModel):'
622 622
623 623 callback_daemon, extras = prepare_callback_daemon(
624 624 extras, protocol=vcs_settings.HOOKS_PROTOCOL,
625 host=vcs_settings.HOOKS_HOST,
625 626 use_direct_calls=vcs_settings.HOOKS_DIRECT_CALLS)
626 627
627 628 with callback_daemon:
@@ -117,6 +117,7 b' class TestSanitizeVcsSettings(object):'
117 117 ('vcs.svn.compatible_version', ''),
118 118 ('git_rev_filter', '--all'),
119 119 ('vcs.hooks.protocol', 'http'),
120 ('vcs.hooks.host', '127.0.0.1'),
120 121 ('vcs.scm_app_implementation', 'http'),
121 122 ('vcs.server', ''),
122 123 ('vcs.server.log_level', 'debug'),
@@ -465,6 +465,7 b' class TestPrepareHooksDaemon(object):'
465 465 prepare_mock.assert_called_once_with(
466 466 expected_extras,
467 467 protocol=app_settings['vcs.hooks.protocol'],
468 host=app_settings['vcs.hooks.host'],
468 469 txn_id=None,
469 470 use_direct_calls=app_settings['vcs.hooks.direct_calls'])
470 471
@@ -180,7 +180,7 b' class TestHttpHooksCallbackDaemon(object'
180 180 assert daemon._daemon == tcp_server
181 181
182 182 _, port = tcp_server.server_address
183 expected_uri = '{}:{}'.format(daemon.IP_ADDRESS, port)
183 expected_uri = '{}:{}'.format('127.0.0.1', port)
184 184 msg = 'Preparing HTTP callback daemon at `{}` and ' \
185 185 'registering hook object'.format(expected_uri)
186 186 assert_message_in_log(
@@ -192,7 +192,7 b' class TestHttpHooksCallbackDaemon(object'
192 192 daemon = hooks_daemon.HttpHooksCallbackDaemon()
193 193
194 194 _, port = tcp_server.server_address
195 expected_uri = '{}:{}'.format(daemon.IP_ADDRESS, port)
195 expected_uri = '{}:{}'.format('127.0.0.1', port)
196 196 assert daemon.hooks_uri == expected_uri
197 197
198 198 msg = 'Preparing HTTP callback daemon at `{}` and ' \
@@ -264,7 +264,8 b' class TestPrepareHooksDaemon(object):'
264 264 self, protocol):
265 265 expected_extras = {'extra1': 'value1'}
266 266 callback, extras = hooks_daemon.prepare_callback_daemon(
267 expected_extras.copy(), protocol=protocol, use_direct_calls=True)
267 expected_extras.copy(), protocol=protocol,
268 host='127.0.0.1', use_direct_calls=True)
268 269 assert isinstance(callback, hooks_daemon.DummyHooksCallbackDaemon)
269 270 expected_extras['hooks_module'] = 'rhodecode.lib.hooks_daemon'
270 271 expected_extras['time'] = extras['time']
@@ -281,7 +282,8 b' class TestPrepareHooksDaemon(object):'
281 282 'hooks_protocol': protocol.lower()
282 283 }
283 284 callback, extras = hooks_daemon.prepare_callback_daemon(
284 expected_extras.copy(), protocol=protocol, use_direct_calls=False,
285 expected_extras.copy(), protocol=protocol, host='127.0.0.1',
286 use_direct_calls=False,
285 287 txn_id='txnid2')
286 288 assert isinstance(callback, expected_class)
287 289 extras.pop('hooks_uri')
@@ -301,7 +303,7 b' class TestPrepareHooksDaemon(object):'
301 303 with pytest.raises(Exception):
302 304 callback, extras = hooks_daemon.prepare_callback_daemon(
303 305 expected_extras.copy(),
304 protocol=protocol,
306 protocol=protocol, host='127.0.0.1',
305 307 use_direct_calls=False)
306 308
307 309
@@ -177,6 +177,7 b' def ini_config(request, tmpdir_factory, '
177 177 'vcs.server.protocol': 'http',
178 178 'vcs.scm_app_implementation': 'http',
179 179 'vcs.hooks.protocol': 'http',
180 'vcs.hooks.host': '127.0.0.1',
180 181 }},
181 182
182 183 {'handler_console': {
@@ -521,6 +521,7 b' vcs.scm_app_implementation = http'
521 521 ## Push/Pull operations hooks protocol, available options are:
522 522 ## `http` - use http-rpc backend (default)
523 523 vcs.hooks.protocol = http
524 vcs.hooks.host = 127.0.0.1
524 525
525 526 vcs.server.log_level = debug
526 527 ## Start VCSServer with this instance as a subprocess, usefull for development
General Comments 0
You need to be logged in to leave comments. Login now