async def get(self): if not self.get_argument('resource', False): self.set_status(400) self.write({"Error": "No resource was provided"}) resources = self.get_argument('resource') username, domain = extract_user(resources) if username == None and domain == None: self.write({"Error": "Bad resource provided"}) return if domain == DOMAIN: try: user = await self.application.objects.get(User, username=username) profile = await self.application.objects.get(user.profile) response = Webfinger(profile).generate() self.write(response) except User.DoesNotExist: self.write({"Error": "User not found"}) self.set_status(404) else: self.write({"Error": "Incorrect domain"}) self.set_status(400)
def on_get(self, req, resp): # For now I will assume that webfinger only asks for the actor, so resources # is just one element. if not 'resource' in req.params.keys(): raise falcon.HTTPBadRequest( description="No resource was provided along the request.") resources = req.params['resource'] username, domain = extract_user(resources) if username == None and domain == None: raise falcon.HTTPBadRequest( description="Unable to decode resource.") if domain == DOMAIN: user = User.get_or_none(username=username) if user: response = Webfinger(user).generate() resp.body = json.dumps(response) resp.status = falcon.HTTP_200 else: raise falcon.HTTPNotFound(description="User was not found.") else: raise falcon.HTTPBadRequest( description="Resouce domain doesn't match local domain.")
def user_from_uri(uri): username, domain = extract_user(uri) user = User.get_or_none(username=username) return user