Skip to content

SSL client certificate support #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dataikuapi/apinode_admin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
class APINodeAdminClient(DSSBaseClient):
"""Entry point for the DSS APINode admin client"""

def __init__(self, uri, api_key):
def __init__(self, uri, api_key, **kwargs):
"""
Instantiate a new DSS API client on the given base uri with the given API key.

:param str uri: Base URI of the DSS API node server (http://host:port/ or https://host:port/)
:param str api_key: Optional, API key for the service. Only required if the service has authentication
:param str tls_verify: Optional, can be False to disable CA checks, True to force enable, or be a file name containing the CA certs to be trusted
:param str tls_client_cert: Optional, set a TLS/SSL client certificate. Use a string tuple (cert,key) or a string for a combined certificate
"""
DSSBaseClient.__init__(self, "%s/%s" % (uri, "admin/api"), api_key)
DSSBaseClient.__init__(self, "%s/%s" % (uri, "admin/api"), api_key, **kwargs)

########################################################
# Services generations
Expand Down
6 changes: 4 additions & 2 deletions dataikuapi/apinode_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ class APINodeClient(DSSBaseClient):
This is an API client for the user-facing API of DSS API Node server (user facing API)
"""

def __init__(self, uri, service_id, api_key=None):
def __init__(self, uri, service_id, api_key=None, **kwargs):
"""
Instantiate a new DSS API client on the given base URI with the given API key.

:param str uri: Base URI of the DSS API node server (http://host:port/ or https://host:port/)
:param str service_id: Identifier of the service to query
:param str api_key: Optional, API key for the service. Only required if the service has authentication
:param str tls_verify: Optional, can be False to disable CA checks, True to force enable, or be a file name containing the CA certs to be trusted
:param str tls_client_cert: Optional, set a TLS/SSL client certificate. Use a string tuple (cert,key) or a string for a combined certificate
"""
DSSBaseClient.__init__(self, "%s/%s" % (uri, "public/api/v1/%s" % service_id), api_key)
DSSBaseClient.__init__(self, "%s/%s" % (uri, "public/api/v1/%s" % service_id), api_key, **kwargs)

def predict_record(self, endpoint_id, features, forced_generation=None, dispatch_key=None, context=None):
"""
Expand Down
6 changes: 5 additions & 1 deletion dataikuapi/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from .utils import DataikuException

class DSSBaseClient(object):
def __init__(self, base_uri, api_key=None, internal_ticket=None):
def __init__(self, base_uri, api_key=None, internal_ticket=None, tls_verify=None, tls_client_cert=None):
self.api_key = api_key
self.base_uri = base_uri
self._session = Session()
if tls_verify is not None:
self._session.verify = tls_verify
if tls_client_cert is not None:
self._session.cert = tls_client_cert

########################################################
# Internal Request handling
Expand Down
11 changes: 10 additions & 1 deletion dataikuapi/dssclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@
class DSSClient(object):
"""Entry point for the DSS API client"""

def __init__(self, host, api_key=None, internal_ticket = None):
def __init__(self, host, api_key=None, internal_ticket=None, tls_verify=None, tls_client_cert=None):
"""
Instantiate a new DSS API client on the given host with the given API key.

API keys can be managed in DSS on the project page or in the global settings.

The API key will define which operations are allowed for the client.

:param str host: Base URI of the DSS Design/Automation node server (http://host:port/ or https://host:port/)
:param str api_key: Optional, API key for the service. Only required if the service has authentication
:param str tls_verify: Optional, can be False to disable CA checks, True to force enable, or be a file name containing the CA certs to be trusted
:param str tls_client_cert: Optional, set a TLS/SSL client certificate. Use a string tuple (cert,key) or a string for a combined certificate
"""
self.api_key = api_key
self.internal_ticket = internal_ticket
self.host = host
self._session = Session()
if tls_verify is not None:
self._session.verify = tls_verify
if tls_client_cert is not None:
self._session.cert = tls_client_cert

if self.api_key is not None:
self._session.auth = HTTPBasicAuth(self.api_key, "")
Expand Down