From 3b3731d873664db00c02603363f61d34c41a3990 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 25 Apr 2016 22:13:19 -0400 Subject: embed pixelated --- src/pixelated/resources/keys_resource.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/pixelated/resources/keys_resource.py (limited to 'src/pixelated/resources/keys_resource.py') diff --git a/src/pixelated/resources/keys_resource.py b/src/pixelated/resources/keys_resource.py new file mode 100644 index 00000000..9075ab9e --- /dev/null +++ b/src/pixelated/resources/keys_resource.py @@ -0,0 +1,30 @@ +from email.utils import parseaddr +from pixelated.resources import respond_json_deferred, BaseResource +from twisted.web import server + + +class KeysResource(BaseResource): + + isLeaf = True + + def __init__(self, services_factory): + BaseResource.__init__(self, services_factory) + + def render_GET(self, request): + _keymanager = self.keymanager(request) + + def finish_request(key): + if key.private: + respond_json_deferred(None, request, status_code=401) + else: + respond_json_deferred(key.get_active_json(), request) + + def key_not_found(_): + respond_json_deferred(None, request, status_code=404) + + _, key_to_find = parseaddr(request.args.get('search')[0]) + d = _keymanager.fetch_key(key_to_find) + d.addCallback(finish_request) + d.addErrback(key_not_found) + + return server.NOT_DONE_YET -- cgit v1.2.3