Skip to content

Commit

Permalink
Use awx_plugins.interfaces for runtime detection
Browse files Browse the repository at this point in the history
The original function name was `server_product_name()` but it didn't
really represent what it did. So it was renamed into
`detect_server_product_name()` in an attempt of disambiguation.
  • Loading branch information
webknjaz committed Oct 2, 2024
1 parent 67bb227 commit 31d13b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 4 additions & 2 deletions awx/api/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions awx/main/utils/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import collections
import copy
import io
import os
import json
import logging
import re
Expand All @@ -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
Expand Down Expand Up @@ -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'
5 changes: 3 additions & 2 deletions awx/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')
Expand Down

0 comments on commit 31d13b9

Please sign in to comment.