Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Django 4.2 #480

Merged
merged 8 commits into from
Jul 25, 2023
2 changes: 1 addition & 1 deletion omero/plugins/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def wrapper(self, *args, **kwargs):
import django # NOQA
except Exception:
self.ctx.die(681, "ERROR: Django not installed!")
if django.VERSION < (3, 2) or django.VERSION >= (3, 3):
if django.VERSION < (3, 2) or django.VERSION >= (4, 3):
self.ctx.err(
"ERROR: Django version %s is not "
"supported!" % django.get_version()
Expand Down
10 changes: 8 additions & 2 deletions omeroweb/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@
# Monkeypatch Django development web server to always run in single thread
# even if --nothreading is not specified on command line
def force_nothreading(
addr, port, wsgi_handler, ipv6=False, threading=False, server_cls=WSGIServer
addr,
port,
wsgi_handler,
ipv6=False,
threading=False,
on_bind=None,
server_cls=WSGIServer,
):
django_core_servers_basehttp_run(
addr, port, wsgi_handler, ipv6, False, server_cls
addr, port, wsgi_handler, ipv6, False, on_bind, server_cls
)

import django.core.servers.basehttp
Expand Down
55 changes: 50 additions & 5 deletions omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,10 +1408,55 @@ def process_custom_settings(
LOGGING["loggers"][""]["level"] = "INFO"


def report_settings(module):
from django.views.debug import SafeExceptionReporterFilter
class CallableSettingWrapper:
"""
Object to wrap callable appearing in settings.

Adapted from:
* `django.views.debug.CallableSettingWrapper()`
"""

def __init__(self, callable_setting):
self._wrapped = callable_setting

def __repr__(self):
return repr(self._wrapped)


def cleanse_setting(key, value):
"""
Cleanse an individual setting key/value of sensitive content. If the
value is a dictionary, recursively cleanse the keys in that dictionary.

setting_filter = SafeExceptionReporterFilter()
Adapted from:
* `django.views.debug.SafeExceptionReporterFilter.cleanse_setting()`
"""
cleansed_substitute = "********************"
hidden_settings = re.compile("API|TOKEN|KEY|SECRET|PASS|SIGNATUREE", flags=re.I)

try:
is_sensitive = hidden_settings.search(key)
except TypeError:
is_sensitive = False

if is_sensitive:
cleansed = cleansed_substitute
elif isinstance(value, dict):
cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
elif isinstance(value, list):
cleansed = [cleanse_setting("", v) for v in value]
elif isinstance(value, tuple):
cleansed = tuple([cleanse_setting("", v) for v in value])
else:
cleansed = value

if callable(cleansed):
cleansed = CallableSettingWrapper(cleansed)

return cleansed


def report_settings(module):
custom_settings_mappings = getattr(module, "CUSTOM_SETTINGS_MAPPINGS", {})
for key in sorted(custom_settings_mappings):
values = custom_settings_mappings[key]
Expand All @@ -1422,7 +1467,7 @@ def report_settings(module):
logger.debug(
"%s = %r (source:%s)",
global_name,
setting_filter.cleanse_setting(global_name, global_value),
cleanse_setting(global_name, global_value),
source,
)

Expand All @@ -1435,7 +1480,7 @@ def report_settings(module):
logger.debug(
"%s = %r (deprecated:%s, %s)",
global_name,
setting_filter.cleanse_setting(global_name, global_value),
cleanse_setting(global_name, global_value),
key,
description,
)
Expand Down
55 changes: 0 additions & 55 deletions omeroweb/webgateway/middleware.py

This file was deleted.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def read(fname):
"omero-py>=5.7.0",
# minimum requirements for `omero web start`
"concurrent-log-handler>=0.9.20",
"Django>=3.2.19,<4.0",
"django-pipeline==2.0.7",
"Django>=3.2.19,<4.3",
"django-pipeline==2.1.0",
"django-cors-headers==3.7.0",
"whitenoise>=5.3.0",
"gunicorn>=19.3",
Expand All @@ -67,6 +67,6 @@ def read(fname):
include_package_data=True,
tests_require=["pytest"],
extras_require={
"redis": ["django-redis==5.0.0"],
"redis": ["django-redis==5.3.0"],
},
)