mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 03:30:02 -03:30
resurrect cchurch's license feature caching
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
|
from django.core.cache import cache
|
||||||
|
from django.core.signals import setting_changed
|
||||||
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
@@ -9,6 +12,7 @@ from rest_framework.exceptions import APIException
|
|||||||
|
|
||||||
# Tower
|
# Tower
|
||||||
from awx.main.utils.common import get_licenser
|
from awx.main.utils.common import get_licenser
|
||||||
|
from awx.main.utils import memoize
|
||||||
|
|
||||||
__all__ = ['LicenseForbids', 'get_license', 'get_licensed_features',
|
__all__ = ['LicenseForbids', 'get_license', 'get_licensed_features',
|
||||||
'feature_enabled', 'feature_exists']
|
'feature_enabled', 'feature_exists']
|
||||||
@@ -19,10 +23,18 @@ class LicenseForbids(APIException):
|
|||||||
default_detail = _('Your Tower license does not allow that.')
|
default_detail = _('Your Tower license does not allow that.')
|
||||||
|
|
||||||
|
|
||||||
|
@memoize(cache_key='_validated_license_data')
|
||||||
def _get_validated_license_data():
|
def _get_validated_license_data():
|
||||||
return get_licenser().validate()
|
return get_licenser().validate()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(setting_changed)
|
||||||
|
def _on_setting_changed(sender, **kwargs):
|
||||||
|
# Clear cached result above when license changes.
|
||||||
|
if kwargs.get('setting', None) == 'LICENSE':
|
||||||
|
cache.delete('_validated_license_data')
|
||||||
|
|
||||||
|
|
||||||
def get_license(show_key=False):
|
def get_license(show_key=False):
|
||||||
"""Return a dictionary representing the active license on this Tower instance."""
|
"""Return a dictionary representing the active license on this Tower instance."""
|
||||||
license_data = _get_validated_license_data()
|
license_data = _get_validated_license_data()
|
||||||
|
|||||||
Reference in New Issue
Block a user