From 16a396a60dec301713abc05f8c694992e7043a3d Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Thu, 1 Aug 2024 13:50:45 -0400 Subject: [PATCH] [change] Removed support for deprecated settings --- openwisp_controller/config/settings.py | 67 ++++++++++---------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/openwisp_controller/config/settings.py b/openwisp_controller/config/settings.py index 01f79b5af..113347805 100644 --- a/openwisp_controller/config/settings.py +++ b/openwisp_controller/config/settings.py @@ -6,26 +6,11 @@ logger = logging.getLogger(__name__) -def get_settings_value(option, default): - if option == 'CONFIG_BACKEND_FIELD_SHOWN' and hasattr( - settings, 'OPENWISP_CONTROLLER_BACKEND_DEVICE_LIST' - ): - logger.warn( - 'OPENWISP_CONTROLLER_BACKEND_DEVICE_LIST is deprecated and will be ' - 'removed in the future, please use ' - 'OPENWISP_CONTROLLER_CONFIG_BACKEND_FIELD_SHOWN instead.' - ) - return getattr(settings, 'OPENWISP_CONTROLLER_BACKEND_DEVICE_LIST', default) - if hasattr(settings, f'NETJSONCONFIG_{option}'): - logger.warn( - f'NETJSONCONFIG_{option} setting is deprecated. It will be removed ' - f'in the future, please use OPENWISP_CONTROLLER_{option} instead.' - ) - return getattr(settings, f'NETJSONCONFIG_{option}') +def get_setting(option, default): return getattr(settings, f'OPENWISP_CONTROLLER_{option}', default) -BACKENDS = get_settings_value( +BACKENDS = get_setting( 'BACKENDS', ( ('netjsonconfig.OpenWrt', 'OpenWRT'), @@ -33,7 +18,7 @@ def get_settings_value(option, default): ), ) -VPN_BACKENDS = get_settings_value( +VPN_BACKENDS = get_setting( 'VPN_BACKENDS', ( ('openwisp_controller.vpn_backends.OpenVpn', 'OpenVPN'), @@ -42,21 +27,21 @@ def get_settings_value(option, default): ('openwisp_controller.vpn_backends.ZeroTier', 'ZeroTier'), ), ) -DEFAULT_BACKEND = get_settings_value('DEFAULT_BACKEND', BACKENDS[0][0]) -DEFAULT_VPN_BACKEND = get_settings_value('DEFAULT_VPN_BACKEND', VPN_BACKENDS[0][0]) -REGISTRATION_ENABLED = get_settings_value('REGISTRATION_ENABLED', True) -CONSISTENT_REGISTRATION = get_settings_value('CONSISTENT_REGISTRATION', True) -REGISTRATION_SELF_CREATION = get_settings_value('REGISTRATION_SELF_CREATION', True) +DEFAULT_BACKEND = get_setting('DEFAULT_BACKEND', BACKENDS[0][0]) +DEFAULT_VPN_BACKEND = get_setting('DEFAULT_VPN_BACKEND', VPN_BACKENDS[0][0]) +REGISTRATION_ENABLED = get_setting('REGISTRATION_ENABLED', True) +CONSISTENT_REGISTRATION = get_setting('CONSISTENT_REGISTRATION', True) +REGISTRATION_SELF_CREATION = get_setting('REGISTRATION_SELF_CREATION', True) -CONTEXT = get_settings_value('CONTEXT', {}) +CONTEXT = get_setting('CONTEXT', {}) assert isinstance(CONTEXT, dict), 'OPENWISP_CONTROLLER_CONTEXT must be a dictionary' -DEFAULT_AUTO_CERT = get_settings_value('DEFAULT_AUTO_CERT', True) -CERT_PATH = get_settings_value('CERT_PATH', '/etc/x509') -COMMON_NAME_FORMAT = get_settings_value('COMMON_NAME_FORMAT', '{mac_address}-{name}') -MANAGEMENT_IP_DEVICE_LIST = get_settings_value('MANAGEMENT_IP_DEVICE_LIST', True) -CONFIG_BACKEND_FIELD_SHOWN = get_settings_value('CONFIG_BACKEND_FIELD_SHOWN', True) +DEFAULT_AUTO_CERT = get_setting('DEFAULT_AUTO_CERT', True) +CERT_PATH = get_setting('CERT_PATH', '/etc/x509') +COMMON_NAME_FORMAT = get_setting('COMMON_NAME_FORMAT', '{mac_address}-{name}') +MANAGEMENT_IP_DEVICE_LIST = get_setting('MANAGEMENT_IP_DEVICE_LIST', True) +CONFIG_BACKEND_FIELD_SHOWN = get_setting('CONFIG_BACKEND_FIELD_SHOWN', True) -HARDWARE_ID_ENABLED = get_settings_value('HARDWARE_ID_ENABLED', False) +HARDWARE_ID_ENABLED = get_setting('HARDWARE_ID_ENABLED', False) HARDWARE_ID_OPTIONS = { 'blank': not HARDWARE_ID_ENABLED, 'null': True, @@ -65,22 +50,20 @@ def get_settings_value(option, default): 'verbose_name': _('Serial number'), 'help_text': _('Serial number of this device'), } -HARDWARE_ID_OPTIONS.update(get_settings_value('HARDWARE_ID_OPTIONS', {})) -HARDWARE_ID_AS_NAME = get_settings_value('HARDWARE_ID_AS_NAME', True) -DEVICE_VERBOSE_NAME = get_settings_value( - 'DEVICE_VERBOSE_NAME', (_('Device'), _('Devices')) -) -DEVICE_NAME_UNIQUE = get_settings_value('DEVICE_NAME_UNIQUE', True) -DEVICE_GROUP_SCHEMA = get_settings_value( +HARDWARE_ID_OPTIONS.update(get_setting('HARDWARE_ID_OPTIONS', {})) +HARDWARE_ID_AS_NAME = get_setting('HARDWARE_ID_AS_NAME', True) +DEVICE_VERBOSE_NAME = get_setting('DEVICE_VERBOSE_NAME', (_('Device'), _('Devices'))) +DEVICE_NAME_UNIQUE = get_setting('DEVICE_NAME_UNIQUE', True) +DEVICE_GROUP_SCHEMA = get_setting( 'DEVICE_GROUP_SCHEMA', {'type': 'object', 'properties': {}} ) -SHARED_MANAGEMENT_IP_ADDRESS_SPACE = get_settings_value( +SHARED_MANAGEMENT_IP_ADDRESS_SPACE = get_setting( 'SHARED_MANAGEMENT_IP_ADDRESS_SPACE', True ) -DSA_OS_MAPPING = get_settings_value('DSA_OS_MAPPING', {}) -DSA_DEFAULT_FALLBACK = get_settings_value('DSA_DEFAULT_FALLBACK', True) -GROUP_PIE_CHART = get_settings_value('GROUP_PIE_CHART', False) -API_TASK_RETRY_OPTIONS = get_settings_value( +DSA_OS_MAPPING = get_setting('DSA_OS_MAPPING', {}) +DSA_DEFAULT_FALLBACK = get_setting('DSA_DEFAULT_FALLBACK', True) +GROUP_PIE_CHART = get_setting('GROUP_PIE_CHART', False) +API_TASK_RETRY_OPTIONS = get_setting( 'API_TASK_RETRY_OPTIONS', dict(max_retries=5, retry_backoff=True, retry_backoff_max=600, retry_jitter=True), )