- raise Exception("host argument provided, but token missing.")
-
- connprofile = hashlib.sha1(' '.join([
- version, host, token, ('y' if apiinsecure else 'n')
- ])).hexdigest()
-
- if not cache or not services.get(connprofile):
- url = 'https://%s/discovery/v1/apis/{api}/{apiVersion}/rest' % host
- credentials = CredentialsFromToken(api_token=token)
-
- # 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 apiinsecure:
- http.disable_ssl_certificate_validation = True
- services[connprofile] = apiclient.discovery.build(
- 'arvados', version, http=http, discoveryServiceUrl=url)
- http.cache = None
-
- return services[connprofile]
+ raise ValueError("host argument provided, but token missing.")
+
+ if host:
+ # Caller wants us to build the discoveryServiceUrl
+ kwargs['discoveryServiceUrl'] = (
+ 'https://%s/discovery/v1/apis/{api}/{apiVersion}/rest' % (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 insecure:
+ http_kwargs['disable_ssl_certificate_validation'] = True
+ kwargs['http'] = httplib2.Http(**http_kwargs)
+
+ credentials = CredentialsFromToken(api_token=token)
+ kwargs['http'] = credentials.authorize(kwargs['http'])
+
+ svc = apiclient_discovery.build('arvados', version, **kwargs)
+ svc.api_token = token
+ kwargs['http'].cache = None
+ return svc