From 9008744c487ddc6130491898a3fd4568fab03c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sat, 8 Jul 2017 08:56:01 +0000 Subject: [PATCH] api: Make logger use unicode literals --- certidude/api/__init__.py | 8 ++++---- certidude/api/request.py | 14 +++++++------- certidude/api/script.py | 2 +- certidude/api/signed.py | 2 +- certidude/auth.py | 4 ++-- certidude/cli.py | 6 +++--- certidude/decorators.py | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/certidude/api/__init__.py b/certidude/api/__init__.py index 0a054f9..274123c 100644 --- a/certidude/api/__init__.py +++ b/certidude/api/__init__.py @@ -90,9 +90,9 @@ class SessionResource(object): ) if req.context.get("user").is_admin(): - logger.info("Logged in authority administrator %s from %s" % (req.context.get("user"), req.context.get("remote_addr"))) + logger.info(u"Logged in authority administrator %s from %s" % (req.context.get("user"), req.context.get("remote_addr"))) else: - logger.info("Logged in authority user %s from %s" % (req.context.get("user"), req.context.get("remote_addr"))) + logger.info(u"Logged in authority user %s from %s" % (req.context.get("user"), req.context.get("remote_addr"))) return dict( user = dict( name=req.context.get("user").name, @@ -156,11 +156,11 @@ class StaticResource(object): if content_encoding: resp.append_header("Content-Encoding", content_encoding) resp.stream = open(path, "rb") - logger.debug("Serving '%s' from '%s'", req.path, path) + logger.debug(u"Serving '%s' from '%s'", req.path, path) else: resp.status = falcon.HTTP_404 resp.body = "File '%s' not found" % req.path - logger.info("Fail '%s' not found, path resolved to '%s'", req.path, path) + logger.info(u"File '%s' not found, path resolved to '%s'", req.path, path) import ipaddress class NormalizeMiddleware(object): diff --git a/certidude/api/request.py b/certidude/api/request.py index 639565d..8d4d7e9 100644 --- a/certidude/api/request.py +++ b/certidude/api/request.py @@ -81,7 +81,7 @@ class RequestListResource(object): try: renewal_signature = b64decode(renewal_header) except TypeError, ValueError: - logger.error("Renewal failed, bad signature supplied for %s", common_name.value) + logger.error(u"Renewal failed, bad signature supplied for %s", common_name.value) reasons.append("Renewal failed, bad signature supplied") else: try: @@ -97,20 +97,20 @@ class RequestListResource(object): verifier.update(body) verifier.verify() except InvalidSignature: - logger.error("Renewal failed, invalid signature supplied for %s", common_name.value) + logger.error(u"Renewal failed, invalid signature supplied for %s", common_name.value) reasons.append("Renewal failed, invalid signature supplied") else: # At this point renewal signature was valid but we need to perform some extra checks if datetime.utcnow() > cert.not_valid_after: - logger.error("Renewal failed, current certificate for %s has expired", common_name.value) + logger.error(u"Renewal failed, current certificate for %s has expired", common_name.value) reasons.append("Renewal failed, current certificate expired") elif not config.CERTIFICATE_RENEWAL_ALLOWED: - logger.error("Renewal requested for %s, but not allowed by authority settings", common_name.value) + logger.error(u"Renewal requested for %s, but not allowed by authority settings", common_name.value) reasons.append("Renewal requested, but not allowed by authority settings") else: resp.set_header("Content-Type", "application/x-x509-user-cert") _, resp.body = authority._sign(csr, body, overwrite=True) - logger.info("Renewed certificate for %s", common_name.value) + logger.info(u"Renewed certificate for %s", common_name.value) return @@ -125,10 +125,10 @@ class RequestListResource(object): try: resp.set_header("Content-Type", "application/x-pem-file") _, resp.body = authority._sign(csr, body) - logger.info("Autosigned %s as %s is whitelisted", common_name.value, req.context.get("remote_addr")) + logger.info(u"Autosigned %s as %s is whitelisted", common_name.value, req.context.get("remote_addr")) return except EnvironmentError: - logger.info("Autosign for %s from %s failed, signed certificate already exists", + logger.info(u"Autosign for %s from %s failed, signed certificate already exists", common_name.value, req.context.get("remote_addr")) reasons.append("Autosign failed, signed certificate already exists") break diff --git a/certidude/api/script.py b/certidude/api/script.py index a46a899..3751881 100644 --- a/certidude/api/script.py +++ b/certidude/api/script.py @@ -34,5 +34,5 @@ class ScriptResource(): other_tags=other_tags, named_tags=named_tags, attributes=attribs.get("user").get("machine")) - logger.info("Served script %s for %s at %s" % (script, cn, req.context["remote_addr"])) + logger.info(u"Served script %s for %s at %s" % (script, cn, req.context["remote_addr"])) # TODO: Assert time is within reasonable range diff --git a/certidude/api/signed.py b/certidude/api/signed.py index 3d7e1ce..a72810f 100644 --- a/certidude/api/signed.py +++ b/certidude/api/signed.py @@ -38,7 +38,7 @@ class SignedCertificateDetailResource(object): logger.debug(u"Served certificate %s to %s as application/json", cn, req.context.get("remote_addr")) else: - logger.debug("Client did not accept application/json or application/x-pem-file") + logger.debug(u"Client did not accept application/json or application/x-pem-file") raise falcon.HTTPUnsupportedMediaType( "Client did not accept application/json or application/x-pem-file") diff --git a/certidude/auth.py b/certidude/auth.py index f0b775f..8c22f4b 100644 --- a/certidude/auth.py +++ b/certidude/auth.py @@ -99,10 +99,10 @@ def authenticate(optional=False): try: conn.simple_bind_s(upn, passwd) except ldap.STRONG_AUTH_REQUIRED: - logger.critical("LDAP server demands encryption, use ldaps:// instead of ldaps://") + logger.critical(u"LDAP server demands encryption, use ldaps:// instead of ldaps://") raise except ldap.SERVER_DOWN: - logger.critical("Failed to connect LDAP server at %s, are you sure LDAP server's CA certificate has been copied to this machine?", + logger.critical(u"Failed to connect LDAP server at %s, are you sure LDAP server's CA certificate has been copied to this machine?", config.LDAP_AUTHENTICATION_URI) raise except ldap.INVALID_CREDENTIALS: diff --git a/certidude/cli.py b/certidude/cli.py index 53bab37..c7ce96d 100755 --- a/certidude/cli.py +++ b/certidude/cli.py @@ -34,7 +34,7 @@ def fqdn_required(func): def wrapped(**args): common_name = args.get("common_name") if "." in common_name: - logger.info("Using fully qualified hostname %s" % common_name) + logger.info(u"Using fully qualified hostname %s" % common_name) else: raise ValueError("Fully qualified hostname not specified as common name, make sure hostname -f works") return func(**args) @@ -1422,10 +1422,10 @@ def certidude_serve(port, listen, fork, exit_handler): pidfile.write("%d\n" % pid) def exit_handler(): - logger.debug("Shutting down Certidude") + logger.debug(u"Shutting down Certidude") import atexit atexit.register(exit_handler) - logger.debug("Started Certidude at %s", const.FQDN) + logger.debug(u"Started Certidude at %s", const.FQDN) drop_privileges() diff --git a/certidude/decorators.py b/certidude/decorators.py index 7a7327d..c4ff04f 100644 --- a/certidude/decorators.py +++ b/certidude/decorators.py @@ -68,7 +68,7 @@ def serialize(func): import falcon def wrapped(instance, req, resp, **kwargs): if not req.client_accepts("application/json"): - logger.debug("Client did not accept application/json") + logger.debug(u"Client did not accept application/json") raise falcon.HTTPUnsupportedMediaType( "Client did not accept application/json") resp.set_header("Cache-Control", "no-cache, no-store, must-revalidate")