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

Support tower license within the database

With backwards support for the file-based license
This commit is contained in:
Matthew Jones 2015-12-16 11:21:52 -05:00
parent 35b19bf220
commit 9db80bd9fc
5 changed files with 22 additions and 8 deletions

View File

@ -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.

View File

@ -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'],

View File

@ -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

View File

@ -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)

View File

@ -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 = {