diff --git a/awx/api/views.py b/awx/api/views.py index 1677bb37be..a87957b0e9 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -192,7 +192,7 @@ class ApiV1ConfigView(APIView): '''Return various sitewide configuration settings.''' license_reader = TaskSerializer() - license_data = license_reader.from_file(show_key=request.user.is_superuser) + license_data = license_reader.from_database(show_key=request.user.is_superuser) pendo_state = tower_settings.PENDO_TRACKING_STATE if tower_settings.PENDO_TRACKING_STATE in ('off', 'anonymous', 'detailed') else 'off' @@ -264,9 +264,7 @@ class ApiV1ConfigView(APIView): # If the license is valid, write it to disk. if license_data['valid_key']: - fh = open(TASK_FILE, "w") - fh.write(data_actual) - fh.close() + tower_settings.LICENSE = data_actual # Spawn a task to ensure that MongoDB is started (or stopped) # as appropriate, based on whether the license uses it. diff --git a/awx/main/conf.py b/awx/main/conf.py index 40646c2537..915f361639 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -9,17 +9,24 @@ class TowerConfiguration(object): # TODO: Caching so we don't have to hit the database every time for settings def __getattr__(self, key): + settings_manifest = django_settings.TOWER_SETTINGS_MANIFEST + if key not in settings_manifest: + raise AttributeError("Tower Setting with key '{0}' is not defined in the manifest".format(key)) ts = TowerSettings.objects.filter(key=key) if not ts.exists(): - return getattr(django_settings, key) + try: + val_actual = getattr(django_settings, key) + except AttributeError: + val_actual = settings_manifest[key]['default'] + return val_actual return ts[0].value_converted - def create(key, value): + def __setattr__(self, key, value): settings_manifest = django_settings.TOWER_SETTINGS_MANIFEST if key not in settings_manifest: raise AttributeError("Tower Setting with key '{0}' does not exist".format(key)) settings_entry = settings_manifest[key] - setting_actual = TowerSettings.objects.filter(key=key) + settings_actual = TowerSettings.objects.filter(key=key) if not settings_actual.exists(): settings_actual = TowerSettings(key=key, description=settings_entry['description'], diff --git a/awx/main/middleware.py b/awx/main/middleware.py index 39e8bc7565..4737ed74a8 100644 --- a/awx/main/middleware.py +++ b/awx/main/middleware.py @@ -15,7 +15,7 @@ from django.conf import settings from awx import __version__ as version from awx.main.models import ActivityStream, Instance -from awx.main.comf import tower_settings +from awx.main.conf import tower_settings from awx.api.authentication import TokenAuthentication diff --git a/awx/main/models/configuration.py b/awx/main/models/configuration.py index c7e8d07f68..c3591dd31c 100644 --- a/awx/main/models/configuration.py +++ b/awx/main/models/configuration.py @@ -54,6 +54,8 @@ class TowerSettings(CreatedModifiedModel): converted_type = [x.strip() for x in self.value.split(',')] elif self.value_type == 'bool': converted_type = self.value in [True, "true", "True", 1, "1", "yes"] + elif self.value_type == 'string': + converted_type = self.value else: t = __builtins__[self.value_type] converted_type = t(self.value) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 5bff8359c7..2e35c848f7 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -822,6 +822,13 @@ TOWER_SETTINGS_MANIFEST = { "type": "bool", "category": "system", }, + "LICENSE": { + "name": "Tower License", + "description": "Controls what features and functionality is enabled in Tower.", + "default": "{}", + "type": "string", + "category": "system", + }, } # Logging configuration. LOGGING = {