diff --git a/development.ini b/development.ini --- a/development.ini +++ b/development.ini @@ -226,6 +226,13 @@ allow_custom_hooks_settings = True # CHANGELOG #################################### +### SSH CONFIG #### +#################################### + +## SSH is disabled by default, until an Administrator decides to enable it. +ssh_enabled = false + +#################################### ### CELERY CONFIG #### #################################### diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py --- a/kallithea/lib/base.py +++ b/kallithea/lib/base.py @@ -408,6 +408,7 @@ class BaseController(TGController): ## INI stored c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True)) c.visual.allow_custom_hooks_settings = str2bool(config.get('allow_custom_hooks_settings', True)) + c.ssh_enabled = str2bool(config.get('ssh_enabled', False)) c.instance_id = config.get('instance_id') c.issues_url = config.get('bugtracker', url('issues_url')) @@ -636,3 +637,15 @@ def jsonify(func, *args, **kwargs): log.warning(msg) log.debug("Returning JSON wrapped action output") return json.dumps(data, encoding='utf-8') + +@decorator.decorator +def IfSshEnabled(func, *args, **kwargs): + """Decorator for functions that can only be called if SSH access is enabled. + + If SSH access is disabled in the configuration file, HTTPNotFound is raised. + """ + if not c.ssh_enabled: + from kallithea.lib import helpers as h + h.flash(_("SSH access is disabled."), category='warning') + raise webob.exc.HTTPNotFound() + return func(*args, **kwargs) diff --git a/kallithea/lib/paster_commands/template.ini.mako b/kallithea/lib/paster_commands/template.ini.mako --- a/kallithea/lib/paster_commands/template.ini.mako +++ b/kallithea/lib/paster_commands/template.ini.mako @@ -323,6 +323,13 @@ allow_custom_hooks_settings = True # CHANGELOG <%text>#################################### +<%text>### SSH CONFIG #### +<%text>#################################### + +<%text>## SSH is disabled by default, until an Administrator decides to enable it. +ssh_enabled = false + +<%text>#################################### <%text>### CELERY CONFIG #### <%text>#################################### diff --git a/kallithea/tests/conftest.py b/kallithea/tests/conftest.py --- a/kallithea/tests/conftest.py +++ b/kallithea/tests/conftest.py @@ -42,6 +42,7 @@ def pytest_configure(): 'port': '4999', }, '[app:main]': { + 'ssh_enabled': 'true', 'app_instance_uuid': 'test', 'show_revision_number': 'true', 'beaker.cache.sql_cache_short.expire': '1',