Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
patching the default cornice service (which would impact other uses of it)
"""
default_cors_headers = ("Backoff", "Retry-After", "Alert", "Content-Length", "Content-Type")
def error_handler(self, request):
return errors.json_error_handler(request)
@classmethod
def init_from_settings(cls, settings):
cls.cors_origins = tuple(aslist(settings["cors_origins"]))
cors_max_age = settings["cors_max_age_seconds"]
cls.cors_max_age = int(cors_max_age) if cors_max_age else None
class JsonLogFormatter(dockerflow_logging.JsonLogFormatter):
logger_name = "kinto"
@classmethod
def init_from_settings(cls, settings):
cls.logger_name = settings["project_name"]
def __init__(self, fmt=None, datefmt=None, style="%"):
# Do not let mozilla-cloud-services-logger constructor to improperly
# use style as the logger_name.
# See https://github.com/mozilla/mozilla-cloud-services-logger/issues/3
logger_name = self.logger_name
super().__init__(fmt, datefmt, style)
self.logger_name = logger_name
def get_user_info(request):
patching the default cornice service (which would impact other uses of it)
"""
default_cors_headers = ('Backoff', 'Retry-After', 'Alert',
'Content-Length')
def error_handler(self, request):
return errors.json_error_handler(request)
@classmethod
def init_from_settings(cls, settings):
cls.cors_origins = tuple(aslist(settings['cors_origins']))
cors_max_age = settings['cors_max_age_seconds']
cls.cors_max_age = int(cors_max_age) if cors_max_age else None
class JsonLogFormatter(dockerflow_logging.JsonLogFormatter):
logger_name = 'kinto'
@classmethod
def init_from_settings(cls, settings):
cls.logger_name = settings['project_name']
def __init__(self, fmt=None, datefmt=None, style='%'):
# Do not let mozilla-cloud-services-logger constructor to improperly
# use style as the logger_name.
# See https://github.com/mozilla/mozilla-cloud-services-logger/issues/3
logger_name = self.logger_name
super().__init__(fmt, datefmt, style)
self.logger_name = logger_name
def get_user_info(request):
LogRecord nstance, making those properties available for the formatter(s)
to use.
"""
def __init__(self, logger, extra=None):
super(AmoLoggerAdapter, self).__init__(logger, extra or {})
def process(self, msg, kwargs):
kwargs.setdefault('extra', {}).update({
'REMOTE_ADDR': core.get_remote_addr() or '',
'USERNAME': getattr(core.get_user(), 'username', None) or ''
})
return msg, kwargs
class JsonFormatter(dockerflow.logging.JsonLogFormatter):
"""Like JsonLogFormatter, but with uid and remoteAddressChain set from
current user and ip, following mozlog format, as well as an additional
severity field at the root of the output for stackdriver."""
# Map from Python logging levels to Stackdriver severity levels
STACKDRIVER_LEVEL_MAP = {
# 800 is EMERGENCY but Python doesn't have that
# 700 is ALERT but Python doesn't have that
logging.CRITICAL: 600,
logging.ERROR: 500,
logging.WARNING: 400,
# 300 is NOTICE but Python doesn't have that
logging.INFO: 200,
logging.DEBUG: 100,
logging.NOTSET: 0,
}