From 07c650b9e178a729f6ca461206de664862d8f647 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Thu, 26 Oct 2017 07:13:28 -0700 Subject: [PATCH] add /log handler, link to it from /responses reuses LogHandler newly moved from bridgy to webutil in snarfed/webutil@a49b3af4d16b0cb1ec9426b95d8303c05143e40c --- app.yaml | 3 ++- logs.py | 23 ++++++++++++++--------- templates/responses.html | 11 +++++++++-- webmention.py | 1 + 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app.yaml b/app.yaml index 010ae5e..3ece4ef 100644 --- a/app.yaml +++ b/app.yaml @@ -1,6 +1,7 @@ # https://cloud.google.com/appengine/docs/standard/python/config/appref # application: bridgy-federated +# version: 1 runtime: python27 threadsafe: yes api_version: 1 @@ -62,7 +63,7 @@ handlers: script: render.app secure: always -- url: /responses +- url: /(log|responses) script: logs.app secure: always diff --git a/logs.py b/logs.py index 9e3de5a..46aa714 100644 --- a/logs.py +++ b/logs.py @@ -1,20 +1,22 @@ -"""Handlers and utilities for exposing app logs to users. -""" -import cgi +"""Render recent responses and logs.""" +import calendar import datetime -import logging -import re -import urllib import appengine_config -from google.appengine.api import logservice -from google.appengine.ext import ndb -from oauth_dropins.webutil.handlers import TemplateHandler + from oauth_dropins.webutil import util +from oauth_dropins.webutil.handlers import TemplateHandler +from oauth_dropins.webutil import logs import webapp2 from models import Response +VERSION_1_DEPLOYED = datetime.datetime(2017, 10, 26, 16, 0) + + +class LogHandler(logs.LogHandler): + VERSION_IDS = ['1'] + class ResponsesHandler(TemplateHandler): """Renders recent Responses, with links to logs.""" @@ -28,6 +30,8 @@ class ResponsesHandler(TemplateHandler): for r in responses: r.source, r.target = [util.pretty_link(url) for url in r.key.id().split(' ')] + if r.updated >= VERSION_1_DEPLOYED: + r.start_time = calendar.timegm(r.updated.timetuple()) return { 'responses': responses, @@ -35,5 +39,6 @@ class ResponsesHandler(TemplateHandler): app = webapp2.WSGIApplication([ + ('/log', LogHandler), ('/responses', ResponsesHandler), ], debug=appengine_config.DEBUG) diff --git a/templates/responses.html b/templates/responses.html index ba55f66..5a13245 100644 --- a/templates/responses.html +++ b/templates/responses.html @@ -15,14 +15,21 @@

Recent requests we've attempted to federate.

- + {% for r in responses %} - + {% endfor %}
Source Target Protocol Status Log
Source Target Protocol Status Time (click for log)
{{ r.source|safe }} {{ r.target|safe }} {{ r.protocol }} {{ r.status }}{{ r.updated.replace(microsecond=0) }} + {# TODO: support inbound too #} + {% if r.direction == 'out' and r.start_time %} + + {% endif %} + {{ r.updated.replace(microsecond=0) }} + {% if r.direction == 'out' %}{% endif %} +
diff --git a/webmention.py b/webmention.py index a6d9cec..efe89e9 100644 --- a/webmention.py +++ b/webmention.py @@ -41,6 +41,7 @@ class WebmentionHandler(webapp2.RequestHandler): logging.info('Params: %s', self.request.params.items()) source = util.get_required_param(self, 'source') target = util.get_required_param(self, 'target') + logging.info('source target: %s %s', source, target) try: msg = 'Bridgy Fed: new webmention from %s' % source