mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-26 18:06:13 +01:00
- added is_known_apiurl method to check if a given url is a known apiurl
This commit is contained in:
parent
109e199445
commit
7145ecf0c9
12
osc/conf.py
12
osc/conf.py
@ -315,6 +315,11 @@ def parse_apisrv_url(scheme, apisrv):
|
|||||||
def urljoin(scheme, apisrv):
|
def urljoin(scheme, apisrv):
|
||||||
return '://'.join([scheme, apisrv])
|
return '://'.join([scheme, apisrv])
|
||||||
|
|
||||||
|
def is_known_apiurl(url):
|
||||||
|
"""returns true if url is a known apiurl"""
|
||||||
|
apiurl = urljoin(*parse_apisrv_url(None, url))
|
||||||
|
return config['api_host_options'].has_key(apiurl)
|
||||||
|
|
||||||
def get_apiurl_api_host_options(apiurl):
|
def get_apiurl_api_host_options(apiurl):
|
||||||
"""
|
"""
|
||||||
Returns all apihost specific options for the given apiurl, None if
|
Returns all apihost specific options for the given apiurl, None if
|
||||||
@ -325,11 +330,10 @@ def get_apiurl_api_host_options(apiurl):
|
|||||||
# had been mingled into before. But this works fine for now.
|
# had been mingled into before. But this works fine for now.
|
||||||
|
|
||||||
apiurl = urljoin(*parse_apisrv_url(None, apiurl))
|
apiurl = urljoin(*parse_apisrv_url(None, apiurl))
|
||||||
try:
|
if is_known_apiurl(apiurl):
|
||||||
return config['api_host_options'][apiurl]
|
return config['api_host_options'][apiurl]
|
||||||
except KeyError:
|
raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl,
|
||||||
raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl,
|
'', apiurl)
|
||||||
'', apiurl)
|
|
||||||
|
|
||||||
def get_apiurl_usr(apiurl):
|
def get_apiurl_usr(apiurl):
|
||||||
"""
|
"""
|
||||||
|
@ -2375,14 +2375,12 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100):
|
|||||||
|
|
||||||
req = urllib2.Request(url)
|
req = urllib2.Request(url)
|
||||||
api_host_options = {}
|
api_host_options = {}
|
||||||
try:
|
if conf.is_known_apiurl(url):
|
||||||
|
# ok no external request
|
||||||
urllib2.install_opener(conf._build_opener(url))
|
urllib2.install_opener(conf._build_opener(url))
|
||||||
api_host_options = conf.get_apiurl_api_host_options(url)
|
api_host_options = conf.get_apiurl_api_host_options(url)
|
||||||
for header, value in api_host_options['http_headers']:
|
for header, value in api_host_options['http_headers']:
|
||||||
req.add_header(header, value)
|
req.add_header(header, value)
|
||||||
except:
|
|
||||||
# "external" request (url is no apiurl)
|
|
||||||
pass
|
|
||||||
|
|
||||||
req.get_method = lambda: method
|
req.get_method = lambda: method
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user