]> git.ipfire.org Git - people/jschlag/pbs.git/blame - src/web/handlers_keys.py
Use autotools
[people/jschlag/pbs.git] / src / web / handlers_keys.py
CommitLineData
f6e6ff79
MT
1#!/usr/bin/python
2
3import tornado.web
4
5from handlers_base import BaseHandler
6
7class KeysActionHandler(BaseHandler):
8 def prepare(self):
9 if not self.current_user.has_perm("manage_keys"):
10 raise tornado.web.HTTPError(403)
11
12
13class KeysImportHandler(KeysActionHandler):
14 @tornado.web.authenticated
15 def get(self):
16 self.render("keys-import.html")
17
18 @tornado.web.authenticated
19 def post(self):
20 data = self.get_argument("data")
21
22 key = self.pakfire.keys.create(data)
23 assert key
24
25 self.redirect("/keys")
26
27
28class KeysDeleteHandler(KeysActionHandler):
29 @tornado.web.authenticated
30 def get(self, fingerprint):
31 key = self.pakfire.keys.get_by_fpr(fingerprint)
32 if not key:
33 raise tornado.web.HTTPError(404, "Could not find key: %s" % fingerprint)
34
35 confirmed = self.get_argument("confirmed", False)
36 if confirmed:
37 key.delete()
38
39 return self.redirect("/keys")
40
41 self.render("keys-delete.html", key=key)
42
43
44class KeysListHandler(BaseHandler):
45 def get(self):
46 keys = self.pakfire.keys.get_all()
47
48 self.render("keys-list.html", keys=keys)
49
50
51class KeysDownloadHandler(BaseHandler):
52 def get(self, fingerprint):
53 key = self.pakfire.keys.get_by_fpr(fingerprint)
54 if not key:
55 raise tornado.web.HTTPError(404, "Could not find key: %s" % fingerprint)
56
57 # Send the key data.
58 self.set_header("Content-Type", "text/plain")
59 self.write(key.key)