mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 08:57:35 -02:30
Simplify hostname parsing
This commit is contained in:
@@ -7,6 +7,7 @@ from urllib import parse as urlparse
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from kubernetes import client, config
|
from kubernetes import client, config
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from awx.main.utils.common import parse_yaml_or_json
|
from awx.main.utils.common import parse_yaml_or_json
|
||||||
from awx.main.utils.execution_environments import get_default_pod_spec
|
from awx.main.utils.execution_environments import get_default_pod_spec
|
||||||
@@ -56,11 +57,10 @@ class PodManager(object):
|
|||||||
def create_secret(self, job):
|
def create_secret(self, job):
|
||||||
registry_cred = job.execution_environment.credential
|
registry_cred = job.execution_environment.credential
|
||||||
host = registry_cred.get_input('host')
|
host = registry_cred.get_input('host')
|
||||||
scheme = 'https'
|
|
||||||
# urlparse requires '//' to be provided if scheme is not specified
|
# urlparse requires '//' to be provided if scheme is not specified
|
||||||
original_parsed = urlparse.urlsplit(host)
|
original_parsed = urlparse.urlsplit(host)
|
||||||
if (not original_parsed.scheme and not host.startswith('//')) or original_parsed.hostname is None:
|
if (not original_parsed.scheme and not host.startswith('//')) or original_parsed.hostname is None:
|
||||||
host = '%s://%s' % (scheme, host)
|
host = 'https://%s' % (host)
|
||||||
parsed = urlparse.urlsplit(host)
|
parsed = urlparse.urlsplit(host)
|
||||||
host = parsed.hostname
|
host = parsed.hostname
|
||||||
if parsed.port:
|
if parsed.port:
|
||||||
@@ -102,8 +102,6 @@ class PodManager(object):
|
|||||||
)
|
)
|
||||||
full_error_msg = '{0}: {1}'.format(error_msg, str(e))
|
full_error_msg = '{0}: {1}'.format(error_msg, str(e))
|
||||||
logger.exception(full_error_msg)
|
logger.exception(full_error_msg)
|
||||||
job.job_explanation = error_msg
|
|
||||||
job.save()
|
|
||||||
raise PermissionError(full_error_msg)
|
raise PermissionError(full_error_msg)
|
||||||
|
|
||||||
if replace_secret:
|
if replace_secret:
|
||||||
@@ -121,8 +119,6 @@ class PodManager(object):
|
|||||||
)
|
)
|
||||||
full_error_msg = '{0}: {1}'.format(error_msg, str(e))
|
full_error_msg = '{0}: {1}'.format(error_msg, str(e))
|
||||||
logger.exception(full_error_msg)
|
logger.exception(full_error_msg)
|
||||||
job.job_explanation = error_msg
|
|
||||||
job.save()
|
|
||||||
# let job continue for the case where secret was created manually and cluster cred doesn't have permission to create a secret
|
# let job continue for the case where secret was created manually and cluster cred doesn't have permission to create a secret
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = 'Failed to create imagePullSecret for container group {}'.format(job.instance_group.name)
|
error_msg = 'Failed to create imagePullSecret for container group {}'.format(job.instance_group.name)
|
||||||
|
|||||||
@@ -47,11 +47,10 @@ def construct_rsyslog_conf_template(settings=settings):
|
|||||||
return tmpl
|
return tmpl
|
||||||
|
|
||||||
if protocol.startswith('http'):
|
if protocol.startswith('http'):
|
||||||
scheme = 'https'
|
|
||||||
# urlparse requires '//' to be provided if scheme is not specified
|
# urlparse requires '//' to be provided if scheme is not specified
|
||||||
original_parsed = urlparse.urlsplit(host)
|
original_parsed = urlparse.urlsplit(host)
|
||||||
if (not original_parsed.scheme and not host.startswith('//')) or original_parsed.hostname is None:
|
if (not original_parsed.scheme and not host.startswith('//')) or original_parsed.hostname is None:
|
||||||
host = '%s://%s' % (scheme, host)
|
host = 'https://%s' % (host)
|
||||||
parsed = urlparse.urlsplit(host)
|
parsed = urlparse.urlsplit(host)
|
||||||
|
|
||||||
host = escape_quotes(parsed.hostname)
|
host = escape_quotes(parsed.hostname)
|
||||||
|
|||||||
Reference in New Issue
Block a user