simplify how awx "open" licensing works

This commit is contained in:
Ryan Petrello 2020-10-23 10:51:48 -04:00
parent e591f1f002
commit c139a998b8
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
3 changed files with 20 additions and 19 deletions

View File

@ -187,6 +187,7 @@ class APIView(views.APIView):
'''
Log warning for 400 requests. Add header with elapsed time.
'''
from awx.main.utils.common import get_licenser
#
# If the URL was rewritten, and we get a 404, we should entirely
@ -223,7 +224,7 @@ class APIView(views.APIView):
response = super(APIView, self).finalize_response(request, response, *args, **kwargs)
time_started = getattr(self, 'time_started', None)
response['X-API-Product-Version'] = get_awx_version()
response['X-API-Product-Name'] = 'AWX' if settings.LICENSE.get('license_type', 'UNLICENSED') in 'open' else 'Red Hat Ansible Tower'
response['X-API-Product-Name'] = 'AWX' if get_licenser().validate().get('license_type') == 'open' else 'Red Hat Ansible Tower'
response['X-API-Node'] = settings.CLUSTER_HOST_ID
if time_started:

View File

@ -202,10 +202,13 @@ def get_awx_http_client_headers():
def get_licenser(*args, **kwargs):
from awx.main.utils.licensing import Licenser, OpenLicense
try:
# Get License Config from db?
from awx.main.utils.licensing import Licenser
return Licenser(*args, **kwargs)
if os.path.exists('/var/lib/awx/.tower_version'):
return Licenser(*args, **kwargs)
else:
return OpenLicense()
except Exception as e:
raise ValueError(_('Error importing Tower License: %s') % e)

View File

@ -17,7 +17,6 @@ import copy
import io
import json
import logging
import os
import re
import requests
import time
@ -68,6 +67,16 @@ def validate_entitlement_manifest(data):
return json.loads(z.open(f).read())
class OpenLicense(object):
def validate(self):
return dict(
license_type='open',
valid_key=True,
subscription_name='OPEN',
product_name="AWX",
)
class Licenser(object):
# warn when there is a month (30 days) left on the license
LICENSE_TIMEOUT = 60 * 60 * 24 * 30
@ -98,23 +107,11 @@ class Licenser(object):
if 'company_name' in kwargs:
kwargs.pop('company_name')
self._attrs.update(kwargs)
if os.path.exists('/var/lib/awx/.tower_version'):
if 'valid_key' in self._attrs:
if not self._attrs['valid_key']:
self._unset_attrs()
else:
if 'valid_key' in self._attrs:
if not self._attrs['valid_key']:
self._unset_attrs()
else:
self._generate_open_config()
def _generate_open_config(self):
self._attrs.update(dict(license_type='open',
valid_key=True,
subscription_name='OPEN',
product_name="AWX",
))
settings.LICENSE = self._attrs
self._unset_attrs()
def _unset_attrs(self):