Python code style fixes
This commit is contained in:
parent
08c9a1c7ec
commit
31d4dad2be
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user