diff --git a/osc/conf.py b/osc/conf.py index 9e2dd430..7309e937 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -315,6 +315,11 @@ def parse_apisrv_url(scheme, apisrv): def urljoin(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): """ 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. apiurl = urljoin(*parse_apisrv_url(None, apiurl)) - try: + if is_known_apiurl(apiurl): return config['api_host_options'][apiurl] - except KeyError: - raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl, - '', apiurl) + raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl, + '', apiurl) def get_apiurl_usr(apiurl): """ diff --git a/osc/core.py b/osc/core.py index 5dac0093..83e6afff 100644 --- a/osc/core.py +++ b/osc/core.py @@ -2375,14 +2375,12 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100): req = urllib2.Request(url) api_host_options = {} - try: + if conf.is_known_apiurl(url): + # ok no external request urllib2.install_opener(conf._build_opener(url)) api_host_options = conf.get_apiurl_api_host_options(url) for header, value in api_host_options['http_headers']: req.add_header(header, value) - except: - # "external" request (url is no apiurl) - pass req.get_method = lambda: method