Skip to content

Commit c575a7a

Browse files
committed
Merge branch 'release/10.0'
2 parents 158f7d9 + e667a73 commit c575a7a

File tree

11 files changed

+502
-83
lines changed

11 files changed

+502
-83
lines changed

dataikuapi/apinode_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ class APINodeClient(DSSBaseClient):
66
This is an API client for the user-facing API of DSS API Node server (user facing API)
77
"""
88

9-
def __init__(self, uri, service_id, api_key=None):
9+
def __init__(self, uri, service_id, api_key=None, bearer_token=None):
1010
"""
1111
Instantiate a new DSS API client on the given base URI with the given API key.
1212
1313
:param str uri: Base URI of the DSS API node server (http://host:port/ or https://host:port/)
1414
:param str service_id: Identifier of the service to query
15-
:param str api_key: Optional, API key for the service. Only required if the service has authentication
15+
:param str api_key: Optional, API key for the service. Only required if the service has its authorization setup to API keys
16+
:param str bearer_token: Optional, The bearer token. Only required if the service has its authorization setup to OAuth2/JWT
1617
"""
17-
DSSBaseClient.__init__(self, "%s/%s" % (uri, "public/api/v1/%s" % service_id), api_key)
18+
DSSBaseClient.__init__(self, "%s/%s" % (uri, "public/api/v1/%s" % service_id), api_key=api_key, bearer_token=bearer_token)
1819

1920
def predict_record(self, endpoint_id, features, forced_generation=None, dispatch_key=None, context=None,
2021
with_explanations=None, explanation_method=None, n_explanations=None, n_explanations_mc_steps=None):

dataikuapi/base_client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from .utils import DataikuException
66

77
class DSSBaseClient(object):
8-
def __init__(self, base_uri, api_key=None, internal_ticket=None):
8+
def __init__(self, base_uri, api_key=None, internal_ticket=None, bearer_token=None):
99
self.api_key = api_key
10+
self.bearer_token = bearer_token
1011
self.base_uri = base_uri
1112
self._session = Session()
1213

@@ -18,12 +19,18 @@ def _perform_http(self, method, path, params=None, body=None, stream=False):
1819
if body:
1920
body = json.dumps(body)
2021

21-
auth = HTTPBasicAuth(self.api_key, "")
22+
headers = None
23+
auth = None
24+
25+
if self.api_key:
26+
auth = HTTPBasicAuth(self.api_key, "")
27+
elif self.bearer_token:
28+
headers = {"Authorization": "Bearer " + self.bearer_token}
2229

2330
try:
2431
http_res = self._session.request(
2532
method, "%s/%s" % (self.base_uri, path),
26-
params=params, data=body,
33+
params=params, data=body, headers=headers,
2734
auth=auth, stream = stream)
2835
http_res.raise_for_status()
2936
return http_res

0 commit comments

Comments
 (0)