def __init__(self, handle, host, guid, public_key, *args, **kwargs): super().__init__(handle, *args, **kwargs) self.xrd.elements.append( Element("Alias", "%s/people/%s" % (host, guid))) username = handle.split("@")[0] self.xrd.links.append( Link(rel="http://microformats.org/profile/hcard", type_="text/html", href="%s/hcard/users/%s" % (host, guid))) self.xrd.links.append( Link(rel="http://joindiaspora.com/seed_location", type_="text/html", href=host)) self.xrd.links.append( Link(rel="http://joindiaspora.com/guid", type_="text/html", href=guid)) self.xrd.links.append( Link(rel="http://webfinger.net/rel/profile-page", type_="text/html", href="%s/u/%s" % (host, username))) self.xrd.links.append( Link(rel="http://schemas.google.com/g/2010#updates-from", type_="application/atom+xml", href="%s/public/%s.atom" % (host, username))) # Base64 the key # See https://wiki.diasporafoundation.org/Federation_Protocol_Overview#Diaspora_Public_Key try: base64_key = b64encode(bytes(public_key, encoding="UTF-8")).decode("ascii") except TypeError: # Python 2 base64_key = b64encode(public_key).decode("ascii") self.xrd.links.append( Link(rel="diaspora-public-key", type_="RSA", href=base64_key))
def __init__(self): super(HostMeta, self).__init__() self.attributes.append(('xmlns:hm','http://host-meta.net/ns/1.0')) hosts = getattr(settings, "WELLKNOWN_HOSTMETA_HOSTS", ('example.com',)) for host in hosts: self.elements.append(Element('hm:Host', host))
def get_host_meta(): """ This function services the well-known host-meta XRD data for RESTCONF API root discovery. """ if args.verbose > 0: print 'get_host_meta: entry' xrd_obj = XRD() # Add a few extra elements and links before RESTCONF to help make sure # the parsing/XPATH is correct xrd_obj.elements.append(Element('hm:Host', 'testDevice')) xrd_obj.links.append( Link(rel='license', href='http://www.apache.org/licenses/LICENSE-2.0')) xrd_obj.links.append(Link(rel='author', href='http://bcsw.net')) # Add the link for RESTCONF xrd_obj.links.append(Link(rel='restconf', href=args.root_resource)) # Add some extra links here as well xrd_obj.links.append(Link(rel='testPath', href='this/does/not/exist')) xrd_obj.links.append( Link(rel='http://oexchange.org/spec/0.8/rel/resident-target', type_='application/xrd+xml', href='http://twitter.com/oexchange.xrd')) # Convert to XML, pretty-print it to aid in debugging xrd_doc = xrd_obj.to_xml() return Response(xrd_doc.toprettyxml(indent=' '), mimetype='application/xrd+xml')
def __init__(self, address, *args, **kwargs): super().__init__(*args, **kwargs) subject = Element("Subject", "acct:%s" % address) self.xrd.elements.append(subject)