From 31d4dad2be9ef0e8a153141cc8af443fc87f9c67 Mon Sep 17 00:00:00 2001 From: Marvin Martinson Date: Wed, 11 Aug 2021 19:43:55 +0000 Subject: [PATCH] Python code style fixes --- pinecrypt/server/api/utils/firewall.py | 12 +++++++----- pinecrypt/server/logger.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pinecrypt/server/api/utils/firewall.py b/pinecrypt/server/api/utils/firewall.py index 5ed415e..ab3023e 100644 --- a/pinecrypt/server/api/utils/firewall.py +++ b/pinecrypt/server/api/utils/firewall.py @@ -1,6 +1,4 @@ - import falcon -import logging import binascii import click import gssapi @@ -29,6 +27,7 @@ whitelist_blocked_requests = Counter( logger = LogHandler() + def whitelist_subnets(subnets): """ Validate source IP address of API call against subnet list @@ -93,8 +92,8 @@ def authenticate(optional=False): if req.context["remote"]["addr"] in subnet: kerberized = True - if not req.auth: # no credentials provided - if optional: # optional allowed + if not req.auth: # no credentials provided + if optional: # optional allowed req.context["user"] = None return func(resource, req, resp, *args, **kwargs) @@ -213,9 +212,11 @@ def authenticate(optional=False): def login_required(func): return authenticate()(func) + def login_optional(func): return authenticate(optional=True)(func) + def authorize_admin(func): @whitelist_subnets(const.ADMIN_SUBNETS) def wrapped(resource, req, resp, *args, **kwargs): @@ -231,6 +232,7 @@ def authorize_server(func): Make sure the request originator has a certificate with server flags """ from asn1crypto import pem, x509 + def wrapped(resource, req, resp, *args, **kwargs): buf = req.get_header("X-SSL-CERT") if not buf: @@ -281,7 +283,7 @@ def cookie_login(func): }, { "$set": { "last_seen": now, - } + } }) return func(resource, req, resp, *args, **kwargs) return wrapped diff --git a/pinecrypt/server/logger.py b/pinecrypt/server/logger.py index 8db8453..445af58 100644 --- a/pinecrypt/server/logger.py +++ b/pinecrypt/server/logger.py @@ -1,5 +1,6 @@ import time + class LoggerObject(object): msg = None args = None @@ -11,12 +12,16 @@ class CertidudeLogger(object): def info(self, msg, *args): self.pre_emit(msg, *args, level="Info") + def warning(self, msg, *args): self.pre_emit(msg, *args, level="Warning") + def error(self, msg, *args): self.pre_emit(msg, *args, level="Error") + def debug(self, msg, *args): self.pre_emit(msg, *args, level="Debug") + def pre_emit(self, msg, *args, level): record = LoggerObject() record.msg = msg @@ -24,5 +29,6 @@ class CertidudeLogger(object): record.levelname = level record.created = time.time() self.emit(record) - def emit(self,record): - console.log(record) + + def emit(self, record): + pass