From 27e93e499fe7697db76d13e3a1fd4ee6eaa8150c Mon Sep 17 00:00:00 2001 From: sadnub Date: Wed, 6 Apr 2022 15:53:09 -0400 Subject: [PATCH] add django-silk to the docker dev setup --- .devcontainer/entrypoint.sh | 8 ++++++++ .devcontainer/requirements.txt | 3 +++ api/tacticalrmm/tacticalrmm/settings.py | 27 +++++++++++++++++++++++++ api/tacticalrmm/tacticalrmm/urls.py | 5 ++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh index f0f22014..3c59e208 100644 --- a/.devcontainer/entrypoint.sh +++ b/.devcontainer/entrypoint.sh @@ -60,6 +60,8 @@ DEBUG = True DOCKER_BUILD = True +SWAGGER_ENABLED = True + CERT_FILE = '${CERT_PUB_PATH}' KEY_FILE = '${CERT_PRIV_PATH}' @@ -88,6 +90,12 @@ MESH_TOKEN_KEY = '${MESH_TOKEN}' REDIS_HOST = '${REDIS_HOST}' MESH_WS_URL = '${MESH_WS_URL}' ADMIN_ENABLED = True + +DEV_MIDDLEWARE = [ + "silk.middleware.SilkyMiddleware", +] + +DEV_APPS = ["silk"] EOF )" diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt index 87430b24..5afb2599 100644 --- a/.devcontainer/requirements.txt +++ b/.devcontainer/requirements.txt @@ -34,3 +34,6 @@ Pygments==2.11.2 isort==5.10.1 mypy==0.931 types-pytz==2021.3.4 +model-bakery==1.4.0 +coverage==6.3.2 +django-silk==4.3.0 diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index c4b2649f..df264920 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -75,6 +75,9 @@ if "GHACTIONS" in os.environ: REDIS_HOST = "localhost" ADMIN_ENABLED = False +DEV_MIDDLEWARE = [] +DEV_APPS = [] + try: from .local_settings import * except ImportError: @@ -151,6 +154,7 @@ INSTALLED_APPS = [ "scripts", "alerts", "drf_spectacular", + *DEV_APPS, ] @@ -178,6 +182,29 @@ if ADMIN_ENABLED: # type: ignore ) +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "corsheaders.middleware.CorsMiddleware", ## + *DEV_MIDDLEWARE, + "tacticalrmm.middleware.LogIPMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "tacticalrmm.middleware.AuditMiddleware", + "tacticalrmm.middleware.LinuxMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +if ADMIN_ENABLED: # type: ignore + MIDDLEWARE += ("django.contrib.messages.middleware.MessageMiddleware",) + +try: + if DEMO: # type: ignore + MIDDLEWARE += ("tacticalrmm.middleware.DemoMiddleware",) +except: + pass + ROOT_URLCONF = "tacticalrmm.urls" diff --git a/api/tacticalrmm/tacticalrmm/urls.py b/api/tacticalrmm/tacticalrmm/urls.py index 6e4abeec..456f94fb 100644 --- a/api/tacticalrmm/tacticalrmm/urls.py +++ b/api/tacticalrmm/tacticalrmm/urls.py @@ -58,6 +58,9 @@ if getattr(settings, "SWAGGER_ENABLED", False): ), ) +if "silk" in getattr(settings, "DEV_APPS", []): + urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))] + ws_urlpatterns = [ - path("ws/dashinfo/", DashInfo.as_asgi()), + path("ws/dashinfo/", DashInfo.as_asgi()), # type: ignore ]