From 23d0cd04660abdb4ce9f4ebfb8b3f52070fa4c25 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Tue, 2 Nov 2021 15:55:20 +0100 Subject: [PATCH] update tabluate. fix audit.py and include in container --- core/admin/Dockerfile | 1 + core/admin/audit.py | 28 +++++++++++++++------------- core/admin/requirements-prod.txt | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) mode change 100644 => 100755 core/admin/audit.py diff --git a/core/admin/Dockerfile b/core/admin/Dockerfile index 95a46fa2..8adf2ca5 100644 --- a/core/admin/Dockerfile +++ b/core/admin/Dockerfile @@ -43,6 +43,7 @@ COPY --from=assets static ./mailu/ui/static COPY mailu ./mailu COPY migrations ./migrations COPY start.py /start.py +COPY audit.py /audit.py RUN pybabel compile -d mailu/translations diff --git a/core/admin/audit.py b/core/admin/audit.py old mode 100644 new mode 100755 index db105ff4..79365286 --- a/core/admin/audit.py +++ b/core/admin/audit.py @@ -1,14 +1,17 @@ -from mailu import app +#!/usr/bin/python3 import sys import tabulate +import mailu +app = mailu.create_app() + # Known endpoints without permissions known_missing_permissions = [ - "index", - "static", "bootstrap.static", - "admin.static", "admin.login" + 'index', + 'static', 'bootstrap.static', + 'admin.static', 'admin.login' ] @@ -16,7 +19,7 @@ known_missing_permissions = [ missing_permissions = [] permissions = {} for endpoint, function in app.view_functions.items(): - audit = function.__dict__.get("_audit_permissions") + audit = function.__dict__.get('_audit_permissions') if audit: handler, args = audit if args: @@ -28,16 +31,15 @@ for endpoint, function in app.view_functions.items(): elif endpoint not in known_missing_permissions: missing_permissions.append(endpoint) - -# Fail if any endpoint is missing a permission check -if missing_permissions: - print("The following endpoints are missing permission checks:") - print(missing_permissions.join(",")) - sys.exit(1) - - # Display the permissions table print(tabulate.tabulate([ [route, *permissions[route.endpoint]] for route in app.url_map.iter_rules() if route.endpoint in permissions ])) + +# Warn if any endpoint is missing a permission check +if missing_permissions: + print() + print('The following endpoints are missing permission checks:') + print(','.join(missing_permissions)) + diff --git a/core/admin/requirements-prod.txt b/core/admin/requirements-prod.txt index 673c4445..79075f96 100644 --- a/core/admin/requirements-prod.txt +++ b/core/admin/requirements-prod.txt @@ -65,7 +65,7 @@ six==1.15.0 socrate==0.1.1 SQLAlchemy==1.3.3 srslib==0.1.4 -tabulate==0.8.3 +tabulate==0.8.9 tenacity==5.0.4 toml==0.10.2 urllib3==1.26.5