summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-12-05 21:57:33 -0600
committerDan McGee <dan@archlinux.org>2011-12-05 21:57:33 -0600
commitab9162ac1413b5f59833f7f710863643766ee2f5 (patch)
tree4e68b656c674bcd52e58064b6285060a3e243ecd
parentfb61a6acdf113e2c2266b93fb690b0444c175264 (diff)
Add pgp_keys visualize JSON view
This will be used for an SVG graph of all of the master and developer PGP keys. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--visualize/urls.py1
-rw-r--r--visualize/views.py48
2 files changed, 48 insertions, 1 deletions
diff --git a/visualize/urls.py b/visualize/urls.py
index 57ee0626..02d83bec 100644
--- a/visualize/urls.py
+++ b/visualize/urls.py
@@ -4,6 +4,7 @@ urlpatterns = patterns('visualize.views',
(r'^$', 'index', {}, 'visualize-index'),
(r'^by_arch/$', 'by_arch', {}, 'visualize-byarch'),
(r'^by_repo/$', 'by_repo', {}, 'visualize-byrepo'),
+ (r'^pgp_keys/$', 'pgp_keys', {}, 'visualize-pgp_keys'),
)
# vim: set ts=4 sw=4 et:
diff --git a/visualize/views.py b/visualize/views.py
index f2b1d63b..be6057b2 100644
--- a/visualize/views.py
+++ b/visualize/views.py
@@ -1,10 +1,14 @@
-from django.db.models import Count, Sum
+from datetime import datetime
+
+from django.contrib.auth.models import User
+from django.db.models import Count, Sum, Q
from django.http import HttpResponse
from django.utils import simplejson
from django.views.decorators.cache import cache_page
from django.views.generic.simple import direct_to_template
from main.models import Package, Arch, Repo
+from devel.models import MasterKey, PGPSignature
def index(request):
return direct_to_template(request, 'visualize/index.html', {})
@@ -66,4 +70,46 @@ def by_repo(request):
to_json = simplejson.dumps(data['by_repo'], ensure_ascii=False)
return HttpResponse(to_json, mimetype='application/json')
+
+@cache_page(1800)
+def pgp_keys(request):
+ node_list = []
+
+ users = User.objects.filter(is_active=True).select_related('userprofile')
+ node_list.extend({
+ 'name': dev.get_full_name(),
+ 'key': dev.userprofile.pgp_key,
+ 'group': 'dev'
+ } for dev in users.filter(groups__name='Developers'))
+ node_list.extend({
+ 'name': tu.get_full_name(),
+ 'key': tu.userprofile.pgp_key,
+ 'group': 'tu'
+ } for tu in users.filter(groups__name='Trusted Users').exclude(
+ groups__name='Developers'))
+
+ master_keys = MasterKey.objects.select_related('owner').filter(
+ revoked__isnull=True)
+ node_list.extend({
+ 'name': 'Master Key (%s)' % key.owner.get_full_name(),
+ 'key': key.pgp_key,
+ 'group': 'master'
+ } for key in master_keys)
+
+ node_list.append({
+ 'name': 'CA Cert Signing Authority',
+ 'key': 'A31D4F81EF4EBD07B456FA04D2BB0D0165D0FD58',
+ 'group': 'cacert',
+ })
+
+ not_expired = Q(expires__gt=datetime.now) | Q(expires__isnull=True)
+ signatures = PGPSignature.objects.filter(not_expired, valid=True)
+ edge_list = [{ 'signee': sig.signee, 'signer': sig.signer }
+ for sig in signatures]
+
+ data = { 'nodes': node_list, 'edges': edge_list }
+
+ to_json = simplejson.dumps(data, ensure_ascii=False)
+ return HttpResponse(to_json, mimetype='application/json')
+
# vim: set ts=4 sw=4 et: