- apiVersion)
- if 'ARVADOS_API_HOST' not in config.settings():
- raise Exception("ARVADOS_API_HOST is not set. Aborting.")
- url = ('https://%s/discovery/v1/apis/{api}/{apiVersion}/rest' %
- config.get('ARVADOS_API_HOST'))
- credentials = CredentialsFromEnv()
-
- # Use system's CA certificates (if we find them) instead of httplib2's
- ca_certs = '/etc/ssl/certs/ca-certificates.crt'
- if not os.path.exists(ca_certs):
- ca_certs = None # use httplib2 default
-
- http = httplib2.Http(ca_certs=ca_certs,
- cache=(http_cache('discovery') if cache else None))
- http = credentials.authorize(http)
- if re.match(r'(?i)^(true|1|yes)$',
- config.get('ARVADOS_API_HOST_INSECURE', 'no')):
- http.disable_ssl_certificate_validation=True
- services[version] = apiclient.discovery.build(
- 'arvados', apiVersion, http=http, discoveryServiceUrl=url)
- http.cache = None
+ version)
+
+ if 'discoveryServiceUrl' not in kwargs:
+ api_host = config.get('ARVADOS_API_HOST')
+ if not api_host:
+ raise ValueError(
+ "No discoveryServiceUrl or ARVADOS_API_HOST set.")
+ kwargs['discoveryServiceUrl'] = (
+ 'https://%s/discovery/v1/apis/{api}/{apiVersion}/rest' %
+ (api_host,))
+
+ if 'http' not in kwargs:
+ http_kwargs = {}
+ # Prefer system's CA certificates (if available) over httplib2's.
+ certs_path = '/etc/ssl/certs/ca-certificates.crt'
+ if os.path.exists(certs_path):
+ http_kwargs['ca_certs'] = certs_path
+ if cache:
+ http_kwargs['cache'] = http_cache('discovery')
+ if (config.get('ARVADOS_API_HOST_INSECURE', '').lower() in
+ ('yes', 'true', '1')):
+ http_kwargs['disable_ssl_certificate_validation'] = True
+ kwargs['http'] = httplib2.Http(**http_kwargs)
+
+ kwargs['http'] = CredentialsFromEnv().authorize(kwargs['http'])
+ services[version] = apiclient.discovery.build('arvados', version,
+ **kwargs)
+ kwargs['http'].cache = None