From 833827b545e266e072d45dcbac8d45c59fcce813 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Tue, 15 Feb 2022 16:10:36 +0100 Subject: [PATCH 01/15] personal API key --- dataikuapi/dss/admin.py | 32 ++++++++++++++++ dataikuapi/dssclient.py | 81 ++++++++++++++++++++++++++++++++++------- 2 files changed, 100 insertions(+), 13 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 175ca5a8d..cc66b84e5 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -1060,6 +1060,38 @@ def set_definition(self, definition): body = definition) +class DSSPersonalApiKey(object): + """ + A personal API key on the DSS instance + """ + def __init__(self, client, id_): + """Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key`""" + self.client = client + self.id_ = id_ + + ######################################################## + # Key description + ######################################################## + + def get_definition(self): + """ + Get the API key's definition + :returns: the personal API key definition, as a JSON object + """ + return self.client._perform_json( + "GET", "/personal-api-keys/%s" % (self.id_)) + + ######################################################## + # Key deletion + ######################################################## + + def delete(self): + """ + Delete the API key + """ + return self.client._perform_empty( + "DELETE", "/personal-api-keys/%s" % self.id_) + class DSSCluster(object): """ A handle to interact with a cluster on the DSS instance diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index cdb788a94..ee0277ab8 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -10,7 +10,7 @@ from .dss.project import DSSProject from .dss.app import DSSApp from .dss.plugin import DSSPlugin -from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables +from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables, DSSPersonalApiKey from .dss.meaning import DSSMeaning from .dss.sqlquery import DSSSQLQuery from .dss.discussion import DSSObjectDiscussions @@ -644,6 +644,73 @@ def create_global_api_key(self, label=None, description=None, admin=False): key = resp.get('key', '') return DSSGlobalApiKey(self, key) + ######################################################## + # Personal API Keys + ######################################################## + + def list_personal_api_keys(self, as_type='dict'): + """ + List all personal API keys: + - not admin: only the keys belonging to the current user + - admin: all the personal keys + :param str as_type: 'objects' or 'dict' + :returns: All personal API keys + """ + + resp = self._perform_json( + "GET", "/personal-api-keys/") + if as_type == 'objects': + return [DSSPersonalApiKey(self, item['id']) for item in resp] + else: + return resp + + def get_personal_api_key(self, id_): + """ + Get a specific API key + :param str id_: the id of the desired API key + :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key + """ + return DSSPersonalApiKey(self, id_) + + def list_personal_api_keys(self, as_type='dict'): + """ + List all personal API keys: + - not admin: only the keys belonging to the current user + - admin: all the personal keys + :param str as_type: 'objects' or 'dict' + :returns: All personal API keys + """ + + resp = self._perform_json( + "GET", "/personal-api-keys/all") + if as_type == 'objects': + return [DSSPersonalApiKey(self, item['id']) for item in resp] + else: + return resp + + def create_personal_api_key(self, label="", description="", as_type='dict', user=""): + """ + Create a Personal API key + :param str label: the label of the new API key + :param str description: the description of the new API key + :param str as_type: 'object' or 'dict' + :param str user: the id of the user to impersonate (optional) + :returns: The new personal API key + """ + resp = self._perform_json( + "POST", "/personal-api-keys/", body={"user": user, "label": label, "description": description}) + if resp is None: + raise Exception('API key creation returned no data') + if resp.get('messages', {}).get('error', False): + raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) + if not resp.get('id', False): + raise Exception('API key creation returned no key') + + if as_type == 'object': + return DSSPersonalApiKey(self, resp["id"]) + else: + return resp + ######################################################## # Meanings ######################################################## @@ -1001,18 +1068,6 @@ def get_ticket_from_browser_headers(self, headers_dict): """ return self._perform_json("POST", "/auth/ticket-from-browser-headers", body=headers_dict) - def create_personal_api_key(self, label): - """ - Creates a personal API key corresponding to the user doing the request. - This can be called if the DSSClient was initialized with an internal - ticket or with a personal API key - - :param: label string: Label for the new API key - :returns: a dict of the new API key, containing at least "secret", i.e. the actual secret API key - :rtype: dict - """ - return self._perform_json("POST", "/auth/personal-api-keys", - params={"label": label}) ######################################################## # Container execution From 88c1408b7067b11c57bc61317ba2c1da48583347 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Mon, 21 Feb 2022 16:59:38 +0100 Subject: [PATCH 02/15] WIP --- dataikuapi/dssclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index ee0277ab8..31b51fbb7 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -648,6 +648,9 @@ def create_global_api_key(self, label=None, description=None, admin=False): # Personal API Keys ######################################################## + def list_all_personal_api_keys(self, as_type='dict'): + + def list_personal_api_keys(self, as_type='dict'): """ List all personal API keys: @@ -688,7 +691,10 @@ def list_personal_api_keys(self, as_type='dict'): else: return resp - def create_personal_api_key(self, label="", description="", as_type='dict', user=""): + def create_personal_api_key_for_user(self, label="", description="", as_type='dict', user=""): + + + def create_personal_api_key(self, label="", description="", as_type='dict'): """ Create a Personal API key :param str label: the label of the new API key From b34a188cf8388d0d4183ec2bf4239b8c7746a094 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Tue, 29 Mar 2022 12:22:52 +0200 Subject: [PATCH 03/15] personal API key --- dataikuapi/dssclient.py | 70 +++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index 31b51fbb7..e530cce71 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -648,18 +648,12 @@ def create_global_api_key(self, label=None, description=None, admin=False): # Personal API Keys ######################################################## - def list_all_personal_api_keys(self, as_type='dict'): - - def list_personal_api_keys(self, as_type='dict'): """ - List all personal API keys: - - not admin: only the keys belonging to the current user - - admin: all the personal keys + List all your personal API keys :param str as_type: 'objects' or 'dict' - :returns: All personal API keys + :returns: All personal API keys associated with your user """ - resp = self._perform_json( "GET", "/personal-api-keys/") if as_type == 'objects': @@ -667,44 +661,65 @@ def list_personal_api_keys(self, as_type='dict'): else: return resp - def get_personal_api_key(self, id_): + def get_personal_api_key(self, key): """ - Get a specific API key - :param str id_: the id of the desired API key - :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key + Get a handle to interact with a specific Personal API key + + :param str key: the secret key of the desired API key + :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle """ - return DSSPersonalApiKey(self, id_) + return DSSPersonalApiKey(self, key) - def list_personal_api_keys(self, as_type='dict'): + + def create_personal_api_key(self, label="", description="", as_type='dict'): """ - List all personal API keys: - - not admin: only the keys belonging to the current user - - admin: all the personal keys - :param str as_type: 'objects' or 'dict' - :returns: All personal API keys + Create a Personal API key associated with your user + :param str label: the label of the new API key + :param str description: the description of the new API key + :param str as_type: 'object' or 'dict' + :returns: The new personal API key associated with your user """ + resp = self._perform_json( + "POST", "/personal-api-keys/", body={"label": label, "description": description}) + if resp is None: + raise Exception('API key creation returned no data') + if resp.get('messages', {}).get('error', False): + raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) + if not resp.get('id', False): + raise Exception('API key creation returned no key') + if as_type == 'object': + return DSSPersonalApiKey(self, resp["id"]) + else: + return resp + + def list_all_personal_api_keys(self, as_type='dict'): + """ + List all personal API keys + Only admin can list all the keys + :param str as_type: 'objects' or 'dict' + :returns: All personal API keys in DSS + """ resp = self._perform_json( - "GET", "/personal-api-keys/all") + "GET", "/admin/personal-api-keys/") if as_type == 'objects': return [DSSPersonalApiKey(self, item['id']) for item in resp] else: return resp - def create_personal_api_key_for_user(self, label="", description="", as_type='dict', user=""): - - def create_personal_api_key(self, label="", description="", as_type='dict'): + def create_personal_api_key_for_user(self, label="", description="", as_type='dict', user=""): """ - Create a Personal API key + Create a Personal API key associated on behalf of a user + Only admin can create a key for another user :param str label: the label of the new API key :param str description: the description of the new API key :param str as_type: 'object' or 'dict' - :param str user: the id of the user to impersonate (optional) - :returns: The new personal API key + :param str user: the id of the user to impersonate + :returns: The new personal API key associated with 'user' """ resp = self._perform_json( - "POST", "/personal-api-keys/", body={"user": user, "label": label, "description": description}) + "POST", "/admin/personal-api-keys/", body={"user": user, "label": label, "description": description}) if resp is None: raise Exception('API key creation returned no data') if resp.get('messages', {}).get('error', False): @@ -717,6 +732,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): else: return resp + ######################################################## # Meanings ######################################################## From 5dafd4a5f525a5ae9bec7fd4bb128457f87e3dc0 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Wed, 27 Apr 2022 11:27:27 +0200 Subject: [PATCH 04/15] implement Mickael comments --- dataikuapi/dss/admin.py | 2 ++ dataikuapi/dssclient.py | 42 ++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 965fff2ec..f33ed051f 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -1065,6 +1065,7 @@ def set_definition(self, definition): class DSSPersonalApiKey(object): """ A personal API key on the DSS instance + Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key` """ def __init__(self, client, id_): """Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key`""" @@ -1078,6 +1079,7 @@ def __init__(self, client, id_): def get_definition(self): """ Get the API key's definition + :returns: the personal API key definition, as a JSON object """ return self.client._perform_json( diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index 30b9965a3..0c9bf36c5 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -612,6 +612,7 @@ def get_global_api_key(self, key): Get a handle to interact with a specific Global API key :param str key: the secret key of the desired API key + :returns: A :class:`dataikuapi.dss.admin.DSSGlobalApiKey` API key handle """ return DSSGlobalApiKey(self, key) @@ -625,6 +626,7 @@ def create_global_api_key(self, label=None, description=None, admin=False): :param str label: the label of the new API key :param str description: the description of the new API key :param str admin: has the new API key admin rights (True or False) + :returns: A :class:`dataikuapi.dss.admin.DSSGlobalApiKey` API key handle """ resp = self._perform_json( @@ -651,8 +653,11 @@ def create_global_api_key(self, label=None, description=None, admin=False): def list_personal_api_keys(self, as_type='dict'): """ List all your personal API keys - :param str as_type: 'objects' or 'dict' - :returns: All personal API keys associated with your user + + :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + + :return: if as_type=dict, each personal API keys is returned as a dict. + if as_type=object, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/personal-api-keys/") @@ -661,23 +666,26 @@ def list_personal_api_keys(self, as_type='dict'): else: return resp - def get_personal_api_key(self, key): + def get_personal_api_key(self, id): """ Get a handle to interact with a specific Personal API key - :param str key: the secret key of the desired API key + :param str id: the secret id of the desired API key + :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle """ - return DSSPersonalApiKey(self, key) - + return DSSPersonalApiKey(self, id) def create_personal_api_key(self, label="", description="", as_type='dict'): """ Create a Personal API key associated with your user + :param str label: the label of the new API key :param str description: the description of the new API key - :param str as_type: 'object' or 'dict' - :returns: The new personal API key associated with your user + :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + + :return: if as_type=dict, the new personal API key is returned as a dict. + if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/personal-api-keys/", body={"label": label, "description": description}) @@ -697,8 +705,11 @@ def list_all_personal_api_keys(self, as_type='dict'): """ List all personal API keys Only admin can list all the keys - :param str as_type: 'objects' or 'dict' - :returns: All personal API keys in DSS + + :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + + :return: if as_type=dict, each personal API keys is returned as a dict. + if as_type=object, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/admin/personal-api-keys/") @@ -707,16 +718,18 @@ def list_all_personal_api_keys(self, as_type='dict'): else: return resp - - def create_personal_api_key_for_user(self, label="", description="", as_type='dict', user=""): + def create_personal_api_key_for_user(self, label="", description="", user="", as_type='dict'): """ Create a Personal API key associated on behalf of a user Only admin can create a key for another user + :param str label: the label of the new API key :param str description: the description of the new API key - :param str as_type: 'object' or 'dict' :param str user: the id of the user to impersonate - :returns: The new personal API key associated with 'user' + :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + + :return: if as_type=dict, the new personal API key is returned as a dict. + if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/admin/personal-api-keys/", body={"user": user, "label": label, "description": description}) @@ -732,7 +745,6 @@ def create_personal_api_key_for_user(self, label="", description="", as_type='di else: return resp - ######################################################## # Meanings ######################################################## From ab6086a2d1bb0c4023bbac098bcf11618937c1b4 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Wed, 4 May 2022 15:26:32 +0200 Subject: [PATCH 05/15] fix doc of get_personal_api_key --- dataikuapi/dssclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index 0c9bf36c5..190d9270e 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -670,7 +670,7 @@ def get_personal_api_key(self, id): """ Get a handle to interact with a specific Personal API key - :param str id: the secret id of the desired API key + :param str id: the id of the desired API key :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle """ From 45f2886b7bd7747a98193e8c141181e75736cb0a Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Wed, 11 May 2022 12:22:47 +0200 Subject: [PATCH 06/15] implement Mickael comments --- dataikuapi/dss/admin.py | 1 - dataikuapi/dssclient.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 8a813f5ec..02990c7cb 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -1142,7 +1142,6 @@ class DSSPersonalApiKey(object): Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key` """ def __init__(self, client, id_): - """Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key`""" self.client = client self.id_ = id_ diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index dc2748366..f0e51218a 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -742,7 +742,7 @@ def list_all_personal_api_keys(self, as_type='dict'): else: return resp - def create_personal_api_key_for_user(self, label="", description="", user="", as_type='dict'): + def create_personal_api_key_for_user(self, user, label="", description="", as_type='dict'): """ Create a Personal API key associated on behalf of a user Only admin can create a key for another user From 9d0053d5755705afb6f6cda8b9d585907a26aa03 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Wed, 11 May 2022 13:49:14 +0200 Subject: [PATCH 07/15] Change default type to object for new endpoints --- dataikuapi/dssclient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index f0e51218a..00161fbc5 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -674,7 +674,7 @@ def create_global_api_key(self, label=None, description=None, admin=False): # Personal API Keys ######################################################## - def list_personal_api_keys(self, as_type='dict'): + def list_personal_api_keys(self, as_type='object'): """ List all your personal API keys @@ -725,7 +725,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): else: return resp - def list_all_personal_api_keys(self, as_type='dict'): + def list_all_personal_api_keys(self, as_type='object'): """ List all personal API keys Only admin can list all the keys @@ -742,7 +742,7 @@ def list_all_personal_api_keys(self, as_type='dict'): else: return resp - def create_personal_api_key_for_user(self, user, label="", description="", as_type='dict'): + def create_personal_api_key_for_user(self, user, label="", description="", as_type='object'): """ Create a Personal API key associated on behalf of a user Only admin can create a key for another user From 332c18ac0afce54c024c1dca8a63ff29a3473828 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Thu, 12 May 2022 09:44:06 +0200 Subject: [PATCH 08/15] Fix default type objects --- dataikuapi/dssclient.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index 00161fbc5..ce92f2907 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -674,14 +674,14 @@ def create_global_api_key(self, label=None, description=None, admin=False): # Personal API Keys ######################################################## - def list_personal_api_keys(self, as_type='object'): + def list_personal_api_keys(self, as_type='objects'): """ List all your personal API keys :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" :return: if as_type=dict, each personal API keys is returned as a dict. - if as_type=object, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/personal-api-keys/") @@ -709,7 +709,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" :return: if as_type=dict, the new personal API key is returned as a dict. - if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=objects, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/personal-api-keys/", body={"label": label, "description": description}) @@ -720,12 +720,12 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): if not resp.get('id', False): raise Exception('API key creation returned no key') - if as_type == 'object': + if as_type == 'objects': return DSSPersonalApiKey(self, resp["id"]) else: return resp - def list_all_personal_api_keys(self, as_type='object'): + def list_all_personal_api_keys(self, as_type='objects'): """ List all personal API keys Only admin can list all the keys @@ -733,7 +733,7 @@ def list_all_personal_api_keys(self, as_type='object'): :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" :return: if as_type=dict, each personal API keys is returned as a dict. - if as_type=object, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/admin/personal-api-keys/") @@ -742,7 +742,7 @@ def list_all_personal_api_keys(self, as_type='object'): else: return resp - def create_personal_api_key_for_user(self, user, label="", description="", as_type='object'): + def create_personal_api_key_for_user(self, user, label="", description="", as_type='objects'): """ Create a Personal API key associated on behalf of a user Only admin can create a key for another user @@ -750,10 +750,10 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty :param str label: the label of the new API key :param str description: the description of the new API key :param str user: the id of the user to impersonate - :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" :return: if as_type=dict, the new personal API key is returned as a dict. - if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=objects, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/admin/personal-api-keys/", body={"user": user, "label": label, "description": description}) @@ -764,7 +764,7 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty if not resp.get('id', False): raise Exception('API key creation returned no key') - if as_type == 'object': + if as_type == 'objects': return DSSPersonalApiKey(self, resp["id"]) else: return resp From caa9dbe7a56d6410f1e923ae69cc11e4f068b208 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Thu, 12 May 2022 10:37:32 +0200 Subject: [PATCH 09/15] Use plurial type only for list objects --- dataikuapi/dssclient.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index ce92f2907..c7d42f763 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -709,7 +709,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" :return: if as_type=dict, the new personal API key is returned as a dict. - if as_type=objects, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/personal-api-keys/", body={"label": label, "description": description}) @@ -720,7 +720,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): if not resp.get('id', False): raise Exception('API key creation returned no key') - if as_type == 'objects': + if as_type == 'object': return DSSPersonalApiKey(self, resp["id"]) else: return resp @@ -742,7 +742,7 @@ def list_all_personal_api_keys(self, as_type='objects'): else: return resp - def create_personal_api_key_for_user(self, user, label="", description="", as_type='objects'): + def create_personal_api_key_for_user(self, user, label="", description="", as_type='object'): """ Create a Personal API key associated on behalf of a user Only admin can create a key for another user @@ -753,7 +753,7 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" :return: if as_type=dict, the new personal API key is returned as a dict. - if as_type=objects, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. + if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "POST", "/admin/personal-api-keys/", body={"user": user, "label": label, "description": description}) @@ -764,7 +764,7 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty if not resp.get('id', False): raise Exception('API key creation returned no key') - if as_type == 'objects': + if as_type == 'object': return DSSPersonalApiKey(self, resp["id"]) else: return resp From 9ea8cc6f9df58b19d4c8185cef88c71789e9da1d Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Thu, 12 May 2022 14:37:32 +0200 Subject: [PATCH 10/15] Implement Mickael's comments --- dataikuapi/dssclient.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index c7d42f763..ba65df8f7 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -676,7 +676,7 @@ def create_global_api_key(self, label=None, description=None, admin=False): def list_personal_api_keys(self, as_type='objects'): """ - List all your personal API keys + List all your personal API keys. :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" @@ -692,7 +692,7 @@ def list_personal_api_keys(self, as_type='objects'): def get_personal_api_key(self, id): """ - Get a handle to interact with a specific Personal API key + Get a handle to interact with a specific Personal API key. :param str id: the id of the desired API key @@ -702,7 +702,7 @@ def get_personal_api_key(self, id): def create_personal_api_key(self, label="", description="", as_type='dict'): """ - Create a Personal API key associated with your user + Create a Personal API key associated with your user. :param str label: the label of the new API key :param str description: the description of the new API key @@ -715,8 +715,6 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): "POST", "/personal-api-keys/", body={"label": label, "description": description}) if resp is None: raise Exception('API key creation returned no data') - if resp.get('messages', {}).get('error', False): - raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) if not resp.get('id', False): raise Exception('API key creation returned no key') @@ -727,8 +725,8 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): def list_all_personal_api_keys(self, as_type='objects'): """ - List all personal API keys - Only admin can list all the keys + List all personal API keys. + Only admin can list all the keys. :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" @@ -744,8 +742,8 @@ def list_all_personal_api_keys(self, as_type='objects'): def create_personal_api_key_for_user(self, user, label="", description="", as_type='object'): """ - Create a Personal API key associated on behalf of a user - Only admin can create a key for another user + Create a Personal API key associated on behalf of a user. + Only admin can create a key for another user. :param str label: the label of the new API key :param str description: the description of the new API key @@ -759,8 +757,6 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty "POST", "/admin/personal-api-keys/", body={"user": user, "label": label, "description": description}) if resp is None: raise Exception('API key creation returned no data') - if resp.get('messages', {}).get('error', False): - raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) if not resp.get('id', False): raise Exception('API key creation returned no key') From 8413957bf791d73b3438303d0f969e8a2a6cc5f9 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Thu, 12 May 2022 19:02:13 +0200 Subject: [PATCH 11/15] Implement Mickael's comments --- dataikuapi/dssclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index ba65df8f7..fc734ac67 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -678,7 +678,7 @@ def list_personal_api_keys(self, as_type='objects'): """ List all your personal API keys. - :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" :return: if as_type=dict, each personal API keys is returned as a dict. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. From b3304e3fca7f5a13a31ade8a9d3e62de5bf4f25b Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Thu, 12 May 2022 19:05:06 +0200 Subject: [PATCH 12/15] Implement Mickael's comments --- dataikuapi/dssclient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index fc734ac67..fd6681828 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -728,7 +728,7 @@ def list_all_personal_api_keys(self, as_type='objects'): List all personal API keys. Only admin can list all the keys. - :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" + :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" :return: if as_type=dict, each personal API keys is returned as a dict. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. @@ -748,7 +748,7 @@ def create_personal_api_key_for_user(self, user, label="", description="", as_ty :param str label: the label of the new API key :param str description: the description of the new API key :param str user: the id of the user to impersonate - :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" + :param str as_type: How to return the personal API keys. Possible values are "dict" and "object" :return: if as_type=dict, the new personal API key is returned as a dict. if as_type=object, the new personal API key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. From dbbcb10eeb92a38604e970614d9e4564c6a73871 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Tue, 17 May 2022 16:00:36 +0200 Subject: [PATCH 13/15] Adapt test to listitems --- dataikuapi/dss/admin.py | 34 ++++++++++++++++++++++++++++++++++ dataikuapi/dssclient.py | 23 ++++++++++++++--------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 02990c7cb..49a5afa33 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -1,5 +1,7 @@ import datetime +from dataikuapi.dss.utils import DSSTaggableObjectListItem + from .future import DSSFuture import json, warnings @@ -1169,6 +1171,38 @@ def delete(self): return self.client._perform_empty( "DELETE", "/personal-api-keys/%s" % self.id_) +class DSSPersonalApiKeyListItem(DSSTaggableObjectListItem): + """An item in a list of datasets. Do not instantiate this class, :meth:`dataikuapi.DSSClient.list_personal_api_keys` or :meth:`dataikuapi.DSSClient.list_all_personal_api_keys`""" + def __init__(self, client, data): + super(DSSPersonalApiKeyListItem, self).__init__(data) + self.client = client + + def to_personal_api_key(self): + """Gets the :class:`DSSPersonalApiKey` corresponding to this item""" + return DSSPersonalApiKey(self.client, self._data["id"]) + + @property + def id(self): + return self._data["id"] + @property + def user(self): + return self._data["user"] + @property + def key(self): + return self._data["key"] + @property + def label(self): + return self._data["label"] + @property + def description(self): + return self._data["description"] + @property + def created_on(self): + return self._data["createdOn"] + @property + def created_by(self): + return self._data["createdBy"] + class DSSCluster(object): """ A handle to interact with a cluster on the DSS instance diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index fd6681828..be761c8f9 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -10,7 +10,7 @@ from .dss.project import DSSProject from .dss.app import DSSApp from .dss.plugin import DSSPlugin -from .dss.admin import DSSUser, DSSUserActivity, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables, DSSPersonalApiKey +from .dss.admin import DSSPersonalApiKeyListItem, DSSUser, DSSUserActivity, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables, DSSPersonalApiKey from .dss.meaning import DSSMeaning from .dss.sqlquery import DSSSQLQuery @@ -674,21 +674,24 @@ def create_global_api_key(self, label=None, description=None, admin=False): # Personal API Keys ######################################################## - def list_personal_api_keys(self, as_type='objects'): + def list_personal_api_keys(self, as_type='listitems'): """ List all your personal API keys. :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" - :return: if as_type=dict, each personal API keys is returned as a dict. + :return: if as_type=listitems, each one as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/personal-api-keys/") - if as_type == 'objects': + + if as_type == "listitems": + return [DSSPersonalApiKeyListItem(self, item) for item in resp] + elif as_type == 'objects': return [DSSPersonalApiKey(self, item['id']) for item in resp] else: - return resp + raise ValueError("Unknown as_type") def get_personal_api_key(self, id): """ @@ -723,22 +726,24 @@ def create_personal_api_key(self, label="", description="", as_type='dict'): else: return resp - def list_all_personal_api_keys(self, as_type='objects'): + def list_all_personal_api_keys(self, as_type='listitems'): """ List all personal API keys. Only admin can list all the keys. :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" - :return: if as_type=dict, each personal API keys is returned as a dict. + :return: if as_type=listitems, each one as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( "GET", "/admin/personal-api-keys/") - if as_type == 'objects': + if as_type == "listitems": + return [DSSPersonalApiKeyListItem(self, item) for item in resp] + elif as_type == 'objects': return [DSSPersonalApiKey(self, item['id']) for item in resp] else: - return resp + raise ValueError("Unknown as_type") def create_personal_api_key_for_user(self, user, label="", description="", as_type='object'): """ From ac849082364f2aa30aecd01bfade5b86779a1fe0 Mon Sep 17 00:00:00 2001 From: Quentin Castel Date: Wed, 18 May 2022 09:13:14 +0200 Subject: [PATCH 14/15] implement Mickael comments --- dataikuapi/dss/admin.py | 101 ++++++++++++++++++++++------------------ dataikuapi/dssclient.py | 8 ++-- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 49a5afa33..09a216569 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -7,16 +7,15 @@ class DSSConnectionInfo(dict): """A class holding read-only information about a connection. - This class should not be created directly. Instead, use :meth:`DSSConnection.get_info` + Do not create this object directly, use :meth:`DSSConnection.get_info` instead. The main use case of this class is to retrieve the decrypted credentials for a connection, if allowed by the connection permissions. Depending on the connection kind, the credential may be available using :meth:`get_basic_credential` - or :meth:`get_aws_credential` + or :meth:`get_aws_credential`. """ def __init__(self, data): - """Do not call this directly, use :meth:`DSSConnection.get_info`""" super(DSSConnectionInfo, self).__init__(data) def get_type(self): @@ -54,9 +53,9 @@ def get_aws_credential(self): class DSSConnection(object): """ A connection on the DSS instance. + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_connection` instead. """ def __init__(self, client, name): - """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_connection`""" self.client = client self.name = name @@ -151,10 +150,9 @@ def sync_datasets_acls(self): class DSSUser(object): """ A handle for a user on the DSS instance. - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_user` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_user` instead. """ def __init__(self, client, login): - """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_user`""" self.client = client self.login = login @@ -243,7 +241,7 @@ def get_client_as(self): class DSSOwnUser(object): """ A handle to interact with your own user - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_own_user` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_own_user` instead. """ def __init__(self, client): self.client = client @@ -259,9 +257,11 @@ def get_settings(self): class DSSUserSettingsBase(object): - """Settings for a DSS user""" + """ + Settings for a DSS user. + Do not create this object directly, use :meth:`DSSUser.get_settings` or :meth:`DSSOwnUser.get_settings` instead. + """ def __init__(self, settings): - """Do not call this directly, use :meth:`DSSUser.get_settings` or :meth:`DSSOwnUser.get_settings` """ self.settings = settings def get_raw(self): @@ -333,10 +333,11 @@ def remove_plugin_credential(self, plugin_id, param_set_id, preset_id, param_nam class DSSUserSettings(DSSUserSettingsBase): - """Settings for a DSS user""" - + """ + Settings for a DSS user. + Do not create this object directly, use :meth:`DSSUser.get_settings` instead. + """ def __init__(self, client, login, settings): - """Do not call this directly, use :meth:`DSSUser.get_settings`""" super(DSSUserSettings, self).__init__(settings) self.client = client self.login = login @@ -368,10 +369,11 @@ def save(self): class DSSOwnUserSettings(DSSUserSettingsBase): - """Settings for the current DSS user""" - + """ + Settings for the current DSS user. + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_own_user` instead. + """ def __init__(self, client, settings): - """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_own_user`""" super(DSSOwnUserSettings, self).__init__(settings) self.client = client @@ -383,9 +385,8 @@ def save(self): class DSSUserActivity(object): """ Activity for a DSS user. - Do not call this directly, use :meth:`DSSUser.get_activity` or :meth:`DSSClient.list_users_activity` + Do not create this object directly, use :meth:`DSSUser.get_activity` or :meth:`DSSClient.list_users_activity` instead. """ - def __init__(self, client, login, activity): self.client = client self.login = login @@ -444,10 +445,9 @@ def last_session_activity(self): class DSSGroup(object): """ A group on the DSS instance. - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_group` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_group` instead. """ def __init__(self, client, name): - """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_group`""" self.client = client self.name = name @@ -490,10 +490,9 @@ def set_definition(self, definition): class DSSGeneralSettings(object): """ The general settings of the DSS instance. - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_general_settings` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_general_settings` instead. """ def __init__(self, client): - """Do not call this directly, use :meth:`dataikuapi.DSSClient.get_general_settings`""" self.client = client self.settings = self.client._perform_json("GET", "/admin/general-settings") @@ -616,6 +615,7 @@ def push_container_exec_base_images(self): raise Exception('Container exec base image push failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) return resp + class DSSUserImpersonationRule(object): """ Helper to build user-level rule items for the impersonation settings @@ -678,6 +678,7 @@ def user_regexp(self, regexp, unix_user, hadoop_user=None): self.raw['targetHadoop'] = hadoop_user return self + class DSSGroupImpersonationRule(object): """ Helper to build group-level rule items for the impersonation settings @@ -722,10 +723,11 @@ def group_regexp(self, regexp, unix_user, hadoop_user=None): self.raw['targetHadoop'] = hadoop_user return self + class DSSCodeEnv(object): """ A code env on the DSS instance. - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_code_env` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_code_env` instead. """ def __init__(self, client, env_lang, env_name): self.client = client @@ -925,7 +927,7 @@ def get_log(self, log_name): class DSSCodeEnvSettings(object): """ Base settings class for a DSS code env. - Do not instantiate this class directly, use :meth:`DSSCodeEnv.get_settings` + Do not create this object directly, use :meth:`DSSCodeEnv.get_settings` instead. Use :meth:`save` to save your changes """ @@ -950,6 +952,7 @@ def save(self): self.codeenv.client._perform_json( "PUT", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name), body=self.settings) + class DSSCodeEnvPackageListBearer(object): def get_required_packages(self, as_list=False): """ @@ -1027,11 +1030,10 @@ def set_built_spark_kubernetes_confs(self, *configs, **kwargs): class DSSDesignCodeEnvSettings(DSSCodeEnvSettings, DSSCodeEnvPackageListBearer, DSSCodeEnvContainerConfsBearer): """ Base settings class for a DSS code env on a design node. - Do not instantiate this class directly, use :meth:`DSSCodeEnv.get_settings` + Do not create this object directly, use :meth:`DSSCodeEnv.get_settings` instead. Use :meth:`save` to save your changes """ - def __init__(self, codeenv, settings): super(DSSDesignCodeEnvSettings, self).__init__(codeenv, settings) @@ -1039,15 +1041,13 @@ def __init__(self, codeenv, settings): class DSSAutomationCodeEnvSettings(DSSCodeEnvSettings, DSSCodeEnvContainerConfsBearer): """ Base settings class for a DSS code env on an automation node. - Do not instantiate this class directly, use :meth:`DSSCodeEnv.get_settings` + Do not create this object directly, use :meth:`DSSCodeEnv.get_settings` instead. Use :meth:`save` to save your changes """ - def __init__(self, codeenv, settings): super(DSSAutomationCodeEnvSettings, self).__init__(codeenv, settings) - def get_version(self, version_id=None): """ Get a specific code env version (for versioned envs) or the single @@ -1077,11 +1077,10 @@ def get_version(self, version_id=None): class DSSAutomationCodeEnvVersionSettings(DSSCodeEnvPackageListBearer): """ Base settings class for a DSS code env version on an automation node. - Do not instantiate this class directly, use :meth:`DSSAutomationCodeEnvSettings.get_version` + Do not create this object directly, use :meth:`DSSAutomationCodeEnvSettings.get_version` instead. Use :meth:`save` on the :class:`DSSAutomationCodeEnvSettings` to save your changes """ - def __init__(self, codeenv_settings, version_settings): self.codeenv_settings = codeenv_settings self.settings = version_settings @@ -1140,8 +1139,8 @@ def set_definition(self, definition): class DSSPersonalApiKey(object): """ - A personal API key on the DSS instance - Do not call that directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key` + A personal API key on the DSS instance. + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_personal_api_key` instead. """ def __init__(self, client, id_): self.client = client @@ -1171,8 +1170,12 @@ def delete(self): return self.client._perform_empty( "DELETE", "/personal-api-keys/%s" % self.id_) -class DSSPersonalApiKeyListItem(DSSTaggableObjectListItem): - """An item in a list of datasets. Do not instantiate this class, :meth:`dataikuapi.DSSClient.list_personal_api_keys` or :meth:`dataikuapi.DSSClient.list_all_personal_api_keys`""" + +class DSSPersonalApiKeyListItem(dict): + """ + An item in a list of personal API key. + Do not create this object directly, use :meth:`dataikuapi.DSSClient.list_personal_api_keys` or :meth:`dataikuapi.DSSClient.list_all_personal_api_keys` instead. + """ def __init__(self, client, data): super(DSSPersonalApiKeyListItem, self).__init__(data) self.client = client @@ -1184,31 +1187,39 @@ def to_personal_api_key(self): @property def id(self): return self._data["id"] + @property def user(self): return self._data["user"] + @property def key(self): return self._data["key"] + @property def label(self): return self._data["label"] + @property def description(self): return self._data["description"] + @property def created_on(self): - return self._data["createdOn"] + timestamp = self._data["createdOn"] + return datetime.datetime.fromtimestamp(timestamp / 1000) if timestamp > 0 else None + @property def created_by(self): return self._data["createdBy"] - + + class DSSCluster(object): """ - A handle to interact with a cluster on the DSS instance + A handle to interact with a cluster on the DSS instance. + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_cluster` instead. """ def __init__(self, client, cluster_id): - """Do not call that directly, use :meth:`dataikuapi.DSSClient.get_cluster`""" self.client = client self.cluster_id = cluster_id @@ -1302,10 +1313,10 @@ def stop(self, terminate=True): class DSSClusterSettings(object): """ - The settings of a cluster + The settings of a cluster. + Do not create this object directly, use :meth:`DSSCluster.get_settings` instead. """ def __init__(self, client, cluster_id, settings): - """Do not call directly, use :meth:`DSSCluster.get_settings`""" self.client = client self.cluster_id = cluster_id self.settings = settings @@ -1335,12 +1346,13 @@ def save(self): return self.client._perform_json( "PUT", "/admin/clusters/%s" % (self.cluster_id), body=self.settings) + class DSSClusterStatus(object): """ - The status of a cluster + The status of a cluster. + Do not create this object directly, use :meth:`DSSCluster.get_Status` instead. """ def __init__(self, client, cluster_id, status): - """Do not call directly, use :meth:`DSSCluster.get_Status`""" self.client = client self.cluster_id = cluster_id self.status = status @@ -1356,9 +1368,8 @@ class DSSInstanceVariables(dict): """ Dict containing the instance variables. The variables can be modified directly in the dict and persisted using its :meth:`save` method. - Do not create this directly, use :meth:`dataikuapi.DSSClient.get_global_variables` + Do not create this object directly, use :meth:`dataikuapi.DSSClient.get_global_variables` instead. """ - def __init__(self, client, variables): super(dict, self).__init__() self.update(variables) @@ -1376,7 +1387,7 @@ def save(self): class DSSGlobalUsageSummary(object): """ The summary of the usage of the DSS instance. - Do not create this directly, use :meth:`dataikuapi.dss.DSSClient.get_global_usage_summary` + Do not create this object directly, use :meth:`dataikuapi.dss.DSSClient.get_global_usage_summary` instead. """ def __init__(self, data): self.data = data diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index be761c8f9..b3a96bc27 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -678,9 +678,9 @@ def list_personal_api_keys(self, as_type='listitems'): """ List all your personal API keys. - :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" + :param str as_type: How to return the personal API keys. Possible values are "listitems" and "objects" - :return: if as_type=listitems, each one as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. + :return: if as_type=listitems, each key as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( @@ -731,9 +731,9 @@ def list_all_personal_api_keys(self, as_type='listitems'): List all personal API keys. Only admin can list all the keys. - :param str as_type: How to return the personal API keys. Possible values are "dict" and "objects" + :param str as_type: How to return the personal API keys. Possible values are "listitems" and "objects" - :return: if as_type=listitems, each one as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. + :return: if as_type=listitems, each key as a :class:`dataikuapi.dss.admin.DSSPersonalApiKeyListItem`. if as_type=objects, each key is returned as a :class:`dataikuapi.dss.admin.DSSPersonalApiKey`. """ resp = self._perform_json( From 9d94d96aaaca20ac8b1a2dcb2f251120e1d7144b Mon Sep 17 00:00:00 2001 From: Mickael Hoarau Date: Thu, 19 May 2022 09:06:57 +0200 Subject: [PATCH 15/15] Fix attributes not working anymore for listitem and some typos [sc-58209] --- dataikuapi/dss/admin.py | 21 ++++++++++----------- dataikuapi/dssclient.py | 6 ++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dataikuapi/dss/admin.py b/dataikuapi/dss/admin.py index 09a216569..d4c73018b 100644 --- a/dataikuapi/dss/admin.py +++ b/dataikuapi/dss/admin.py @@ -1,10 +1,9 @@ import datetime -from dataikuapi.dss.utils import DSSTaggableObjectListItem - from .future import DSSFuture import json, warnings + class DSSConnectionInfo(dict): """A class holding read-only information about a connection. Do not create this object directly, use :meth:`DSSConnection.get_info` instead. @@ -1182,36 +1181,36 @@ def __init__(self, client, data): def to_personal_api_key(self): """Gets the :class:`DSSPersonalApiKey` corresponding to this item""" - return DSSPersonalApiKey(self.client, self._data["id"]) + return DSSPersonalApiKey(self.client, self["id"]) @property def id(self): - return self._data["id"] + return self["id"] @property def user(self): - return self._data["user"] + return self["user"] @property def key(self): - return self._data["key"] + return self["key"] @property def label(self): - return self._data["label"] + return self["label"] @property def description(self): - return self._data["description"] + return self["description"] @property def created_on(self): - timestamp = self._data["createdOn"] + timestamp = self["createdOn"] return datetime.datetime.fromtimestamp(timestamp / 1000) if timestamp > 0 else None @property def created_by(self): - return self._data["createdBy"] + return self["createdBy"] class DSSCluster(object): @@ -1350,7 +1349,7 @@ def save(self): class DSSClusterStatus(object): """ The status of a cluster. - Do not create this object directly, use :meth:`DSSCluster.get_Status` instead. + Do not create this object directly, use :meth:`DSSCluster.get_status` instead. """ def __init__(self, client, cluster_id, status): self.client = client diff --git a/dataikuapi/dssclient.py b/dataikuapi/dssclient.py index b3a96bc27..736500bca 100644 --- a/dataikuapi/dssclient.py +++ b/dataikuapi/dssclient.py @@ -20,6 +20,7 @@ import os.path as osp from .utils import DataikuException, dku_basestring_type + class DSSClient(object): """Entry point for the DSS API client""" @@ -1146,7 +1147,6 @@ def apply_kubernetes_namespaces_policies(self): resp = self._perform_json("POST", "/admin/container-exec/actions/apply-kubernetes-policies") return DSSFuture.from_resp(self, resp) - ######################################################## # Global Instance Info ######################################################## @@ -1154,7 +1154,8 @@ def apply_kubernetes_namespaces_policies(self): def get_instance_info(self): """ Get global information about the DSS instance - :return: a :classss:`DSSInstanceInfo` + + :returns: a :class:`DSSInstanceInfo` """ resp = self._perform_json("GET", "/instance-info") return DSSInstanceInfo(resp) @@ -1284,6 +1285,7 @@ def execute(self, settings=None): return self.client._perform_json("POST", "/projects/import/%s/process" % (self.import_id), body = settings) + class DSSInstanceInfo(object): """Global information about the DSS instance"""