From 8dac5375b6d3c39a2705fe806c4dff448ee5dd2a Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Thu, 21 Nov 2013 11:09:33 +0100 Subject: [PATCH] add /info view for debugging purposes --- isso/__init__.py | 6 ++++-- isso/views/__init__.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/isso/__init__.py b/isso/__init__.py index dc4c650..2ff200f 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -60,7 +60,7 @@ from werkzeug.contrib.fixers import ProxyFix local = Local() local_manager = LocalManager([local]) -from isso import db, migrate, wsgi, ext +from isso import db, migrate, wsgi, ext, views from isso.core import ThreadedMixin, uWSGIMixin, Config from isso.utils import parse, http, JSONRequest, origin from isso.views import comments @@ -96,7 +96,9 @@ class Isso(object): self.signal = ext.Signal(*subscribers) self.urls = Map() - self.api = comments.API(self) + + views.Info(self) + comments.API(self) def sign(self, obj): return self.signer.dumps(obj) diff --git a/isso/views/__init__.py b/isso/views/__init__.py index 50cedfa..0b995cd 100644 --- a/isso/views/__init__.py +++ b/isso/views/__init__.py @@ -1,7 +1,19 @@ # -*- encoding: utf-8 -*- +from __future__ import unicode_literals + +import pkg_resources +dist = pkg_resources.get_distribution("isso") + +import json + +from werkzeug.wrappers import Response +from werkzeug.routing import Rule from werkzeug.exceptions import BadRequest +from isso import local +from isso.compat import text_type as str + class requires: """Verify that the request URL contains and can parse the parameter. @@ -33,3 +45,21 @@ class requires: return func(cls, env, req, *args, **kwargs) return dec + + +class Info(object): + + def __init__(self, isso): + self.moderation = isso.conf.getboolean("moderation", "enabled") + isso.urls.add(Rule('/info', endpoint=self.show)) + + def show(self, environ, request): + + rv = { + "version": dist.version, + "host": str(local("host")), + "origin": str(local("origin")), + "moderation": self.moderation, + } + + return Response(json.dumps(rv), 200, content_type="application/json")