mirror of
https://github.com/ansible/awx.git
synced 2026-03-25 21:05:03 -02:30
Merge pull request #2716 from ryanpetrello/insights-user-agent
add a user agent for requests to Insights Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -64,7 +64,7 @@ from awx.api.filters import V1CredentialFilterBackend
|
|||||||
from awx.api.generics import get_view_name
|
from awx.api.generics import get_view_name
|
||||||
from awx.api.generics import * # noqa
|
from awx.api.generics import * # noqa
|
||||||
from awx.api.versioning import reverse, get_request_version
|
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.models import * # noqa
|
||||||
from awx.main.utils import * # noqa
|
from awx.main.utils import * # noqa
|
||||||
from awx.main.utils import (
|
from awx.main.utils import (
|
||||||
@@ -1592,7 +1592,15 @@ class HostInsights(GenericAPIView):
|
|||||||
def _get_insights(self, url, username, password):
|
def _get_insights(self, url, username, password):
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.auth = requests.auth.HTTPBasicAuth(username, password)
|
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)
|
return session.get(url, headers=headers, timeout=120)
|
||||||
|
|
||||||
def get_insights(self, url, username, password):
|
def get_insights(self, url, username, password):
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import re
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@@ -218,6 +220,10 @@ class TestHostInsights():
|
|||||||
assert resp.data['error'] == 'The Insights Credential for "inventory_name_here" was not found.'
|
assert resp.data['error'] == 'The Insights Credential for "inventory_name_here" was not found.'
|
||||||
assert resp.status_code == 404
|
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:
|
class TestSurveySpecValidation:
|
||||||
|
|
||||||
|
|||||||
@@ -951,7 +951,7 @@ TOWER_ADMIN_ALERTS = True
|
|||||||
# Note: This setting may be overridden by database settings.
|
# Note: This setting may be overridden by database settings.
|
||||||
TOWER_URL_BASE = "https://towerhost"
|
TOWER_URL_BASE = "https://towerhost"
|
||||||
|
|
||||||
INSIGHTS_URL_BASE = "https://access.redhat.com"
|
INSIGHTS_URL_BASE = "https://example.org"
|
||||||
|
|
||||||
TOWER_SETTINGS_MANIFEST = {}
|
TOWER_SETTINGS_MANIFEST = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user