From f4499a54590c191cc86ac294615a3d783c6c39b9 Mon Sep 17 00:00:00 2001 From: "Langhammer, Jens" Date: Tue, 1 Oct 2019 10:24:10 +0200 Subject: [PATCH] *(minor): stdlib logging to structlog --- .vscode/.ropeproject/config.py | 114 ------------------ .vscode/.ropeproject/objectdb | Bin 282 -> 0 bytes .vscode/settings.json | 14 --- .../admin/templatetags/admin_reflection.py | 4 +- .../app_gw/management/commands/app_gw_web.py | 5 +- passbook/app_gw/proxy/handler.py | 4 +- passbook/app_gw/proxy/response.py | 5 +- passbook/app_gw/proxy/utils.py | 5 +- passbook/app_gw/signals.py | 5 +- passbook/app_gw/websocket/consumer.py | 4 +- passbook/audit/models.py | 5 +- passbook/core/apps.py | 4 +- passbook/core/auth/factors/dummy.py | 4 +- passbook/core/auth/factors/password.py | 4 +- passbook/core/auth/view.py | 4 +- passbook/core/forms/authentication.py | 5 +- .../core/management/commands/import_users.py | 4 +- passbook/core/management/commands/web.py | 5 +- passbook/core/management/commands/worker.py | 5 +- passbook/core/models.py | 4 +- passbook/core/signals.py | 5 +- passbook/core/tasks.py | 4 +- passbook/core/urls.py | 5 +- passbook/core/views/access.py | 5 +- passbook/core/views/authentication.py | 4 +- passbook/hibp_policy/models.py | 4 +- passbook/ldap/auth.py | 5 +- passbook/ldap/ldap_connector.py | 4 +- passbook/lib/sentry.py | 4 +- passbook/lib/templatetags/is_active.py | 5 +- passbook/lib/templatetags/reflection.py | 5 +- passbook/oauth_client/apps.py | 4 +- passbook/oauth_client/clients.py | 4 +- .../oauth_client/source_types/azure_ad.py | 4 +- passbook/oauth_client/source_types/discord.py | 4 +- passbook/oauth_client/source_types/manager.py | 5 +- passbook/oauth_client/source_types/reddit.py | 4 +- .../oauth_client/source_types/supervisr.py | 4 +- passbook/oauth_client/source_types/twitter.py | 5 +- passbook/oauth_client/views/core.py | 5 +- passbook/oauth_provider/views/oauth2.py | 4 +- passbook/oidc_provider/apps.py | 5 +- passbook/oidc_provider/lib.py | 5 +- passbook/otp/factors.py | 5 +- passbook/otp/views.py | 4 +- passbook/password_expiry_policy/models.py | 4 +- passbook/policy/task.py | 5 +- passbook/root/celery.py | 8 +- passbook/root/urls.py | 5 +- passbook/saml_idp/apps.py | 4 +- passbook/saml_idp/base.py | 4 +- passbook/saml_idp/models.py | 5 +- passbook/saml_idp/views.py | 5 +- passbook/saml_idp/xml_render.py | 4 +- passbook/saml_idp/xml_signing.py | 5 +- passbook/suspicious_policy/signals.py | 5 +- 56 files changed, 111 insertions(+), 259 deletions(-) delete mode 100644 .vscode/.ropeproject/config.py delete mode 100644 .vscode/.ropeproject/objectdb delete mode 100644 .vscode/settings.json diff --git a/.vscode/.ropeproject/config.py b/.vscode/.ropeproject/config.py deleted file mode 100644 index dee2d1ae9..000000000 --- a/.vscode/.ropeproject/config.py +++ /dev/null @@ -1,114 +0,0 @@ -# The default ``config.py`` -# flake8: noqa - - -def set_prefs(prefs): - """This function is called before opening the project""" - - # Specify which files and folders to ignore in the project. - # Changes to ignored resources are not added to the history and - # VCSs. Also they are not returned in `Project.get_files()`. - # Note that ``?`` and ``*`` match all characters but slashes. - # '*.pyc': matches 'test.pyc' and 'pkg/test.pyc' - # 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc' - # '.svn': matches 'pkg/.svn' and all of its children - # 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' - # 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' - prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject', - '.hg', '.svn', '_svn', '.git', '.tox'] - - # Specifies which files should be considered python files. It is - # useful when you have scripts inside your project. Only files - # ending with ``.py`` are considered to be python files by - # default. - # prefs['python_files'] = ['*.py'] - - # Custom source folders: By default rope searches the project - # for finding source folders (folders that should be searched - # for finding modules). You can add paths to that list. Note - # that rope guesses project source folders correctly most of the - # time; use this if you have any problems. - # The folders should be relative to project root and use '/' for - # separating folders regardless of the platform rope is running on. - # 'src/my_source_folder' for instance. - # prefs.add('source_folders', 'src') - - # You can extend python path for looking up modules - # prefs.add('python_path', '~/python/') - - # Should rope save object information or not. - prefs['save_objectdb'] = True - prefs['compress_objectdb'] = False - - # If `True`, rope analyzes each module when it is being saved. - prefs['automatic_soa'] = True - # The depth of calls to follow in static object analysis - prefs['soa_followed_calls'] = 0 - - # If `False` when running modules or unit tests "dynamic object - # analysis" is turned off. This makes them much faster. - prefs['perform_doa'] = True - - # Rope can check the validity of its object DB when running. - prefs['validate_objectdb'] = True - - # How many undos to hold? - prefs['max_history_items'] = 32 - - # Shows whether to save history across sessions. - prefs['save_history'] = True - prefs['compress_history'] = False - - # Set the number spaces used for indenting. According to - # :PEP:`8`, it is best to use 4 spaces. Since most of rope's - # unit-tests use 4 spaces it is more reliable, too. - prefs['indent_size'] = 4 - - # Builtin and c-extension modules that are allowed to be imported - # and inspected by rope. - prefs['extension_modules'] = [] - - # Add all standard c-extensions to extension_modules list. - prefs['import_dynload_stdmods'] = True - - # If `True` modules with syntax errors are considered to be empty. - # The default value is `False`; When `False` syntax errors raise - # `rope.base.exceptions.ModuleSyntaxError` exception. - prefs['ignore_syntax_errors'] = False - - # If `True`, rope ignores unresolvable imports. Otherwise, they - # appear in the importing namespace. - prefs['ignore_bad_imports'] = False - - # If `True`, rope will insert new module imports as - # `from import ` by default. - prefs['prefer_module_from_imports'] = False - - # If `True`, rope will transform a comma list of imports into - # multiple separate import statements when organizing - # imports. - prefs['split_imports'] = False - - # If `True`, rope will remove all top-level import statements and - # reinsert them at the top of the module when making changes. - prefs['pull_imports_to_top'] = True - - # If `True`, rope will sort imports alphabetically by module name instead - # of alphabetically by import statement, with from imports after normal - # imports. - prefs['sort_imports_alphabetically'] = False - - # Location of implementation of - # rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general - # case, you don't have to change this value, unless you're an rope expert. - # Change this value to inject you own implementations of interfaces - # listed in module rope.base.oi.type_hinting.providers.interfaces - # For example, you can add you own providers for Django Models, or disable - # the search type-hinting in a class hierarchy, etc. - prefs['type_hinting_factory'] = ( - 'rope.base.oi.type_hinting.factory.default_type_hinting_factory') - - -def project_opened(project): - """This function is called after opening the project""" - # Do whatever you like here! diff --git a/.vscode/.ropeproject/objectdb b/.vscode/.ropeproject/objectdb deleted file mode 100644 index ac516f28e66b2c7951709da3989910d805a0aac0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 282 zcmbWxO-{ow5C!1S0!ah3y+#+c7nRs>0v45!V3A#9JJZ?_|4hb$8YvPiDA&g22;I)p zy!U-gMl70#qA0+<^WI1vQq>?=UX6I&l=;1bopI1% zd8UYr4LzJh)jy|wIzhMD^O6GK>=)}FylJXDWgJD}6yU8cb)|E3cf>i3xH#fc60twj CkY1bs diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0b70cee17..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "python.pythonPath": "env/bin/python", - "editor.tabSize": 4, - "[html]": { - "editor.tabSize": 2 - }, - "[yml]": { - "editor.tabSize": 2 - }, - "cSpell.words": [ - "SAML", - "passbook" - ] -} diff --git a/passbook/admin/templatetags/admin_reflection.py b/passbook/admin/templatetags/admin_reflection.py index 7d4cbe302..d4e3359f3 100644 --- a/passbook/admin/templatetags/admin_reflection.py +++ b/passbook/admin/templatetags/admin_reflection.py @@ -1,14 +1,14 @@ """passbook admin templatetags""" import inspect -from logging import getLogger from django import template from django.db.models import Model +from structlog import get_logger from passbook.lib.utils.template import render_to_string register = template.Library() -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @register.simple_tag() def get_links(model_instance): diff --git a/passbook/app_gw/management/commands/app_gw_web.py b/passbook/app_gw/management/commands/app_gw_web.py index 5b6945ce1..7ce281304 100644 --- a/passbook/app_gw/management/commands/app_gw_web.py +++ b/passbook/app_gw/management/commands/app_gw_web.py @@ -1,14 +1,13 @@ """passbook app_gw webserver management command""" -from logging import getLogger - from daphne.cli import CommandLineInterface from django.core.management.base import BaseCommand from django.utils import autoreload +from structlog import get_logger from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class Command(BaseCommand): diff --git a/passbook/app_gw/proxy/handler.py b/passbook/app_gw/proxy/handler.py index 15ca0d64d..fc652cb1a 100644 --- a/passbook/app_gw/proxy/handler.py +++ b/passbook/app_gw/proxy/handler.py @@ -1,6 +1,5 @@ """passbook app_gw request handler""" import mimetypes -from logging import getLogger from random import SystemRandom from urllib.parse import urlparse @@ -8,6 +7,7 @@ import certifi import urllib3 from django.core.cache import cache from django.utils.http import urlencode +from structlog import get_logger from passbook.app_gw.models import ApplicationGatewayProvider from passbook.app_gw.proxy.exceptions import InvalidUpstream @@ -19,7 +19,7 @@ from passbook.policy.engine import PolicyEngine SESSION_UPSTREAM_KEY = 'passbook_app_gw_upstream' IGNORED_HOSTNAMES_KEY = 'passbook_app_gw_ignored' -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) QUOTE_SAFE = r'<.;>\(}*+|~=-$/_:^@)[{]&\'!,"`' ERRORS_MESSAGES = { 'upstream-no-scheme': ("Upstream URL scheme must be either " diff --git a/passbook/app_gw/proxy/response.py b/passbook/app_gw/proxy/response.py index 3984953bc..6088c52d3 100644 --- a/passbook/app_gw/proxy/response.py +++ b/passbook/app_gw/proxy/response.py @@ -1,7 +1,6 @@ """response functions from django-revproxy""" -import logging - from django.http import HttpResponse, StreamingHttpResponse +from structlog import get_logger from passbook.app_gw.proxy.utils import (cookie_from_string, set_response_headers, should_stream) @@ -9,7 +8,7 @@ from passbook.app_gw.proxy.utils import (cookie_from_string, #: Default number of bytes that are going to be read in a file lecture DEFAULT_AMT = 2 ** 16 -logger = logging.getLogger(__name__) +logger = get_logger(__name__) def get_django_response(proxy_response, strict_cookies=False): diff --git a/passbook/app_gw/proxy/utils.py b/passbook/app_gw/proxy/utils.py index 820d8d12d..4ec691bd0 100644 --- a/passbook/app_gw/proxy/utils.py +++ b/passbook/app_gw/proxy/utils.py @@ -1,8 +1,9 @@ """Utils from django-revproxy, slightly adjusted""" -import logging import re from wsgiref.util import is_hop_by_hop +from structlog import get_logger + try: from http.cookies import SimpleCookie COOKIE_PREFIX = '' @@ -155,7 +156,7 @@ def encode_items(items): return encoded -logger = logging.getLogger('revproxy.cookies') +logger = get_logger() def cookie_from_string(cookie_string, strict_cookies=False): diff --git a/passbook/app_gw/signals.py b/passbook/app_gw/signals.py index 163432681..19a7600f8 100644 --- a/passbook/app_gw/signals.py +++ b/passbook/app_gw/signals.py @@ -1,15 +1,14 @@ """passbook app_gw cache clean signals""" -from logging import getLogger - from django.core.cache import cache from django.db.models.signals import post_save from django.dispatch import receiver +from structlog import get_logger from passbook.app_gw.models import ApplicationGatewayProvider from passbook.app_gw.proxy.handler import IGNORED_HOSTNAMES_KEY -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @receiver(post_save) # pylint: disable=unused-argument diff --git a/passbook/app_gw/websocket/consumer.py b/passbook/app_gw/websocket/consumer.py index bedfa41ad..303aa93d0 100644 --- a/passbook/app_gw/websocket/consumer.py +++ b/passbook/app_gw/websocket/consumer.py @@ -1,14 +1,14 @@ """websocket proxy consumer""" import threading -from logging import getLogger from ssl import CERT_NONE import websocket from channels.generic.websocket import WebsocketConsumer +from structlog import get_logger from passbook.app_gw.models import ApplicationGatewayProvider -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class ProxyConsumer(WebsocketConsumer): """Proxy websocket connection to upstream""" diff --git a/passbook/audit/models.py b/passbook/audit/models.py index c54447e74..a12a3c5e6 100644 --- a/passbook/audit/models.py +++ b/passbook/audit/models.py @@ -1,6 +1,4 @@ """passbook audit models""" -from logging import getLogger - from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.contrib.postgres.fields import JSONField @@ -8,10 +6,11 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext as _ from ipware import get_client_ip +from structlog import get_logger from passbook.lib.models import UUIDModel -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class AuditEntry(UUIDModel): """An individual audit log entry""" diff --git a/passbook/core/apps.py b/passbook/core/apps.py index 198a3eb43..ac2e58b34 100644 --- a/passbook/core/apps.py +++ b/passbook/core/apps.py @@ -1,12 +1,12 @@ """passbook core app config""" from importlib import import_module -from logging import getLogger from django.apps import AppConfig +from structlog import get_logger from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PassbookCoreConfig(AppConfig): """passbook core app config""" diff --git a/passbook/core/auth/factors/dummy.py b/passbook/core/auth/factors/dummy.py index 593916409..fda43b9b7 100644 --- a/passbook/core/auth/factors/dummy.py +++ b/passbook/core/auth/factors/dummy.py @@ -1,9 +1,9 @@ """passbook multi-factor authentication engine""" -from logging import getLogger +from structlog import get_logger from passbook.core.auth.factor import AuthenticationFactor -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class DummyFactor(AuthenticationFactor): diff --git a/passbook/core/auth/factors/password.py b/passbook/core/auth/factors/password.py index 1be36d663..416fe9398 100644 --- a/passbook/core/auth/factors/password.py +++ b/passbook/core/auth/factors/password.py @@ -1,6 +1,5 @@ """passbook multi-factor authentication engine""" from inspect import Signature -from logging import getLogger from django.contrib import messages from django.contrib.auth import _clean_credentials @@ -10,6 +9,7 @@ from django.forms.utils import ErrorList from django.shortcuts import redirect, reverse from django.utils.translation import gettext as _ from django.views.generic import FormView +from structlog import get_logger from passbook.core.auth.factor import AuthenticationFactor from passbook.core.auth.view import AuthenticationView @@ -19,7 +19,7 @@ from passbook.core.tasks import send_email from passbook.lib.config import CONFIG from passbook.lib.utils.reflection import path_to_class -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def authenticate(request, backends, **credentials): diff --git a/passbook/core/auth/view.py b/passbook/core/auth/view.py index 4173abfe9..242f667ab 100644 --- a/passbook/core/auth/view.py +++ b/passbook/core/auth/view.py @@ -1,5 +1,4 @@ """passbook multi-factor authentication engine""" -from logging import getLogger from typing import List, Tuple from django.contrib.auth import login @@ -7,6 +6,7 @@ from django.contrib.auth.mixins import UserPassesTestMixin from django.shortcuts import get_object_or_404, redirect, reverse from django.utils.http import urlencode from django.views.generic import View +from structlog import get_logger from passbook.core.models import Factor, User from passbook.core.views.utils import PermissionDeniedView @@ -14,7 +14,7 @@ from passbook.lib.utils.reflection import class_to_path, path_to_class from passbook.lib.utils.urls import is_url_absolute from passbook.policy.engine import PolicyEngine -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def _redirect_with_qs(view, get_query_set=None): """Wrapper to redirect whilst keeping GET Parameters""" diff --git a/passbook/core/forms/authentication.py b/passbook/core/forms/authentication.py index 0f83059ab..875285702 100644 --- a/passbook/core/forms/authentication.py +++ b/passbook/core/forms/authentication.py @@ -1,16 +1,15 @@ """passbook core authentication forms""" -from logging import getLogger - from django import forms from django.core.exceptions import ValidationError from django.core.validators import validate_email from django.utils.translation import gettext_lazy as _ +from structlog import get_logger from passbook.core.models import User from passbook.lib.config import CONFIG from passbook.lib.utils.ui import human_list -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class LoginForm(forms.Form): """Allow users to login""" diff --git a/passbook/core/management/commands/import_users.py b/passbook/core/management/commands/import_users.py index c0b1a829b..dedc1b1ac 100644 --- a/passbook/core/management/commands/import_users.py +++ b/passbook/core/management/commands/import_users.py @@ -1,13 +1,13 @@ """passbook import_users management command""" from csv import DictReader -from logging import getLogger from django.core.management.base import BaseCommand from django.core.validators import EmailValidator, ValidationError +from structlog import get_logger from passbook.core.models import User -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class Command(BaseCommand): """Import users from CSV file""" diff --git a/passbook/core/management/commands/web.py b/passbook/core/management/commands/web.py index 562fe8b6f..a85870949 100644 --- a/passbook/core/management/commands/web.py +++ b/passbook/core/management/commands/web.py @@ -1,15 +1,14 @@ """passbook Webserver management command""" -from logging import getLogger - import cherrypy from django.conf import settings from django.core.management.base import BaseCommand +from structlog import get_logger from passbook.lib.config import CONFIG from passbook.root.wsgi import application -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class Command(BaseCommand): diff --git a/passbook/core/management/commands/worker.py b/passbook/core/management/commands/worker.py index c4a56045f..3e2ca36df 100644 --- a/passbook/core/management/commands/worker.py +++ b/passbook/core/management/commands/worker.py @@ -1,13 +1,12 @@ """passbook Worker management command""" -from logging import getLogger - from django.core.management.base import BaseCommand from django.utils import autoreload +from structlog import get_logger from passbook.root.celery import CELERY_APP -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class Command(BaseCommand): diff --git a/passbook/core/models.py b/passbook/core/models.py index 1b8e274a9..96266fe88 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -1,7 +1,6 @@ """passbook core models""" import re from datetime import timedelta -from logging import getLogger from random import SystemRandom from time import sleep from typing import List @@ -14,11 +13,12 @@ from django.urls import reverse_lazy from django.utils.timezone import now from django.utils.translation import gettext as _ from model_utils.managers import InheritanceManager +from structlog import get_logger from passbook.core.signals import password_changed from passbook.lib.models import CreatedUpdatedModel, UUIDModel -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def default_nonce_duration(): diff --git a/passbook/core/signals.py b/passbook/core/signals.py index 6806690f7..60fdac8fd 100644 --- a/passbook/core/signals.py +++ b/passbook/core/signals.py @@ -1,14 +1,13 @@ """passbook core signals""" -from logging import getLogger - from django.core.cache import cache from django.core.signals import Signal from django.db.models.signals import post_save from django.dispatch import receiver +from structlog import get_logger from passbook.core.exceptions import PasswordPolicyInvalid -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) user_signed_up = Signal(providing_args=['request', 'user']) invitation_created = Signal(providing_args=['request', 'invitation']) diff --git a/passbook/core/tasks.py b/passbook/core/tasks.py index 0abb9ecfa..fc1c5ac1b 100644 --- a/passbook/core/tasks.py +++ b/passbook/core/tasks.py @@ -1,16 +1,16 @@ """passbook core tasks""" from datetime import datetime -from logging import getLogger from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.html import strip_tags +from structlog import get_logger from passbook.core.models import Nonce from passbook.lib.config import CONFIG from passbook.root.celery import CELERY_APP -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @CELERY_APP.task() def send_email(to_address, subject, template, context): diff --git a/passbook/core/urls.py b/passbook/core/urls.py index b5da3d10e..3ed35de5d 100644 --- a/passbook/core/urls.py +++ b/passbook/core/urls.py @@ -1,12 +1,11 @@ """passbook URL Configuration""" -from logging import getLogger - from django.urls import path +from structlog import get_logger from passbook.core.auth import view from passbook.core.views import authentication, overview, user -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) urlpatterns = [ # Authentication views diff --git a/passbook/core/views/access.py b/passbook/core/views/access.py index 054181371..8bd17c9a4 100644 --- a/passbook/core/views/access.py +++ b/passbook/core/views/access.py @@ -1,13 +1,12 @@ """passbook access helper classes""" -from logging import getLogger - from django.contrib import messages from django.utils.translation import gettext as _ +from structlog import get_logger from passbook.core.models import Application from passbook.policy.engine import PolicyEngine -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class AccessMixin: """Mixin class for usage in Authorization views. diff --git a/passbook/core/views/authentication.py b/passbook/core/views/authentication.py index 119c85f61..732f6c2a5 100644 --- a/passbook/core/views/authentication.py +++ b/passbook/core/views/authentication.py @@ -1,5 +1,4 @@ """passbook core authentication views""" -from logging import getLogger from typing import Dict from django.contrib import messages @@ -11,6 +10,7 @@ from django.shortcuts import get_object_or_404, redirect, reverse from django.utils.translation import ugettext as _ from django.views import View from django.views.generic import FormView +from structlog import get_logger from passbook.core.auth.view import AuthenticationView, _redirect_with_qs from passbook.core.exceptions import PasswordPolicyInvalid @@ -20,7 +20,7 @@ from passbook.core.signals import invitation_used, user_signed_up from passbook.core.tasks import send_email from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class LoginView(UserPassesTestMixin, FormView): diff --git a/passbook/hibp_policy/models.py b/passbook/hibp_policy/models.py index 7936fbb2a..1c66ecba8 100644 --- a/passbook/hibp_policy/models.py +++ b/passbook/hibp_policy/models.py @@ -1,14 +1,14 @@ """passbook HIBP Models""" from hashlib import sha1 -from logging import getLogger from django.db import models from django.utils.translation import gettext as _ from requests import get +from structlog import get_logger from passbook.core.models import Policy, PolicyResult, User -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class HaveIBeenPwendPolicy(Policy): """Check if password is on HaveIBeenPwned's list by upload the first diff --git a/passbook/ldap/auth.py b/passbook/ldap/auth.py index 24a26d875..33068d19e 100644 --- a/passbook/ldap/auth.py +++ b/passbook/ldap/auth.py @@ -1,12 +1,11 @@ """passbook LDAP Authentication Backend""" -from logging import getLogger - from django.contrib.auth.backends import ModelBackend +from structlog import get_logger from passbook.ldap.ldap_connector import LDAPConnector from passbook.ldap.models import LDAPSource -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class LDAPBackend(ModelBackend): diff --git a/passbook/ldap/ldap_connector.py b/passbook/ldap/ldap_connector.py index 6b8b7a751..0bd3f780a 100644 --- a/passbook/ldap/ldap_connector.py +++ b/passbook/ldap/ldap_connector.py @@ -1,15 +1,15 @@ """Wrapper for ldap3 to easily manage user""" -from logging import getLogger from time import time import ldap3 import ldap3.core.exceptions +from structlog import get_logger from passbook.core.models import User from passbook.ldap.models import LDAPSource from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) USERNAME_FIELD = CONFIG.y('ldap.username_field', 'sAMAccountName') LOGIN_FIELD = CONFIG.y('ldap.login_field', 'userPrincipalName') diff --git a/passbook/lib/sentry.py b/passbook/lib/sentry.py index c5e387d8e..ef8ee78ff 100644 --- a/passbook/lib/sentry.py +++ b/passbook/lib/sentry.py @@ -1,7 +1,7 @@ """passbook sentry integration""" -from logging import getLogger +from structlog import get_logger -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def before_send(event, hint): diff --git a/passbook/lib/templatetags/is_active.py b/passbook/lib/templatetags/is_active.py index 200da9098..a94d7d354 100644 --- a/passbook/lib/templatetags/is_active.py +++ b/passbook/lib/templatetags/is_active.py @@ -1,12 +1,11 @@ """passbook lib navbar Templatetag""" -from logging import getLogger - from django import template from django.urls import reverse +from structlog import get_logger register = template.Library() -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @register.simple_tag(takes_context=True) diff --git a/passbook/lib/templatetags/reflection.py b/passbook/lib/templatetags/reflection.py index cb59d2558..26350595b 100644 --- a/passbook/lib/templatetags/reflection.py +++ b/passbook/lib/templatetags/reflection.py @@ -1,10 +1,9 @@ """passbook Core Reflection templatetags Templatetag""" -from logging import getLogger - from django import template +from structlog import get_logger register = template.Library() -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def get_key_unique(context): diff --git a/passbook/oauth_client/apps.py b/passbook/oauth_client/apps.py index 7379d7963..eb0997062 100644 --- a/passbook/oauth_client/apps.py +++ b/passbook/oauth_client/apps.py @@ -1,12 +1,12 @@ """passbook oauth_client config""" from importlib import import_module -from logging import getLogger from django.apps import AppConfig +from structlog import get_logger from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PassbookOAuthClientConfig(AppConfig): """passbook oauth_client config""" diff --git a/passbook/oauth_client/clients.py b/passbook/oauth_client/clients.py index 06b109664..2ac55776a 100644 --- a/passbook/oauth_client/clients.py +++ b/passbook/oauth_client/clients.py @@ -1,7 +1,6 @@ """OAuth Clients""" import json -from logging import getLogger from urllib.parse import parse_qs, urlencode from django.conf import settings @@ -10,8 +9,9 @@ from django.utils.encoding import force_text from requests import Session from requests.exceptions import RequestException from requests_oauthlib import OAuth1 +from structlog import get_logger -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class BaseOAuthClient: diff --git a/passbook/oauth_client/source_types/azure_ad.py b/passbook/oauth_client/source_types/azure_ad.py index 3dd2c41b6..064cefdae 100644 --- a/passbook/oauth_client/source_types/azure_ad.py +++ b/passbook/oauth_client/source_types/azure_ad.py @@ -1,16 +1,16 @@ """AzureAD OAuth2 Views""" import json import uuid -from logging import getLogger from requests.exceptions import RequestException +from structlog import get_logger from passbook.oauth_client.clients import OAuth2Client from passbook.oauth_client.source_types.manager import MANAGER, RequestKind from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class AzureADOAuth2Client(OAuth2Client): diff --git a/passbook/oauth_client/source_types/discord.py b/passbook/oauth_client/source_types/discord.py index 5ea8419c3..1cd3d90a8 100644 --- a/passbook/oauth_client/source_types/discord.py +++ b/passbook/oauth_client/source_types/discord.py @@ -1,15 +1,15 @@ """Discord OAuth Views""" import json -from logging import getLogger from requests.exceptions import RequestException +from structlog import get_logger from passbook.oauth_client.clients import OAuth2Client from passbook.oauth_client.source_types.manager import MANAGER, RequestKind from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @MANAGER.source(kind=RequestKind.redirect, name='Discord') diff --git a/passbook/oauth_client/source_types/manager.py b/passbook/oauth_client/source_types/manager.py index d34b060e7..69b8fbe7e 100644 --- a/passbook/oauth_client/source_types/manager.py +++ b/passbook/oauth_client/source_types/manager.py @@ -1,10 +1,11 @@ """Source type manager""" from enum import Enum -from logging import getLogger + +from structlog import get_logger from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class RequestKind(Enum): """Enum of OAuth Request types""" diff --git a/passbook/oauth_client/source_types/reddit.py b/passbook/oauth_client/source_types/reddit.py index e5bf9ef61..270a096b5 100644 --- a/passbook/oauth_client/source_types/reddit.py +++ b/passbook/oauth_client/source_types/reddit.py @@ -1,16 +1,16 @@ """Reddit OAuth Views""" import json -from logging import getLogger from requests.auth import HTTPBasicAuth from requests.exceptions import RequestException +from structlog import get_logger from passbook.oauth_client.clients import OAuth2Client from passbook.oauth_client.source_types.manager import MANAGER, RequestKind from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback, OAuthRedirect -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) @MANAGER.source(kind=RequestKind.redirect, name='reddit') diff --git a/passbook/oauth_client/source_types/supervisr.py b/passbook/oauth_client/source_types/supervisr.py index 28b316731..5566bc799 100644 --- a/passbook/oauth_client/source_types/supervisr.py +++ b/passbook/oauth_client/source_types/supervisr.py @@ -1,16 +1,16 @@ """Supervisr OAuth2 Views""" import json -from logging import getLogger from requests.exceptions import RequestException +from structlog import get_logger from passbook.oauth_client.clients import OAuth2Client from passbook.oauth_client.source_types.manager import MANAGER, RequestKind from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class SupervisrOAuth2Client(OAuth2Client): diff --git a/passbook/oauth_client/source_types/twitter.py b/passbook/oauth_client/source_types/twitter.py index f0e645911..8008b4b26 100644 --- a/passbook/oauth_client/source_types/twitter.py +++ b/passbook/oauth_client/source_types/twitter.py @@ -1,15 +1,14 @@ """Twitter OAuth Views""" -from logging import getLogger - from requests.exceptions import RequestException +from structlog import get_logger from passbook.oauth_client.clients import OAuthClient from passbook.oauth_client.source_types.manager import MANAGER, RequestKind from passbook.oauth_client.utils import user_get_or_create from passbook.oauth_client.views.core import OAuthCallback -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class TwitterOAuthClient(OAuthClient): diff --git a/passbook/oauth_client/views/core.py b/passbook/oauth_client/views/core.py index 93a9a6d10..7345b02c3 100644 --- a/passbook/oauth_client/views/core.py +++ b/passbook/oauth_client/views/core.py @@ -1,7 +1,5 @@ """Core OAauth Views""" -from logging import getLogger - from django.conf import settings from django.contrib import messages from django.contrib.auth import authenticate @@ -11,13 +9,14 @@ from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from django.utils.translation import ugettext as _ from django.views.generic import RedirectView, View +from structlog import get_logger from passbook.core.auth.view import AuthenticationView, _redirect_with_qs from passbook.lib.utils.reflection import app from passbook.oauth_client.clients import get_client from passbook.oauth_client.models import OAuthSource, UserOAuthSourceConnection -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) # pylint: disable=too-few-public-methods diff --git a/passbook/oauth_provider/views/oauth2.py b/passbook/oauth_provider/views/oauth2.py index eae14a028..4fadccaf3 100644 --- a/passbook/oauth_provider/views/oauth2.py +++ b/passbook/oauth_provider/views/oauth2.py @@ -1,5 +1,4 @@ """passbook OAuth2 Views""" -from logging import getLogger from urllib.parse import urlencode from django.contrib import messages @@ -7,6 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import get_object_or_404, redirect, reverse from django.utils.translation import ugettext as _ from oauth2_provider.views.base import AuthorizationView +from structlog import get_logger from passbook.audit.models import AuditEntry from passbook.core.models import Application @@ -14,7 +14,7 @@ from passbook.core.views.access import AccessMixin from passbook.core.views.utils import LoadingView, PermissionDeniedView from passbook.oauth_provider.models import OAuth2Provider -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PassbookAuthorizationLoadingView(LoginRequiredMixin, LoadingView): diff --git a/passbook/oidc_provider/apps.py b/passbook/oidc_provider/apps.py index 6f4259179..168b5f51a 100644 --- a/passbook/oidc_provider/apps.py +++ b/passbook/oidc_provider/apps.py @@ -1,11 +1,10 @@ """passbook auth oidc provider app config""" -from logging import getLogger - from django.apps import AppConfig from django.db.utils import InternalError, OperationalError, ProgrammingError from django.urls import include, path +from structlog import get_logger -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PassbookOIDCProviderConfig(AppConfig): """passbook auth oidc provider app config""" diff --git a/passbook/oidc_provider/lib.py b/passbook/oidc_provider/lib.py index 47d809492..06cde26c0 100644 --- a/passbook/oidc_provider/lib.py +++ b/passbook/oidc_provider/lib.py @@ -1,13 +1,12 @@ """OIDC Permission checking""" -from logging import getLogger - from django.contrib import messages from django.shortcuts import redirect +from structlog import get_logger from passbook.core.models import Application from passbook.policy.engine import PolicyEngine -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def check_permissions(request, user, client): """Check permissions, used for diff --git a/passbook/otp/factors.py b/passbook/otp/factors.py index 3b7bdfb54..a4a77daf5 100644 --- a/passbook/otp/factors.py +++ b/passbook/otp/factors.py @@ -1,16 +1,15 @@ """OTP Factor logic""" -from logging import getLogger - from django.contrib import messages from django.utils.translation import gettext as _ from django.views.generic import FormView from django_otp import match_token, user_has_device +from structlog import get_logger from passbook.core.auth.factor import AuthenticationFactor from passbook.otp.forms import OTPVerifyForm from passbook.otp.views import OTP_SETTING_UP_KEY, EnableView -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class OTPFactor(FormView, AuthenticationFactor): """OTP Factor View""" diff --git a/passbook/otp/views.py b/passbook/otp/views.py index 7918c03ba..ff4ee64f1 100644 --- a/passbook/otp/views.py +++ b/passbook/otp/views.py @@ -1,7 +1,6 @@ """passbook OTP Views""" from base64 import b32encode from binascii import unhexlify -from logging import getLogger from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -15,6 +14,7 @@ from django_otp.plugins.otp_static.models import StaticDevice, StaticToken from django_otp.plugins.otp_totp.models import TOTPDevice from qrcode import make from qrcode.image.svg import SvgPathImage +from structlog import get_logger from passbook.lib.boilerplate import NeverCacheMixin from passbook.lib.config import CONFIG @@ -23,7 +23,7 @@ from passbook.otp.utils import otpauth_url OTP_SESSION_KEY = 'passbook_otp_key' OTP_SETTING_UP_KEY = 'passbook_otp_setup' -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class UserSettingsView(LoginRequiredMixin, TemplateView): """View for user settings to control OTP""" diff --git a/passbook/password_expiry_policy/models.py b/passbook/password_expiry_policy/models.py index 93c59e174..1897837a4 100644 --- a/passbook/password_expiry_policy/models.py +++ b/passbook/password_expiry_policy/models.py @@ -1,14 +1,14 @@ """passbook password_expiry_policy Models""" from datetime import timedelta -from logging import getLogger from django.db import models from django.utils.timezone import now from django.utils.translation import gettext as _ +from structlog import get_logger from passbook.core.models import Policy, PolicyResult, User -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PasswordExpiryPolicy(Policy): diff --git a/passbook/policy/task.py b/passbook/policy/task.py index 789140bbf..da8312407 100644 --- a/passbook/policy/task.py +++ b/passbook/policy/task.py @@ -1,12 +1,13 @@ """passbook policy task""" -from logging import getLogger from multiprocessing import Process from multiprocessing.connection import Connection from typing import Any, Dict +from structlog import get_logger + from passbook.core.models import Policy, User -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def _cache_key(policy, user): diff --git a/passbook/root/celery.py b/passbook/root/celery.py index 622f3f3a3..a5d6e19e4 100644 --- a/passbook/root/celery.py +++ b/passbook/root/celery.py @@ -1,15 +1,15 @@ """passbook core celery""" - -import logging import os +from logging.config import dictConfig from celery import Celery, signals from django.conf import settings +from structlog import get_logger # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings") -LOGGER = logging.getLogger(__name__) +LOGGER = get_logger(__name__) CELERY_APP = Celery('passbook') @@ -19,7 +19,7 @@ CELERY_APP = Celery('passbook') @signals.setup_logging.connect def config_loggers(*args, **kwags): """Apply logging settings from settings.py to celery""" - logging.config.dictConfig(settings.LOGGING) + dictConfig(settings.LOGGING) # pylint: disable=unused-argument diff --git a/passbook/root/urls.py b/passbook/root/urls.py index 4b6cd383b..1a16e4585 100644 --- a/passbook/root/urls.py +++ b/passbook/root/urls.py @@ -1,15 +1,14 @@ """passbook URL Configuration""" -from logging import getLogger - from django.conf import settings from django.contrib import admin from django.urls import include, path from django.views.generic import RedirectView +from structlog import get_logger from passbook.core.views import error from passbook.lib.utils.reflection import get_apps -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) admin.autodiscover() admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login') diff --git a/passbook/saml_idp/apps.py b/passbook/saml_idp/apps.py index 6b59da7ed..53a181e83 100644 --- a/passbook/saml_idp/apps.py +++ b/passbook/saml_idp/apps.py @@ -1,12 +1,12 @@ """passbook mod saml_idp app config""" from importlib import import_module -from logging import getLogger from django.apps import AppConfig +from structlog import get_logger from passbook.lib.config import CONFIG -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class PassbookSAMLIDPConfig(AppConfig): """passbook saml_idp app config""" diff --git a/passbook/saml_idp/base.py b/passbook/saml_idp/base.py index d8aa34e6d..151ed9f0d 100644 --- a/passbook/saml_idp/base.py +++ b/passbook/saml_idp/base.py @@ -2,9 +2,9 @@ import time import uuid -from logging import getLogger from bs4 import BeautifulSoup +from structlog import get_logger from passbook.saml_idp import exceptions, utils, xml_render @@ -65,7 +65,7 @@ class Processor: def __init__(self, remote): self.name = remote.name self._remote = remote - self._logger = getLogger(__name__) + self._logger = get_logger(__name__) self._system_params['ISSUER'] = self._remote.issuer self._logger.debug('processor configured') diff --git a/passbook/saml_idp/models.py b/passbook/saml_idp/models.py index 44ca925f5..4cf58bd99 100644 --- a/passbook/saml_idp/models.py +++ b/passbook/saml_idp/models.py @@ -1,16 +1,15 @@ """passbook saml_idp Models""" -from logging import getLogger - from django.contrib.postgres.fields import ArrayField from django.db import models from django.shortcuts import reverse from django.utils.translation import gettext as _ +from structlog import get_logger from passbook.core.models import PropertyMapping, Provider from passbook.lib.utils.reflection import class_to_path, path_to_class from passbook.saml_idp.base import Processor -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) class SAMLProvider(Provider): diff --git a/passbook/saml_idp/views.py b/passbook/saml_idp/views.py index cdd08324c..29243201a 100644 --- a/passbook/saml_idp/views.py +++ b/passbook/saml_idp/views.py @@ -1,6 +1,4 @@ """passbook SAML IDP Views""" -from logging import getLogger - from django.contrib.auth import logout from django.contrib.auth.mixins import AccessMixin from django.core.exceptions import ValidationError @@ -13,6 +11,7 @@ from django.utils.translation import gettext as _ from django.views import View from django.views.decorators.csrf import csrf_exempt from signxml.util import strip_pem_header +from structlog import get_logger from passbook.audit.models import AuditEntry from passbook.core.models import Application @@ -22,7 +21,7 @@ from passbook.policy.engine import PolicyEngine from passbook.saml_idp import exceptions from passbook.saml_idp.models import SAMLProvider -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) URL_VALIDATOR = URLValidator(schemes=('http', 'https')) diff --git a/passbook/saml_idp/xml_render.py b/passbook/saml_idp/xml_render.py index a8cb517c3..108497514 100644 --- a/passbook/saml_idp/xml_render.py +++ b/passbook/saml_idp/xml_render.py @@ -1,11 +1,11 @@ """Functions for creating XML output.""" -from logging import getLogger +from structlog import get_logger from passbook.lib.utils.template import render_to_string from passbook.saml_idp.xml_signing import get_signature_xml, sign_with_signxml -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def _get_attribute_statement(params): diff --git a/passbook/saml_idp/xml_signing.py b/passbook/saml_idp/xml_signing.py index 334cf3ac9..4600bdd62 100644 --- a/passbook/saml_idp/xml_signing.py +++ b/passbook/saml_idp/xml_signing.py @@ -1,14 +1,13 @@ """Signing code goes here.""" -from logging import getLogger - from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from lxml import etree # nosec from signxml import XMLSigner, XMLVerifier +from structlog import get_logger from passbook.lib.utils.template import render_to_string -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def sign_with_signxml(private_key, data, cert, reference_uri=None): diff --git a/passbook/suspicious_policy/signals.py b/passbook/suspicious_policy/signals.py index 2a171789d..1a1df8dc3 100644 --- a/passbook/suspicious_policy/signals.py +++ b/passbook/suspicious_policy/signals.py @@ -1,14 +1,13 @@ """passbook suspicious request signals""" -from logging import getLogger - from django.contrib.auth.signals import user_logged_in, user_login_failed from django.dispatch import receiver from ipware import get_client_ip +from structlog import get_logger from passbook.core.models import User from passbook.suspicious_policy.models import IPScore, UserScore -LOGGER = getLogger(__name__) +LOGGER = get_logger(__name__) def get_remote_ip(request):