mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 10:10:01 -03:30
Use AWX_TASK_ENV when connecting to Red Hat services
This commit is contained in:
@@ -81,7 +81,8 @@ from awx.main.utils import (
|
|||||||
getattrd,
|
getattrd,
|
||||||
get_pk_from_dict,
|
get_pk_from_dict,
|
||||||
schedule_task_manager,
|
schedule_task_manager,
|
||||||
ignore_inventory_computed_fields
|
ignore_inventory_computed_fields,
|
||||||
|
set_environ
|
||||||
)
|
)
|
||||||
from awx.main.utils.encryption import encrypt_value
|
from awx.main.utils.encryption import encrypt_value
|
||||||
from awx.main.utils.filters import SmartFilter
|
from awx.main.utils.filters import SmartFilter
|
||||||
@@ -1606,7 +1607,8 @@ class HostInsights(GenericAPIView):
|
|||||||
|
|
||||||
def _call_insights_api(self, url, session, headers):
|
def _call_insights_api(self, url, session, headers):
|
||||||
try:
|
try:
|
||||||
res = session.get(url, headers=headers, timeout=120)
|
with set_environ(**settings.AWX_TASK_ENV):
|
||||||
|
res = session.get(url, headers=headers, timeout=120)
|
||||||
except requests.exceptions.SSLError:
|
except requests.exceptions.SSLError:
|
||||||
raise BadGateway(_('SSLError while trying to connect to {}').format(url))
|
raise BadGateway(_('SSLError while trying to connect to {}').format(url))
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ from awx.main.models import (
|
|||||||
InstanceGroup,
|
InstanceGroup,
|
||||||
JobTemplate,
|
JobTemplate,
|
||||||
)
|
)
|
||||||
|
from awx.main.utils import set_environ
|
||||||
|
|
||||||
logger = logging.getLogger('awx.api.views.root')
|
logger = logging.getLogger('awx.api.views.root')
|
||||||
|
|
||||||
@@ -191,7 +192,8 @@ class ApiV2SubscriptionView(APIView):
|
|||||||
data['rh_password'] = settings.REDHAT_PASSWORD
|
data['rh_password'] = settings.REDHAT_PASSWORD
|
||||||
try:
|
try:
|
||||||
user, pw = data.get('rh_username'), data.get('rh_password')
|
user, pw = data.get('rh_username'), data.get('rh_password')
|
||||||
validated = get_licenser().validate_rh(user, pw)
|
with set_environ(**settings.AWX_TASK_ENV):
|
||||||
|
validated = get_licenser().validate_rh(user, pw)
|
||||||
if user:
|
if user:
|
||||||
settings.REDHAT_USERNAME = data['rh_username']
|
settings.REDHAT_USERNAME = data['rh_username']
|
||||||
if pw:
|
if pw:
|
||||||
@@ -203,10 +205,15 @@ class ApiV2SubscriptionView(APIView):
|
|||||||
getattr(getattr(exc, 'response', None), 'status_code', None) == 401
|
getattr(getattr(exc, 'response', None), 'status_code', None) == 401
|
||||||
):
|
):
|
||||||
msg = _("The provided credentials are invalid (HTTP 401).")
|
msg = _("The provided credentials are invalid (HTTP 401).")
|
||||||
if isinstance(exc, (ValueError, OSError)) and exc.args:
|
elif isinstance(exc, requests.exceptions.ProxyError):
|
||||||
|
msg = _("Unable to connect to proxy server.")
|
||||||
|
elif isinstance(exc, requests.exceptions.ConnectionError):
|
||||||
|
msg = _("Could not connect to subscription service.")
|
||||||
|
elif isinstance(exc, (ValueError, OSError)) and exc.args:
|
||||||
msg = exc.args[0]
|
msg = exc.args[0]
|
||||||
logger.exception(smart_text(u"Invalid license submitted."),
|
else:
|
||||||
extra=dict(actor=request.user.username))
|
logger.exception(smart_text(u"Invalid license submitted."),
|
||||||
|
extra=dict(actor=request.user.username))
|
||||||
return Response({"error": msg}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": msg}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
return Response(validated)
|
return Response(validated)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from awx.conf.license import get_license
|
|||||||
from awx.main.models import Job
|
from awx.main.models import Job
|
||||||
from awx.main.access import access_registry
|
from awx.main.access import access_registry
|
||||||
from awx.main.models.ha import TowerAnalyticsState
|
from awx.main.models.ha import TowerAnalyticsState
|
||||||
from awx.main.utils import get_awx_http_client_headers
|
from awx.main.utils import get_awx_http_client_headers, set_environ
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['register', 'gather', 'ship', 'table_version']
|
__all__ = ['register', 'gather', 'ship', 'table_version']
|
||||||
@@ -169,12 +169,13 @@ def ship(path):
|
|||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s.headers = get_awx_http_client_headers()
|
s.headers = get_awx_http_client_headers()
|
||||||
s.headers.pop('Content-Type')
|
s.headers.pop('Content-Type')
|
||||||
response = s.post(url,
|
with set_environ(**settings.AWX_TASK_ENV):
|
||||||
files=files,
|
response = s.post(url,
|
||||||
verify="/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
|
files=files,
|
||||||
auth=(rh_user, rh_password),
|
verify="/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
|
||||||
headers=s.headers,
|
auth=(rh_user, rh_password),
|
||||||
timeout=(31, 31))
|
headers=s.headers,
|
||||||
|
timeout=(31, 31))
|
||||||
if response.status_code != 202:
|
if response.status_code != 202:
|
||||||
return logger.exception('Upload failed with status {}, {}'.format(response.status_code,
|
return logger.exception('Upload failed with status {}, {}'.format(response.status_code,
|
||||||
response.text))
|
response.text))
|
||||||
|
|||||||
Reference in New Issue
Block a user