1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #4446 from cchurch/settings-no-conflict

Make settings read-only if modified in Python config files.
This commit is contained in:
Chris Church 2016-12-15 15:01:42 -05:00 committed by GitHub
commit 46922e956f
3 changed files with 30 additions and 16 deletions

View File

@ -1,6 +1,7 @@
# Python # Python
import contextlib import contextlib
import logging import logging
import sys
import threading import threading
import time import time
@ -86,6 +87,7 @@ class SettingsWrapper(UserSettingsHolder):
self.__dict__['_awx_conf_settings'] = self self.__dict__['_awx_conf_settings'] = self
self.__dict__['_awx_conf_preload_expires'] = None self.__dict__['_awx_conf_preload_expires'] = None
self.__dict__['_awx_conf_preload_lock'] = threading.RLock() self.__dict__['_awx_conf_preload_lock'] = threading.RLock()
self.__dict__['_awx_conf_init_readonly'] = False
def _get_supported_settings(self): def _get_supported_settings(self):
return settings_registry.get_registered_settings() return settings_registry.get_registered_settings()
@ -110,6 +112,20 @@ class SettingsWrapper(UserSettingsHolder):
return return
# Otherwise update local preload timeout. # Otherwise update local preload timeout.
self.__dict__['_awx_conf_preload_expires'] = time.time() + SETTING_CACHE_TIMEOUT self.__dict__['_awx_conf_preload_expires'] = time.time() + SETTING_CACHE_TIMEOUT
# Check for any settings that have been defined in Python files and
# make those read-only to avoid overriding in the database.
if not self._awx_conf_init_readonly and 'migrate_to_database_settings' not in sys.argv:
defaults_snapshot = self._get_default('DEFAULTS_SNAPSHOT')
for key in self._get_writeable_settings():
init_default = defaults_snapshot.get(key, None)
try:
file_default = self._get_default(key)
except AttributeError:
file_default = None
if file_default != init_default and file_default is not None:
logger.warning('Setting %s has been marked read-only!', key)
settings_registry._registry[key]['read_only'] = True
self.__dict__['_awx_conf_init_readonly'] = True
# If local preload timer has expired, check to see if another process # If local preload timer has expired, check to see if another process
# has already preloaded the cache and skip preloading if so. # has already preloaded the cache and skip preloading if so.
if cache.get('_awx_conf_preload_expires', empty) is not empty: if cache.get('_awx_conf_preload_expires', empty) is not empty:

View File

@ -82,9 +82,8 @@ PASSWORD_HASHERS = (
# Configure a default UUID for development only. # Configure a default UUID for development only.
SYSTEM_UUID = '00000000-0000-0000-0000-000000000000' SYSTEM_UUID = '00000000-0000-0000-0000-000000000000'
# Store a snapshot of default settings at this point (only for migrating from # Store a snapshot of default settings at this point before loading any
# file to database settings). # customizable config files.
if 'migrate_to_database_settings' in sys.argv:
DEFAULTS_SNAPSHOT = {} DEFAULTS_SNAPSHOT = {}
this_module = sys.modules[__name__] this_module = sys.modules[__name__]
for setting in dir(this_module): for setting in dir(this_module):

View File

@ -57,9 +57,8 @@ LOGGING['handlers']['fact_receiver']['filename'] = '/var/log/tower/fact_receiver
LOGGING['handlers']['system_tracking_migrations']['filename'] = '/var/log/tower/tower_system_tracking_migrations.log' LOGGING['handlers']['system_tracking_migrations']['filename'] = '/var/log/tower/tower_system_tracking_migrations.log'
LOGGING['handlers']['rbac_migrations']['filename'] = '/var/log/tower/tower_rbac_migrations.log' LOGGING['handlers']['rbac_migrations']['filename'] = '/var/log/tower/tower_rbac_migrations.log'
# Store a snapshot of default settings at this point (only for migrating from # Store a snapshot of default settings at this point before loading any
# file to database settings). # customizable config files.
if 'migrate_to_database_settings' in sys.argv:
DEFAULTS_SNAPSHOT = {} DEFAULTS_SNAPSHOT = {}
this_module = sys.modules[__name__] this_module = sys.modules[__name__]
for setting in dir(this_module): for setting in dir(this_module):