From a798412e17a36c47faa75b911a3e71bf52b0532b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 25 Jun 2019 18:00:54 +0200 Subject: [PATCH] separate passbook.core into passbook.root and passbook.core Move Main Django Project into passbook.root while passbook.core holds core functionality. passbook.root contains main settings, ASGI & WSGI, celery and URLs. --- manage.py | 2 +- passbook/admin/views/overview.py | 2 +- passbook/core/apps.py | 1 + passbook/core/management/commands/web.py | 2 +- passbook/core/management/commands/worker.py | 2 +- passbook/core/policies.py | 2 +- passbook/core/tasks.py | 2 +- passbook/core/urls.py | 41 ++------------------- passbook/lib/sentry.py | 20 ++++++++-- passbook/root/__init__.py | 0 passbook/{core => root}/asgi.py | 2 +- passbook/{core => root}/celery.py | 2 +- passbook/{core => root}/requirements.txt | 0 passbook/{core => root}/settings.py | 0 passbook/root/urls.py | 41 +++++++++++++++++++++ passbook/{core => root}/wsgi.py | 0 16 files changed, 69 insertions(+), 50 deletions(-) create mode 100644 passbook/root/__init__.py rename passbook/{core => root}/asgi.py (80%) rename passbook/{core => root}/celery.py (96%) rename passbook/{core => root}/requirements.txt (100%) rename passbook/{core => root}/settings.py (100%) create mode 100644 passbook/root/urls.py rename passbook/{core => root}/wsgi.py (100%) diff --git a/manage.py b/manage.py index aeadd85a4..46a562abb 100755 --- a/manage.py +++ b/manage.py @@ -4,7 +4,7 @@ import os import sys if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.core.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.root.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/passbook/admin/views/overview.py b/passbook/admin/views/overview.py index 9f3b4de94..c7ffd41e4 100644 --- a/passbook/admin/views/overview.py +++ b/passbook/admin/views/overview.py @@ -5,9 +5,9 @@ from django.views.generic import TemplateView from passbook.admin.mixins import AdminRequiredMixin from passbook.core import __version__ -from passbook.core.celery import CELERY_APP from passbook.core.models import (Application, Factor, Invitation, Policy, Provider, Source, User) +from passbook.root.celery import CELERY_APP class AdministrationOverviewView(AdminRequiredMixin, TemplateView): diff --git a/passbook/core/apps.py b/passbook/core/apps.py index ae651b1b8..3329ec500 100644 --- a/passbook/core/apps.py +++ b/passbook/core/apps.py @@ -14,6 +14,7 @@ class PassbookCoreConfig(AppConfig): name = 'passbook.core' label = 'passbook_core' verbose_name = 'passbook Core' + mountpoint = '' def ready(self): import_module('passbook.core.policies') diff --git a/passbook/core/management/commands/web.py b/passbook/core/management/commands/web.py index 655844b58..de424093e 100644 --- a/passbook/core/management/commands/web.py +++ b/passbook/core/management/commands/web.py @@ -26,5 +26,5 @@ class Command(BaseCommand): '-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec '--access-log', '/dev/null', '--application-close-timeout', '500', - 'passbook.core.asgi:application' + 'passbook.root.asgi:application' ]) diff --git a/passbook/core/management/commands/worker.py b/passbook/core/management/commands/worker.py index 1a20f22d5..c4a56045f 100644 --- a/passbook/core/management/commands/worker.py +++ b/passbook/core/management/commands/worker.py @@ -5,7 +5,7 @@ from logging import getLogger from django.core.management.base import BaseCommand from django.utils import autoreload -from passbook.core.celery import CELERY_APP +from passbook.root.celery import CELERY_APP LOGGER = getLogger(__name__) diff --git a/passbook/core/policies.py b/passbook/core/policies.py index 2af0385a5..e50d51dbd 100644 --- a/passbook/core/policies.py +++ b/passbook/core/policies.py @@ -7,8 +7,8 @@ from celery.exceptions import TimeoutError as CeleryTimeoutError from django.core.cache import cache from ipware import get_client_ip -from passbook.core.celery import CELERY_APP from passbook.core.models import Policy, User +from passbook.root.celery import CELERY_APP LOGGER = getLogger(__name__) diff --git a/passbook/core/tasks.py b/passbook/core/tasks.py index e7339c46b..0abb9ecfa 100644 --- a/passbook/core/tasks.py +++ b/passbook/core/tasks.py @@ -6,9 +6,9 @@ from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.html import strip_tags -from passbook.core.celery import CELERY_APP from passbook.core.models import Nonce from passbook.lib.config import CONFIG +from passbook.root.celery import CELERY_APP LOGGER = getLogger(__name__) diff --git a/passbook/core/urls.py b/passbook/core/urls.py index 7fecdf614..b5da3d10e 100644 --- a/passbook/core/urls.py +++ b/passbook/core/urls.py @@ -1,25 +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 django.urls import path from passbook.core.auth import view -from passbook.core.views import authentication, error, overview, user -from passbook.lib.utils.reflection import get_apps +from passbook.core.views import authentication, overview, user LOGGER = getLogger(__name__) -admin.autodiscover() -admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login') -handler400 = error.BadRequestView.as_view() -handler403 = error.ForbiddenView.as_view() -handler404 = error.NotFoundView.as_view() -handler500 = error.ServerErrorView.as_view() - -core_urls = [ +urlpatterns = [ # Authentication views path('auth/login/', authentication.LoginView.as_view(), name='auth-login'), path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'), @@ -39,27 +28,3 @@ core_urls = [ # Overview path('', overview.OverviewView.as_view(), name='overview'), ] - -urlpatterns = [ - # Core (include our own URLs so namespaces are used everywhere) - path('', include((core_urls, 'passbook_core'), namespace='passbook_core')), -] - -for _passbook_app in get_apps(): - if hasattr(_passbook_app, 'mountpoint'): - _path = path(_passbook_app.mountpoint, include((_passbook_app.name+'.urls', - _passbook_app.label), - namespace=_passbook_app.label)) - urlpatterns.append(_path) - LOGGER.debug("Loaded %s's URLs", _passbook_app.name) - -urlpatterns += [ - # Administration - path('administration/django/', admin.site.urls), -] - -if settings.DEBUG: - import debug_toolbar - urlpatterns = [ - path('__debug__/', include(debug_toolbar.urls)), - ] + urlpatterns diff --git a/passbook/lib/sentry.py b/passbook/lib/sentry.py index 9aefc68de..c5e387d8e 100644 --- a/passbook/lib/sentry.py +++ b/passbook/lib/sentry.py @@ -1,17 +1,29 @@ """passbook sentry integration""" +from logging import getLogger + +LOGGER = getLogger(__name__) def before_send(event, hint): """Check if error is database error, and ignore if so""" - from django.db import OperationalError from django_redis.exceptions import ConnectionInterrupted - - ignored_classes = [ + from django.db import OperationalError, InternalError + from rest_framework.exceptions import APIException + from billiard.exceptions import WorkerLostError + from django.core.exceptions import DisallowedHost + ignored_classes = ( OperationalError, ConnectionInterrupted, - ] + APIException, + InternalError, + ConnectionResetError, + WorkerLostError, + DisallowedHost, + ConnectionResetError, + ) if 'exc_info' in hint: _exc_type, exc_value, _ = hint['exc_info'] if isinstance(exc_value, ignored_classes): + LOGGER.info("Supressing error %r", exc_value) return None return event diff --git a/passbook/root/__init__.py b/passbook/root/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/core/asgi.py b/passbook/root/asgi.py similarity index 80% rename from passbook/core/asgi.py rename to passbook/root/asgi.py index 249debe64..38bf72a05 100644 --- a/passbook/core/asgi.py +++ b/passbook/root/asgi.py @@ -8,6 +8,6 @@ import os import django from channels.routing import get_default_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.core.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings") django.setup() application = get_default_application() diff --git a/passbook/core/celery.py b/passbook/root/celery.py similarity index 96% rename from passbook/core/celery.py rename to passbook/root/celery.py index e1ee4556e..622f3f3a3 100644 --- a/passbook/core/celery.py +++ b/passbook/root/celery.py @@ -7,7 +7,7 @@ from celery import Celery, signals from django.conf import settings # set the default Django settings module for the 'celery' program. -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.core.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings") LOGGER = logging.getLogger(__name__) diff --git a/passbook/core/requirements.txt b/passbook/root/requirements.txt similarity index 100% rename from passbook/core/requirements.txt rename to passbook/root/requirements.txt diff --git a/passbook/core/settings.py b/passbook/root/settings.py similarity index 100% rename from passbook/core/settings.py rename to passbook/root/settings.py diff --git a/passbook/root/urls.py b/passbook/root/urls.py new file mode 100644 index 000000000..4b6cd383b --- /dev/null +++ b/passbook/root/urls.py @@ -0,0 +1,41 @@ +"""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 passbook.core.views import error +from passbook.lib.utils.reflection import get_apps + +LOGGER = getLogger(__name__) +admin.autodiscover() +admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login') + +handler400 = error.BadRequestView.as_view() +handler403 = error.ForbiddenView.as_view() +handler404 = error.NotFoundView.as_view() +handler500 = error.ServerErrorView.as_view() + +urlpatterns = [ +] + +for _passbook_app in get_apps(): + if hasattr(_passbook_app, 'mountpoint'): + _path = path(_passbook_app.mountpoint, include((_passbook_app.name+'.urls', + _passbook_app.label), + namespace=_passbook_app.label)) + urlpatterns.append(_path) + LOGGER.debug("Loaded %s's URLs", _passbook_app.name) + +urlpatterns += [ + # Administration + path('administration/django/', admin.site.urls), +] + +if settings.DEBUG: + import debug_toolbar + urlpatterns = [ + path('__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns diff --git a/passbook/core/wsgi.py b/passbook/root/wsgi.py similarity index 100% rename from passbook/core/wsgi.py rename to passbook/root/wsgi.py