mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
adds maintenance exempt paths #11233
This commit is contained in:
parent
39fd64b2ef
commit
55276a8d87
@ -181,19 +181,23 @@ class MaintenanceModeMiddleware:
|
|||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
if get_config().MAINTENANCE_MODE:
|
if get_config().MAINTENANCE_MODE:
|
||||||
self._prevent_db_write_operations()
|
self._prevent_db_write_operations(
|
||||||
|
allow_write=request.path_info.startswith(settings.MAINTENANCE_EXEMPT_PATHS)
|
||||||
|
)
|
||||||
|
|
||||||
return self.get_response(request)
|
return self.get_response(request)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prevent_db_write_operations():
|
def _prevent_db_write_operations(allow_write=False):
|
||||||
"""
|
"""
|
||||||
Prevent any write-related database operations.
|
Prevent any write-related database operations.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
allow_write (bool): Whether to allow write operations.
|
||||||
"""
|
"""
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(
|
mode = 'READ WRITE' if allow_write else 'READ ONLY'
|
||||||
'SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;'
|
cursor.execute(f'SET SESSION CHARACTERISTICS AS TRANSACTION {mode};')
|
||||||
)
|
|
||||||
|
|
||||||
def process_exception(self, request, exception):
|
def process_exception(self, request, exception):
|
||||||
"""
|
"""
|
||||||
|
@ -478,6 +478,12 @@ AUTH_EXEMPT_PATHS = (
|
|||||||
f'/{BASE_PATH}metrics',
|
f'/{BASE_PATH}metrics',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# All URLs starting with a string listed here are exempt from maintenance mode enforcement
|
||||||
|
MAINTENANCE_EXEMPT_PATHS = (
|
||||||
|
f'/{BASE_PATH}admin/extras/configrevision/',
|
||||||
|
f'/{BASE_PATH}login/',
|
||||||
|
)
|
||||||
|
|
||||||
SERIALIZATION_MODULES = {
|
SERIALIZATION_MODULES = {
|
||||||
'json': 'utilities.serializers.json',
|
'json': 'utilities.serializers.json',
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user