mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 00:08:44 -03:30
Only show the product version header when the requester is authenticated (#14135)
This commit is contained in:
@@ -232,7 +232,8 @@ 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()
|
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'] = server_product_name()
|
||||||
|
|
||||||
response['X-API-Node'] = settings.CLUSTER_HOST_ID
|
response['X-API-Node'] = settings.CLUSTER_HOST_ID
|
||||||
|
|||||||
@@ -533,13 +533,7 @@ class ControllerAPIModule(ControllerModule):
|
|||||||
controller_version = response.info().getheader('X-API-Product-Version', None)
|
controller_version = response.info().getheader('X-API-Product-Version', None)
|
||||||
|
|
||||||
parsed_collection_version = Version(self._COLLECTION_VERSION).version
|
parsed_collection_version = Version(self._COLLECTION_VERSION).version
|
||||||
if not controller_version:
|
if controller_version:
|
||||||
self.warn(
|
|
||||||
"You are using the {0} version of this collection but connecting to a controller that did not return a version".format(
|
|
||||||
self._COLLECTION_VERSION
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
parsed_controller_version = Version(controller_version).version
|
parsed_controller_version = Version(controller_version).version
|
||||||
if controller_type == 'AWX':
|
if controller_type == 'AWX':
|
||||||
collection_compare_ver = parsed_collection_version[0]
|
collection_compare_ver = parsed_collection_version[0]
|
||||||
|
|||||||
@@ -76,21 +76,6 @@ def test_version_warning(collection_import, silence_warning):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_no_version_warning(collection_import, silence_warning):
|
|
||||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
|
||||||
testargs = ['module_file2.py', json.dumps(cli_data)]
|
|
||||||
with mock.patch.object(sys, 'argv', testargs):
|
|
||||||
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_no_ping_response):
|
|
||||||
my_module = ControllerAPIModule(argument_spec=dict())
|
|
||||||
my_module._COLLECTION_VERSION = "2.0.0"
|
|
||||||
my_module._COLLECTION_TYPE = "awx"
|
|
||||||
my_module.get_endpoint('ping')
|
|
||||||
silence_warning.assert_called_once_with(
|
|
||||||
'You are using the {0} version of this collection but connecting to a controller that did not return a version'.format(my_module._COLLECTION_VERSION)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_version_warning_strictness_awx(collection_import, silence_warning):
|
def test_version_warning_strictness_awx(collection_import, silence_warning):
|
||||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||||
|
|||||||
Reference in New Issue
Block a user