diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 887b6c587b..84b2ebc151 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -64,7 +64,7 @@ from awx.api.filters import V1CredentialFilterBackend from awx.api.generics import get_view_name from awx.api.generics import * # noqa from awx.api.versioning import reverse, get_request_version -from awx.conf.license import feature_enabled, feature_exists, LicenseForbids +from awx.conf.license import feature_enabled, feature_exists, LicenseForbids, get_license from awx.main.models import * # noqa from awx.main.utils import * # noqa from awx.main.utils import ( @@ -1592,7 +1592,15 @@ class HostInsights(GenericAPIView): def _get_insights(self, url, username, password): session = requests.Session() session.auth = requests.auth.HTTPBasicAuth(username, password) - headers = {'Content-Type': 'application/json'} + license = get_license(show_key=False).get('license_type', 'UNLICENSED') + headers = { + 'Content-Type': 'application/json', + 'User-Agent': '{} {} ({})'.format( + 'AWX' if license == 'open' else 'Red Hat Ansible Tower', + get_awx_version(), + license + ) + } return session.get(url, headers=headers, timeout=120) def get_insights(self, url, username, password): diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index 76c2c6236d..e9a3f177b9 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import re + import mock import pytest import requests @@ -218,6 +220,10 @@ class TestHostInsights(): assert resp.data['error'] == 'The Insights Credential for "inventory_name_here" was not found.' assert resp.status_code == 404 + def test_get_insights_user_agent(self, patch_parent, mocker): + resp = HostInsights()._get_insights('https://example.org', 'joe', 'example') + assert re.match(r'AWX [^\s]+ \(open\)', resp.request.headers['User-Agent']) + class TestSurveySpecValidation: diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 1e0fed8596..a78c91e692 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -951,7 +951,7 @@ TOWER_ADMIN_ALERTS = True # Note: This setting may be overridden by database settings. TOWER_URL_BASE = "https://towerhost" -INSIGHTS_URL_BASE = "https://access.redhat.com" +INSIGHTS_URL_BASE = "https://example.org" TOWER_SETTINGS_MANIFEST = {}