From 4e50ddfc54132960ed79e9580edb336366379cbf Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Sat, 3 Feb 2018 12:55:42 +0200 Subject: [PATCH] api: signed: drop usage of global authority import --- certidude/api/__init__.py | 2 +- certidude/api/signed.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/certidude/api/__init__.py b/certidude/api/__init__.py index 34f5d32..f093900 100644 --- a/certidude/api/__init__.py +++ b/certidude/api/__init__.py @@ -219,7 +219,7 @@ def certidude_app(log_handlers=[]): # Certificate authority API calls app.add_route("/api/certificate/", CertificateAuthorityResource()) - app.add_route("/api/signed/{cn}/", SignedCertificateDetailResource()) + app.add_route("/api/signed/{cn}/", SignedCertificateDetailResource(authority)) app.add_route("/api/request/{cn}/", RequestDetailResource(authority)) app.add_route("/api/request/", RequestListResource(authority)) app.add_route("/api/", SessionResource()) diff --git a/certidude/api/signed.py b/certidude/api/signed.py index 07ea373..1974ed7 100644 --- a/certidude/api/signed.py +++ b/certidude/api/signed.py @@ -3,7 +3,6 @@ import falcon import logging import json import hashlib -from certidude import authority from certidude.auth import login_required, authorize_admin from certidude.decorators import csrf_protection from xattr import getxattr @@ -11,11 +10,14 @@ from xattr import getxattr logger = logging.getLogger(__name__) class SignedCertificateDetailResource(object): + def __init__(self, authority): + self.authority = authority + def on_get(self, req, resp, cn): preferred_type = req.client_prefers(("application/json", "application/x-pem-file")) try: - path, buf, cert, signed, expires = authority.get_signed(cn) + path, buf, cert, signed, expires = self.authority.get_signed(cn) except EnvironmentError: logger.warning("Failed to serve non-existant certificate %s to %s", cn, req.context.get("remote_addr")) @@ -55,5 +57,5 @@ class SignedCertificateDetailResource(object): def on_delete(self, req, resp, cn): logger.info("Revoked certificate %s by %s from %s", cn, req.context.get("user"), req.context.get("remote_addr")) - authority.revoke(cn) + self.authority.revoke(cn)