From 7d514a3bc6872ddc0366d50d716347f50a4fb434 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Sat, 3 Feb 2018 12:57:27 +0200 Subject: [PATCH] api: tag: drop usage of global authority import --- certidude/api/__init__.py | 4 ++-- certidude/api/tag.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/certidude/api/__init__.py b/certidude/api/__init__.py index f093900..5b16e52 100644 --- a/certidude/api/__init__.py +++ b/certidude/api/__init__.py @@ -232,11 +232,11 @@ def certidude_app(log_handlers=[]): app.add_route("/api/signed/{cn}/script/", ScriptResource(authority)) # API calls used by pushed events on the JS end - app.add_route("/api/signed/{cn}/tag/", TagResource()) + app.add_route("/api/signed/{cn}/tag/", TagResource(authority)) app.add_route("/api/signed/{cn}/lease/", LeaseDetailResource(authority)) # API call used to delete existing tags - app.add_route("/api/signed/{cn}/tag/{tag}/", TagDetailResource()) + app.add_route("/api/signed/{cn}/tag/{tag}/", TagDetailResource(authority)) # Gateways can submit leases via this API call app.add_route("/api/lease/", LeaseResource(authority)) diff --git a/certidude/api/tag.py b/certidude/api/tag.py index a670588..5da02b3 100644 --- a/certidude/api/tag.py +++ b/certidude/api/tag.py @@ -1,18 +1,21 @@ import falcon import logging from xattr import getxattr, removexattr, setxattr -from certidude import authority, push +from certidude import push from certidude.auth import login_required, authorize_admin from certidude.decorators import serialize, csrf_protection logger = logging.getLogger(__name__) class TagResource(object): + def __init__(self, authority): + self.authority = authority + @serialize @login_required @authorize_admin def on_get(self, req, resp, cn): - path, buf, cert, signed, expires = authority.get_signed(cn) + path, buf, cert, signed, expires = self.authority.get_signed(cn) tags = [] try: for tag in getxattr(path, "user.xdg.tags").decode("utf-8").split(","): @@ -30,7 +33,7 @@ class TagResource(object): @login_required @authorize_admin def on_post(self, req, resp, cn): - path, buf, cert, signed, expires = authority.get_signed(cn) + path, buf, cert, signed, expires = self.authority.get_signed(cn) key, value = req.get_param("key", required=True), req.get_param("value", required=True) try: tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) @@ -46,11 +49,14 @@ class TagResource(object): class TagDetailResource(object): + def __init__(self, authority): + self.authority = authority + @csrf_protection @login_required @authorize_admin def on_put(self, req, resp, cn, tag): - path, buf, cert, signed, expires = authority.get_signed(cn) + path, buf, cert, signed, expires = self.authority.get_signed(cn) value = req.get_param("value", required=True) try: tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) @@ -72,7 +78,7 @@ class TagDetailResource(object): @login_required @authorize_admin def on_delete(self, req, resp, cn, tag): - path, buf, cert, signed, expires = authority.get_signed(cn) + path, buf, cert, signed, expires = self.authority.get_signed(cn) tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) tags.remove(tag) if not tags: