Add basic support for /.well-known/host-meta(.json)?, not much info in it so far but it works

This commit is contained in:
Danielle McLean 2017-10-27 12:25:17 +11:00
parent 0419a844ce
commit 00d7a29b2d
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
6 changed files with 54 additions and 1 deletions

View file

@ -25,6 +25,7 @@ python-slugify = "*"
markdown = "*" markdown = "*"
bleach = "*" bleach = "*"
django-debug-toolbar = "*" django-debug-toolbar = "*"
xrd = "*"
[dev-packages] [dev-packages]

15
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "89e62295608d784115e1097fc46d5aa458ad26971e7668a1835717f9409fddac" "sha256": "dc39eb988fd0df9d07f81c689d5ee326958f557b423bd98e6d52d0610e5691f5"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -164,6 +164,13 @@
], ],
"version": "==2.6" "version": "==2.6"
}, },
"isodate": {
"hashes": [
"sha256:aa4d33c06640f5352aca96e4b81afd8ab3b47337cc12089822d6f322ac772c81",
"sha256:2e364a3d5759479cdb2d37cce6b9376ea504db2ff90252a2e5b7cc89cc9ff2d8"
],
"version": "==0.6.0"
},
"lxml": { "lxml": {
"hashes": [ "hashes": [
"sha256:7a8715539adb41c78129983ba69d852e0102a3f51d559eeb91dce1f6290c4ad0", "sha256:7a8715539adb41c78129983ba69d852e0102a3f51d559eeb91dce1f6290c4ad0",
@ -397,6 +404,12 @@
"sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"
], ],
"version": "==0.5.1" "version": "==0.5.1"
},
"xrd": {
"hashes": [
"sha256:51d01f732b5b5b7983c5179ffaed864408d95a667b3a6630fe27aa7528274089"
],
"version": "==0.1"
} }
}, },
"develop": {} "develop": {}

View file

@ -5,4 +5,6 @@ from . import views
app_name = 'wellknowns' app_name = 'wellknowns'
urlpatterns = [ urlpatterns = [
url(r'^keybase.txt$', views.keybase, name='keybase'), url(r'^keybase.txt$', views.keybase, name='keybase'),
url(r'^host-meta$', views.host_meta_xml, name='host-meta'),
url(r'^host-meta.json$', views.host_meta_json, name='host-meta.json'),
] ]

View file

@ -0,0 +1,2 @@
from .static import keybase
from .host_meta import host_meta_xml, host_meta_json

View file

@ -0,0 +1,35 @@
from django.http import HttpResponse
from django.conf import settings
from lemoncurry.templatetags.lemoncurry_tags import get_package_json
from xrd import XRD, Attribute, Element, Link
def add_links(dest):
package = get_package_json()
links = (
Link(rel='license', href='https://creativecommons.org/licenses/by-sa/4.0/'),
Link(rel='code-repository', href=package['repository']),
)
dest.extend(links)
def host_meta(request):
h = XRD()
h.attributes.append(Attribute('xmlns:hm', 'http://host-meta.net/ns/1.0'))
h.elements.append(Element('hm:Host', request.META['HTTP_HOST']))
add_links(h.links)
return h
def host_meta_xml(request):
return HttpResponse(
host_meta(request).to_xml().toprettyxml(indent=' ', encoding='utf-8'),
content_type='application/xrd+xml',
)
def host_meta_json(request):
return HttpResponse(
host_meta(request).to_json(),
content_type='application/json'
)