diff --git a/awx/api/generics.py b/awx/api/generics.py index f9b1e04bbc8c..9e1698a61f3a 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -30,6 +30,9 @@ from rest_framework.renderers import StaticHTMLRenderer from rest_framework.negotiation import DefaultContentNegotiation +# Shared code for the AWX platform +from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name + # django-ansible-base from ansible_base.rest_filters.rest_framework.field_lookup_backend import FieldLookupBackend from ansible_base.lib.utils.models import get_all_field_names @@ -43,7 +46,6 @@ from awx.main.models.rbac import give_creator_permissions from awx.main.access import optimize_queryset from awx.main.utils import camelcase_to_underscore, get_search_fields, getattrd, get_object_or_400, decrypt_field, get_awx_version -from awx.main.utils.licensing import server_product_name from awx.main.utils.proxy import is_proxy_in_headers, delete_headers_starting_with_http from awx.main.views import ApiErrorView from awx.api.serializers import ResourceAccessListElementSerializer, CopySerializer @@ -254,7 +256,7 @@ def finalize_response(self, request, response, *args, **kwargs): time_started = getattr(self, 'time_started', None) if request.user.is_authenticated: response['X-API-Product-Version'] = get_awx_version() - response['X-API-Product-Name'] = server_product_name() + response['X-API-Product-Name'] = detect_server_product_name() response['X-API-Node'] = settings.CLUSTER_HOST_ID if time_started: diff --git a/awx/main/utils/licensing.py b/awx/main/utils/licensing.py index 7453f56c81d1..24109cd39ce0 100644 --- a/awx/main/utils/licensing.py +++ b/awx/main/utils/licensing.py @@ -15,7 +15,6 @@ import collections import copy import io -import os import json import logging import re @@ -35,6 +34,9 @@ from django.conf import settings from django.utils.translation import gettext_lazy as _ +# Shared code for the AWX platform +from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name + from awx.main.constants import SUBSCRIPTION_USAGE_MODEL_UNIQUE_HOSTS MAX_INSTANCES = 9999999 @@ -480,13 +482,9 @@ def get_licenser(*args, **kwargs): from awx.main.utils.licensing import Licenser, OpenLicense try: - if os.path.exists('/var/lib/awx/.tower_version'): - return Licenser(*args, **kwargs) - else: + if detect_server_product_name() == 'AWX': return OpenLicense() + else: + return Licenser(*args, **kwargs) except Exception as e: raise ValueError(_('Error importing License: %s') % e) - - -def server_product_name(): - return 'AWX' if isinstance(get_licenser(), OpenLicense) else 'Red Hat Ansible Automation Platform' diff --git a/awx/ui/urls.py b/awx/ui/urls.py index 540a69017b4a..108607b1ee46 100644 --- a/awx/ui/urls.py +++ b/awx/ui/urls.py @@ -2,7 +2,8 @@ from django.utils.translation import gettext_lazy as _ from django.views.generic.base import TemplateView -from awx.main.utils.licensing import server_product_name +# Shared code for the AWX platform +from awx_plugins.interfaces._temporary_private_licensing_api import detect_server_product_name class IndexView(TemplateView): @@ -14,7 +15,7 @@ class MigrationsNotran(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - product_name = server_product_name() + product_name = detect_server_product_name() context['title'] = _('%s Upgrading' % product_name) context['image_alt'] = _('Logo') context['aria_spinner'] = _('Loading')