##// END OF EJS Templates
http-app: refactor new usage of main http api endpoints
super-admin -
r1123:f468f658 python3
parent child Browse files
Show More
@@ -18,7 +18,6 b''
18 import io
18 import io
19 import os
19 import os
20 import sys
20 import sys
21 import base64
22 import locale
21 import locale
23 import logging
22 import logging
24 import uuid
23 import uuid
@@ -37,11 +36,12 b' from pyramid.config import Configurator'
37 from pyramid.wsgi import wsgiapp
36 from pyramid.wsgi import wsgiapp
38 from pyramid.response import Response
37 from pyramid.response import Response
39
38
40 from vcsserver.base import BinaryEnvelope
39 from vcsserver.base import BytesEnvelope, BinaryEnvelope
41 from vcsserver.lib.rc_json import json
40 from vcsserver.lib.rc_json import json
42 from vcsserver.config.settings_maker import SettingsMaker
41 from vcsserver.config.settings_maker import SettingsMaker
43 from vcsserver.str_utils import safe_int, safe_bytes, safe_str
42 from vcsserver.str_utils import safe_int
44 from vcsserver.lib.statsd_client import StatsdClient
43 from vcsserver.lib.statsd_client import StatsdClient
44 from vcsserver.tweens.request_wrapper import get_call_context, get_headers_call_context
45
45
46 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
47
47
@@ -234,6 +234,7 b' class HTTPApplication(object):'
234
234
235 self.global_config = global_config
235 self.global_config = global_config
236 self.config.include('vcsserver.lib.rc_cache')
236 self.config.include('vcsserver.lib.rc_cache')
237 self.config.include('vcsserver.lib.rc_cache.archive_cache')
237
238
238 settings_locale = settings.get('locale', '') or 'en_US.UTF-8'
239 settings_locale = settings.get('locale', '') or 'en_US.UTF-8'
239 vcs = VCS(locale_conf=settings_locale, cache_config=settings)
240 vcs = VCS(locale_conf=settings_locale, cache_config=settings)
@@ -330,7 +331,7 b' class HTTPApplication(object):'
330
331
331 request.registry.vcs_call_context = {
332 request.registry.vcs_call_context = {
332 'method': method,
333 'method': method,
333 'repo_name': payload.get('_repo_name')
334 'repo_name': payload.get('_repo_name'),
334 }
335 }
335
336
336 if wire:
337 if wire:
@@ -345,7 +346,8 b' class HTTPApplication(object):'
345 if log.isEnabledFor(logging.DEBUG):
346 if log.isEnabledFor(logging.DEBUG):
346 # also we SKIP printing out any of those methods args since they maybe excessive
347 # also we SKIP printing out any of those methods args since they maybe excessive
347 just_args_methods = {
348 just_args_methods = {
348 'commitctx': ('content', 'removed', 'updated')
349 'commitctx': ('content', 'removed', 'updated'),
350 'commit': ('content', 'removed', 'updated')
349 }
351 }
350 if method in just_args_methods:
352 if method in just_args_methods:
351 skip_args = just_args_methods[method]
353 skip_args = just_args_methods[method]
@@ -506,10 +508,13 b' class HTTPApplication(object):'
506 def _render(value, system):
508 def _render(value, system):
507 bin_type = False
509 bin_type = False
508 res = value.get('result')
510 res = value.get('result')
509 if res and isinstance(res, BinaryEnvelope):
511 if isinstance(res, BytesEnvelope):
512 log.debug('Result is wrapped in BytesEnvelope type')
513 bin_type = True
514 elif isinstance(res, BinaryEnvelope):
510 log.debug('Result is wrapped in BinaryEnvelope type')
515 log.debug('Result is wrapped in BinaryEnvelope type')
511 value['result'] = res.value
516 value['result'] = res.val
512 bin_type = res.bin_type
517 bin_type = True
513
518
514 request = system.get('request')
519 request = system.get('request')
515 if request is not None:
520 if request is not None:
@@ -573,9 +578,7 b' class HTTPApplication(object):'
573 @wsgiapp
578 @wsgiapp
574 def _hg_stream(environ, start_response):
579 def _hg_stream(environ, start_response):
575 log.debug('http-app: handling hg stream')
580 log.debug('http-app: handling hg stream')
576
581 call_context = get_headers_call_context(environ)
577 packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT'])
578 call_context = msgpack.unpackb(packed_cc)
579
582
580 repo_path = call_context['repo_path']
583 repo_path = call_context['repo_path']
581 repo_name = call_context['repo_name']
584 repo_name = call_context['repo_name']
@@ -606,8 +609,7 b' class HTTPApplication(object):'
606 def _git_stream(environ, start_response):
609 def _git_stream(environ, start_response):
607 log.debug('http-app: handling git stream')
610 log.debug('http-app: handling git stream')
608
611
609 packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT'])
612 call_context = get_headers_call_context(environ)
610 call_context = msgpack.unpackb(packed_cc)
611
613
612 repo_path = call_context['repo_path']
614 repo_path = call_context['repo_path']
613 repo_name = call_context['repo_name']
615 repo_name = call_context['repo_name']
@@ -649,15 +651,18 b' class HTTPApplication(object):'
649
651
650 def handle_vcs_exception(self, exception, request):
652 def handle_vcs_exception(self, exception, request):
651 _vcs_kind = getattr(exception, '_vcs_kind', '')
653 _vcs_kind = getattr(exception, '_vcs_kind', '')
654
652 if _vcs_kind == 'repo_locked':
655 if _vcs_kind == 'repo_locked':
653 # Get custom repo-locked status code if present.
656 headers_call_context = get_headers_call_context(request.environ)
654 status_code = request.headers.get('X-RC-Locked-Status-Code')
657 status_code = safe_int(headers_call_context['locked_status_code'])
658
655 return HTTPRepoLocked(
659 return HTTPRepoLocked(
656 title=str(exception), status_code=status_code)
660 title=str(exception), status_code=status_code, headers=[('X-Rc-Locked', '1')])
657
661
658 elif _vcs_kind == 'repo_branch_protected':
662 elif _vcs_kind == 'repo_branch_protected':
659 # Get custom repo-branch-protected status code if present.
663 # Get custom repo-branch-protected status code if present.
660 return HTTPRepoBranchProtected(title=str(exception))
664 return HTTPRepoBranchProtected(
665 title=str(exception), headers=[('X-Rc-Branch-Protection', '1')])
661
666
662 exc_info = request.exc_info
667 exc_info = request.exc_info
663 store_exception(id(exc_info), exc_info)
668 store_exception(id(exc_info), exc_info)
@@ -767,7 +772,7 b' def main(global_config, **settings):'
767 pyramid_app = HTTPApplication(settings=settings, global_config=global_config).wsgi_app()
772 pyramid_app = HTTPApplication(settings=settings, global_config=global_config).wsgi_app()
768 total_time = time.time() - start_time
773 total_time = time.time() - start_time
769 log.info('Pyramid app `%s` created and configured in %.2fs',
774 log.info('Pyramid app `%s` created and configured in %.2fs',
770 getattr(pyramid_app, 'func_name', 'pyramid_app'), total_time)
775 pyramid_app.__class__, total_time)
771 return pyramid_app
776 return pyramid_app
772
777
773
778
General Comments 0
You need to be logged in to leave comments. Login now