@@ -648,63 +648,78 @@ def create_global_api_key(self, label=None, description=None, admin=False):
648648 # Personal API Keys
649649 ########################################################
650650
651- def list_all_personal_api_keys (self , as_type = 'dict' ):
652-
653-
654651 def list_personal_api_keys (self , as_type = 'dict' ):
655652 """
656- List all personal API keys:
657- - not admin: only the keys belonging to the current user
658- - admin: all the personal keys
653+ List all your personal API keys
659654 :param str as_type: 'objects' or 'dict'
660- :returns: All personal API keys
655+ :returns: All personal API keys associated with your user
661656 """
662-
663657 resp = self ._perform_json (
664658 "GET" , "/personal-api-keys/" )
665659 if as_type == 'objects' :
666660 return [DSSPersonalApiKey (self , item ['id' ]) for item in resp ]
667661 else :
668662 return resp
669663
670- def get_personal_api_key (self , id_ ):
664+ def get_personal_api_key (self , key ):
671665 """
672- Get a specific API key
673- :param str id_: the id of the desired API key
674- :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key
666+ Get a handle to interact with a specific Personal API key
667+
668+ :param str key: the secret key of the desired API key
669+ :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle
675670 """
676- return DSSPersonalApiKey (self , id_ )
671+ return DSSPersonalApiKey (self , key )
677672
678- def list_personal_api_keys (self , as_type = 'dict' ):
673+
674+ def create_personal_api_key (self , label = "" , description = "" , as_type = 'dict' ):
679675 """
680- List all personal API keys:
681- - not admin: only the keys belonging to the current user
682- - admin: all the personal keys
683- :param str as_type: 'objects ' or 'dict'
684- :returns: All personal API keys
676+ Create a Personal API key associated with your user
677+ :param str label: the label of the new API key
678+ :param str description: the description of the new API key
679+ :param str as_type: 'object ' or 'dict'
680+ :returns: The new personal API key associated with your user
685681 """
682+ resp = self ._perform_json (
683+ "POST" , "/personal-api-keys/" , body = {"label" : label , "description" : description })
684+ if resp is None :
685+ raise Exception ('API key creation returned no data' )
686+ if resp .get ('messages' , {}).get ('error' , False ):
687+ raise Exception ('API key creation failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
688+ if not resp .get ('id' , False ):
689+ raise Exception ('API key creation returned no key' )
686690
691+ if as_type == 'object' :
692+ return DSSPersonalApiKey (self , resp ["id" ])
693+ else :
694+ return resp
695+
696+ def list_all_personal_api_keys (self , as_type = 'dict' ):
697+ """
698+ List all personal API keys
699+ Only admin can list all the keys
700+ :param str as_type: 'objects' or 'dict'
701+ :returns: All personal API keys in DSS
702+ """
687703 resp = self ._perform_json (
688- "GET" , "/personal-api-keys/all " )
704+ "GET" , "/admin/ personal-api-keys/" )
689705 if as_type == 'objects' :
690706 return [DSSPersonalApiKey (self , item ['id' ]) for item in resp ]
691707 else :
692708 return resp
693709
694- def create_personal_api_key_for_user (self , label = "" , description = "" , as_type = 'dict' , user = "" ):
695-
696710
697- def create_personal_api_key (self , label = "" , description = "" , as_type = 'dict' ):
711+ def create_personal_api_key_for_user (self , label = "" , description = "" , as_type = 'dict' , user = "" ):
698712 """
699- Create a Personal API key
713+ Create a Personal API key associated on behalf of a user
714+ Only admin can create a key for another user
700715 :param str label: the label of the new API key
701716 :param str description: the description of the new API key
702717 :param str as_type: 'object' or 'dict'
703- :param str user: the id of the user to impersonate (optional)
704- :returns: The new personal API key
718+ :param str user: the id of the user to impersonate
719+ :returns: The new personal API key associated with 'user'
705720 """
706721 resp = self ._perform_json (
707- "POST" , "/personal-api-keys/" , body = {"user" : user , "label" : label , "description" : description })
722+ "POST" , "/admin/ personal-api-keys/" , body = {"user" : user , "label" : label , "description" : description })
708723 if resp is None :
709724 raise Exception ('API key creation returned no data' )
710725 if resp .get ('messages' , {}).get ('error' , False ):
@@ -717,6 +732,7 @@ def create_personal_api_key(self, label="", description="", as_type='dict'):
717732 else :
718733 return resp
719734
735+
720736 ########################################################
721737 # Meanings
722738 ########################################################
0 commit comments