From 29f3e1fce9336f4e0827f19639b31886075e2e96 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Sat, 3 Feb 2018 12:54:36 +0200 Subject: [PATCH] api: script: drop usage of global authority import --- certidude/api/__init__.py | 2 +- certidude/api/script.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/certidude/api/__init__.py b/certidude/api/__init__.py index 3902ef4..34f5d32 100644 --- a/certidude/api/__init__.py +++ b/certidude/api/__init__.py @@ -229,7 +229,7 @@ def certidude_app(log_handlers=[]): # Extended attributes for scripting etc. app.add_route("/api/signed/{cn}/attr/", AttributeResource(authority, namespace="machine")) - app.add_route("/api/signed/{cn}/script/", ScriptResource()) + 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()) diff --git a/certidude/api/script.py b/certidude/api/script.py index 494e528..18bee8a 100644 --- a/certidude/api/script.py +++ b/certidude/api/script.py @@ -1,7 +1,7 @@ import falcon import logging import os -from certidude import const, config, authority +from certidude import const, config from certidude.decorators import serialize from jinja2 import Environment, FileSystemLoader from certidude.firewall import whitelist_subject @@ -10,9 +10,12 @@ logger = logging.getLogger(__name__) env = Environment(loader=FileSystemLoader(config.SCRIPT_DIR), trim_blocks=True) class ScriptResource(): + def __init__(self, authority): + self.authority = authority + @whitelist_subject def on_get(self, req, resp, cn): - path, buf, cert, attribs = authority.get_attributes(cn) + path, buf, cert, attribs = self.authority.get_attributes(cn) # TODO: are keys unique? named_tags = {} other_tags = []