Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Merged
13 changes: 8 additions & 5 deletions qiskit/providers/ibmq/api_v2/ibmqclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@
class IBMQClient:
"""Client for programmatic access to the IBM Q API."""

def __init__(self, api_token, auth_url, proxies=None):
def __init__(self, api_token, auth_url, verify=True, proxies=None):
"""IBMQClient constructor.

Args:
api_token (str): IBM Q api token.
auth_url (str): URL for the authentication service.
verify (bool): if False, ignores SSL certificates errors.
proxies (dict): proxies used in the connection.
"""
self.api_token = api_token
self.auth_url = auth_url

self.client_auth = Auth(RetrySession(auth_url, proxies=proxies))
self.client_api, self.client_ws = self._init_service_clients(proxies=proxies)
self.client_auth = Auth(RetrySession(auth_url, verify=verify, proxies=proxies))
self.client_api, self.client_ws = self._init_service_clients(verify=verify, proxies=proxies)

def _init_service_clients(self, proxies):
def _init_service_clients(self, verify, proxies):
"""Initialize the clients used for communicating with the API and ws.

Args:
verify (bool): if False, ignores SSL certificates errors.
proxies (dict): proxies used in the connection.

Returns:
Expand All @@ -57,7 +59,8 @@ def _init_service_clients(self, proxies):
service_urls = self._user_urls()

# Create the api server client, using the access token.
client_api = Api(RetrySession(service_urls['http'], access_token, proxies=proxies))
client_api = Api(RetrySession(service_urls['http'], access_token,
verify=verify, proxies=proxies))

# Create the websocket server client, using the access token.
client_ws = WebsocketClient(service_urls['ws'], access_token)
Expand Down
7 changes: 5 additions & 2 deletions qiskit/providers/ibmq/api_v2/ibmqversionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
class IBMQVersionFinder:
"""Client for finding the API version being used."""

def __init__(self, url, proxies=None):
def __init__(self, url, verify=True, proxies=None):
"""IBMQVersionFinder constructor.

Args:
url (str): URL for the service.
verify (bool): if False, ignores SSL certificates errors.
proxies (dict): proxies used in the connection.
"""
self.client_version_finder = VersionFinder(RetrySession(url, proxies=proxies))
self.client_version_finder = VersionFinder(
RetrySession(url, verify=verify, proxies=proxies)
)

def version(self):
"""Return the version info.
Expand Down
2 changes: 2 additions & 0 deletions qiskit/providers/ibmq/ibmqsingleprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _authenticate(self, credentials):
# Use an IBMQVersionFinder for finding out the API version.
proxies = credentials.proxies.get('urls')
version_finder = IBMQVersionFinder(url=credentials.base_url,
verify=credentials.verify,
proxies=proxies)
version_info = version_finder.version()

Expand All @@ -90,6 +91,7 @@ def _authenticate(self, credentials):
if version_info['new_api'] and 'api-auth' in version_info:
return IBMQClient(api_token=credentials.token,
auth_url=credentials.url,
verify=credentials.verify,
proxies=proxies)
else:
# Prepare the config_dict for IBMQConnector.
Expand Down
12 changes: 6 additions & 6 deletions test/ibmq/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_proxies_ibmqclient(self, qe_token, qe_url):
"""Should reach the proxy using IBMQClient."""
pproxy_desired_access_log_line_ = pproxy_desired_access_log_line(qe_url)

_ = IBMQClient(qe_token, qe_url, VALID_PROXIES)
_ = IBMQClient(qe_token, qe_url, proxies=VALID_PROXIES)

self.proxy_process.terminate() # kill to be able of reading the output
self.assertIn(pproxy_desired_access_log_line_,
Expand All @@ -69,7 +69,7 @@ def test_proxies_ibmqversionfinder(self, qe_token, qe_url):
"""Should reach the proxy using IBMQVersionFinder."""
pproxy_desired_access_log_line_ = pproxy_desired_access_log_line(qe_url)

version_finder = IBMQVersionFinder(qe_url, VALID_PROXIES)
version_finder = IBMQVersionFinder(qe_url, proxies=VALID_PROXIES)
version_finder.version() # call the version finder, sending logging to the proxy process

self.proxy_process.terminate() # kill to be able of reading the output
Expand All @@ -81,7 +81,7 @@ def test_proxies_ibmqversionfinder(self, qe_token, qe_url):
def test_invalid_proxy_port_ibmqclient(self, qe_token, qe_url):
"""Should raise RequestApiError with ProxyError as original exception using IBMQClient."""
with self.assertRaises(RequestsApiError) as context_manager:
_ = IBMQClient(qe_token, qe_url, INVALID_PORT_PROXIES)
_ = IBMQClient(qe_token, qe_url, proxies=INVALID_PORT_PROXIES)

self.assertIsInstance(context_manager.exception.original_exception, ProxyError)

Expand All @@ -92,7 +92,7 @@ def test_invalid_proxy_port_ibmqversionfinder(self, qe_token, qe_url):
"""Should raise RequestApiError with ProxyError as
original exception using IBMQVersionFinder."""
with self.assertRaises(RequestsApiError) as context_manager:
version_finder = IBMQVersionFinder(qe_url, INVALID_PORT_PROXIES)
version_finder = IBMQVersionFinder(qe_url, proxies=INVALID_PORT_PROXIES)
version_finder.version()

self.assertIsInstance(context_manager.exception.original_exception, ProxyError)
Expand All @@ -103,7 +103,7 @@ def test_invalid_proxy_address_ibmqclient(self, qe_token, qe_url):
"""Should raise RequestApiError with ProxyError as
original exception using IBMQClient."""
with self.assertRaises(RequestsApiError) as context_manager:
_ = IBMQClient(qe_token, qe_url, INVALID_ADDRESS_PROXIES)
_ = IBMQClient(qe_token, qe_url, proxies=INVALID_ADDRESS_PROXIES)

self.assertIsInstance(context_manager.exception.original_exception, ProxyError)

Expand All @@ -114,7 +114,7 @@ def test_invalid_proxy_address_ibmqversionfinder(self, qe_token, qe_url):
"""Should raise RequestApiError with ProxyError as
original exception using IBMQVersionFinder."""
with self.assertRaises(RequestsApiError) as context_manager:
version_finder = IBMQVersionFinder(qe_url, INVALID_ADDRESS_PROXIES)
version_finder = IBMQVersionFinder(qe_url, proxies=INVALID_ADDRESS_PROXIES)
version_finder.version()

self.assertIsInstance(context_manager.exception.original_exception, ProxyError)
Expand Down