diff --git a/configs/development.ini b/configs/development.ini --- a/configs/development.ini +++ b/configs/development.ini @@ -162,6 +162,11 @@ startup.import_repos = false ## the repository. #archive_cache_dir = /tmp/tarballcache +## URL at which the application is running. This is used for bootstraping +## requests in context when no web request is available. Used in ishell, or +## SSH calls. Set this for events to receive proper url for SSH calls. +app.base_url = http://rhodecode.local + ## change this to unique ID for security app_instance_uuid = rc-production diff --git a/configs/production.ini b/configs/production.ini --- a/configs/production.ini +++ b/configs/production.ini @@ -137,6 +137,11 @@ startup.import_repos = false ## the repository. #archive_cache_dir = /tmp/tarballcache +## URL at which the application is running. This is used for bootstraping +## requests in context when no web request is available. Used in ishell, or +## SSH calls. Set this for events to receive proper url for SSH calls. +app.base_url = http://rhodecode.local + ## change this to unique ID for security app_instance_uuid = rc-production diff --git a/rhodecode/apps/ssh_support/lib/ssh_wrapper.py b/rhodecode/apps/ssh_support/lib/ssh_wrapper.py --- a/rhodecode/apps/ssh_support/lib/ssh_wrapper.py +++ b/rhodecode/apps/ssh_support/lib/ssh_wrapper.py @@ -24,9 +24,9 @@ import logging import click -from pyramid.paster import bootstrap, setup_logging -from pyramid.request import Request +from pyramid.paster import setup_logging +from rhodecode.lib.pyramid_utils import bootstrap from .backends import SshWrapper log = logging.getLogger(__name__) @@ -68,9 +68,7 @@ def main(ini_path, mode, user, user_id, 'of this script.') connection_info = os.environ.get('SSH_CONNECTION', '') - # TODO(marcink): configure the running host... - request = Request.blank('/', base_url='http://localhost:8080') - with bootstrap(ini_path, request=request) as env: + with bootstrap(ini_path) as env: try: ssh_wrapper = SshWrapper( command, connection_info, mode, diff --git a/rhodecode/lib/pyramid_utils.py b/rhodecode/lib/pyramid_utils.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/pyramid_utils.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2016-2017 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +import ConfigParser +from pyramid.paster import bootstrap as pyramid_bootstrap +from pyramid.request import Request + + +def get_config(ini_path): + parser = ConfigParser.ConfigParser() + parser.read(ini_path) + return parser + + +def bootstrap(config_uri, request=None, options=None): + + config = get_config(config_uri) + base_url = 'http://rhodecode.local' + try: + base_url = config.get('app:main', 'app.base_url') + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + pass + + request = request or Request.blank('/', base_url=base_url) + + return pyramid_bootstrap(config_uri, request=request, options=options) diff --git a/rhodecode/tests/rhodecode.ini b/rhodecode/tests/rhodecode.ini --- a/rhodecode/tests/rhodecode.ini +++ b/rhodecode/tests/rhodecode.ini @@ -207,6 +207,11 @@ startup.import_repos = true ## the repository. #archive_cache_dir = /tmp/tarballcache +## URL at which the application is running. This is used for bootstraping +## requests in context when no web request is available. Used in ishell, or +## SSH calls. Set this for events to receive proper url for SSH calls. +app.base_url = http://rhodecode.local + ## change this to unique ID for security app_instance_uuid = rc-production