simplify how awx "open" licensing works

This commit is contained in:
Ryan Petrello
2020-10-23 10:51:48 -04:00
parent 1f0b1923d7
commit 7c63a6592e
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. 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 # 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) response = super(APIView, self).finalize_response(request, response, *args, **kwargs)
time_started = getattr(self, 'time_started', None) time_started = getattr(self, 'time_started', None)
response['X-API-Product-Version'] = get_awx_version() 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 response['X-API-Node'] = settings.CLUSTER_HOST_ID
if time_started: if time_started:

View File

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

View File

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