From c33da46f190b3ee0559250258bf5876309c079aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Tue, 5 Apr 2016 15:02:05 +0300 Subject: [PATCH] Push server fixes --- certidude/authority.py | 2 +- certidude/push.py | 7 +++++-- certidude/static/js/certidude.js | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/certidude/authority.py b/certidude/authority.py index e24137e..fd67e52 100644 --- a/certidude/authority.py +++ b/certidude/authority.py @@ -169,7 +169,7 @@ def delete_request(common_name): push.publish("request-deleted", request.common_name) # Write empty certificate to long-polling URL - requests.delete(config.PUSH_PUBLISH % request.common_name, + requests.delete(config.PUSH_PUBLISH % request.fingerprint(), headers={"User-Agent": "Certidude API"}) diff --git a/certidude/push.py b/certidude/push.py index e5f0b2b..ae689a9 100644 --- a/certidude/push.py +++ b/certidude/push.py @@ -16,15 +16,18 @@ def publish(event_type, event_data): event_data = json.dumps(event_data, cls=MyEncoder) url = config.PUSH_PUBLISH % config.PUSH_TOKEN - click.echo("Publishing %s event %s on %s" % (event_type, event_data, url)) + click.echo("Publishing %s event '%s' on %s" % (event_type, event_data, url)) try: notification = requests.post( url, data=event_data, headers={"X-EventSource-Event": event_type, "User-Agent": "Certidude API"}) + if notification.status_code != requests.codes.created: + click.echo("Failed to submit event to push server, server responded %d, expected %d" % ( + notification.status_code, requests.codes.created)) except requests.exceptions.ConnectionError: - click.echo("Failed to submit event to push server: %s" % repr(event_data)) + click.echo("Failed to submit event to push server, connection error") class PushLogHandler(logging.Handler): """ diff --git a/certidude/static/js/certidude.js b/certidude/static/js/certidude.js index 799bd1c..18ec357 100644 --- a/certidude/static/js/certidude.js +++ b/certidude/static/js/certidude.js @@ -67,6 +67,7 @@ function onRequestSubmitted(e) { url: "/api/request/" + e.data + "/", dataType: "json", success: function(request, status, xhr) { + onRequestDeleted(e); // Delete any existing ones just in case $("#pending_requests").prepend( nunjucks.render('views/request.html', { request: request })); }