# HG changeset patch # User Marcin Kuzminski # Date 2017-04-19 13:32:57 # Node ID f7580c8eba5a88d010b424bc4283a025d84bda9d # Parent 6a5ff1d6693fd5f992072dc46cdaa81e8c4479ab core: added ops view to pyramid to have a PING command with pure pyramid. diff --git a/rhodecode/apps/ops/__init__.py b/rhodecode/apps/ops/__init__.py new file mode 100644 --- /dev/null +++ b/rhodecode/apps/ops/__init__.py @@ -0,0 +1,35 @@ +# -*- 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/ + +from rhodecode.config.routing import ADMIN_PREFIX + + +def admin_routes(config): + config.add_route( + name='ops_ping', + pattern='/ping') + + +def includeme(config): + + config.include(admin_routes, route_prefix=ADMIN_PREFIX + '/ops') + + # Scan module for configuration decorators. + config.scan() diff --git a/rhodecode/apps/ops/views.py b/rhodecode/apps/ops/views.py new file mode 100644 --- /dev/null +++ b/rhodecode/apps/ops/views.py @@ -0,0 +1,54 @@ +# -*- 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 logging + +from pyramid.view import view_config + +from rhodecode.apps._base import BaseAppView + + +log = logging.getLogger(__name__) + + +class OpsView(BaseAppView): + + def load_default_context(self): + c = self._get_local_tmpl_context() + c.user = c.auth_user.get_instance() + self._register_global_c(c) + return c + + @view_config( + route_name='ops_ping', request_method='GET', + renderer='json_ext') + def ops_ping(self): + data = { + 'instance': self.request.registry.settings.get('instance_id'), + } + if getattr(self.request, 'user'): + data.update({ + 'caller_ip': self.request.user.ip_addr, + 'caller_name': self.request.user.username, + }) + return {'ok': data} + + + diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -284,6 +284,7 @@ def includeme(config): # apps config.include('rhodecode.apps._base') + config.include('rhodecode.apps.ops') config.include('rhodecode.apps.admin') config.include('rhodecode.apps.channelstream') diff --git a/rhodecode/model/settings.py b/rhodecode/model/settings.py --- a/rhodecode/model/settings.py +++ b/rhodecode/model/settings.py @@ -207,6 +207,7 @@ class SettingsModel(BaseModel): caches.clear_cache_manager(cache_manager) def get_all_settings(self, cache=False): + def _compute(): q = self._get_settings_query() if not q: diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -71,6 +71,7 @@ function registerRCRoutes() { pyroutes.register('repo_integrations_new', '%(repo_name)s/settings/integrations/new', ['repo_name']); pyroutes.register('repo_integrations_create', '%(repo_name)s/settings/integrations/%(integration)s/new', ['repo_name', 'integration']); pyroutes.register('repo_integrations_edit', '%(repo_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_name', 'integration', 'integration_id']); + pyroutes.register('ops_ping', '_admin/ops/ping', []); pyroutes.register('admin_settings_open_source', '_admin/settings/open_source', []); pyroutes.register('admin_settings_vcs_svn_generate_cfg', '_admin/settings/vcs/svn_generate_cfg', []); pyroutes.register('admin_settings_system', '_admin/settings/system', []);