saml: use qommon method to post SOAP messages (#20089)
This commit is contained in:
parent
72caf60520
commit
e06b74f755
|
@ -269,7 +269,7 @@ def format_time(datetime, formatstring, gmtime = False):
|
|||
|
||||
return formatstring % locals()
|
||||
|
||||
def _http_request(url, method='GET', body=None, headers={}, timeout=None):
|
||||
def _http_request(url, method='GET', body=None, headers={}, cert_file=None, timeout=None):
|
||||
get_publisher().reload_cfg()
|
||||
|
||||
if url.startswith('http://'):
|
||||
|
@ -286,16 +286,15 @@ def _http_request(url, method='GET', body=None, headers={}, timeout=None):
|
|||
password = ''
|
||||
headers['Authorization'] = 'Basic %s' % base64.b64encode('%s:%s' % (username, password))
|
||||
|
||||
connection_kwargs = {'host': hostname}
|
||||
if timeout:
|
||||
connection_kwargs['timeout'] = timeout
|
||||
if cert_file:
|
||||
connection_kwargs['cert_file'] = cert_file
|
||||
if url.startswith('http://'):
|
||||
if timeout is None:
|
||||
conn = httplib.HTTPConnection(hostname)
|
||||
else:
|
||||
conn = httplib.HTTPConnection(hostname, timeout=timeout)
|
||||
else:
|
||||
if timeout is None:
|
||||
conn = httplib.HTTPSConnection(hostname)
|
||||
else:
|
||||
conn = httplib.HTTPSConnection(hostname, timeout=timeout)
|
||||
conn = httplib.HTTPConnection(**connection_kwargs)
|
||||
else: # https
|
||||
conn = httplib.HTTPSConnection(**connection_kwargs)
|
||||
query = query.replace('&', '&')
|
||||
|
||||
try:
|
||||
|
@ -321,17 +320,17 @@ def _http_request(url, method='GET', body=None, headers={}, timeout=None):
|
|||
|
||||
return response, status, data, auth_header
|
||||
|
||||
def http_get_page(url, headers={}, timeout=None):
|
||||
return _http_request(url, headers=headers, timeout=timeout)
|
||||
def http_get_page(url, **kwargs):
|
||||
return _http_request(url, **kwargs)
|
||||
|
||||
def http_patch_request(url, body=None, headers={}, timeout=None):
|
||||
return _http_request(url, 'PATCH', body, headers, timeout=timeout)
|
||||
def http_patch_request(url, body=None, **kwargs):
|
||||
return _http_request(url, 'PATCH', body, **kwargs)
|
||||
|
||||
def http_post_request(url, body=None, headers={}, timeout=None):
|
||||
return _http_request(url, 'POST', body, headers, timeout=timeout)
|
||||
def http_post_request(url, body=None, **kwargs):
|
||||
return _http_request(url, 'POST', body, **kwargs)
|
||||
|
||||
def http_delete_request(url, headers={}, timeout=None):
|
||||
return _http_request(url, 'DELETE', None, headers, timeout=timeout)
|
||||
def http_delete_request(url, **kwargs):
|
||||
return _http_request(url, 'DELETE', **kwargs)
|
||||
|
||||
def get_variadic_url(url, variables, encode_query=True):
|
||||
# substitution in an URL : try to be safe
|
||||
|
|
|
@ -54,24 +54,17 @@ def does_idp_authentication():
|
|||
|
||||
|
||||
def soap_call(url, msg, client_cert = None):
|
||||
if url.startswith('http://'):
|
||||
host, query = urllib.splithost(url[5:])
|
||||
conn = httplib.HTTPConnection(host)
|
||||
else:
|
||||
host, query = urllib.splithost(url[6:])
|
||||
conn = httplib.HTTPSConnection(host,
|
||||
key_file = client_cert, cert_file = client_cert)
|
||||
try:
|
||||
conn.request('POST', query, msg, {'Content-Type': 'text/xml'})
|
||||
response = conn.getresponse()
|
||||
except Exception, err:
|
||||
response, status, data, auth_header = misc.http_post_request(
|
||||
url, msg,
|
||||
headers={'Content-Type': 'text/xml'},
|
||||
cert_file=client_cert)
|
||||
except errors.ConnectionError as err:
|
||||
# exception could be raised by request
|
||||
get_logger().warn('SOAP error (on %s): %s' % (url, err))
|
||||
raise SOAPException(url)
|
||||
data = response.read()
|
||||
conn.close()
|
||||
if response.status not in (200, 204): # 204 ok for federation termination
|
||||
get_logger().warn('SOAP error (%s) (on %s)' % (response.status, url))
|
||||
if status not in (200, 204): # 204 ok for federation termination
|
||||
get_logger().warn('SOAP error (%s) (on %s)' % (status, url))
|
||||
raise SOAPException(url)
|
||||
return data
|
||||
|
||||
|
|
Loading…
Reference in New Issue