|
10 | 10 | from .dss.project import DSSProject |
11 | 11 | from .dss.app import DSSApp |
12 | 12 | from .dss.plugin import DSSPlugin |
13 | | -from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster |
| 13 | +from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSPersonalApiKey |
14 | 14 | from .dss.meaning import DSSMeaning |
15 | 15 | from .dss.sqlquery import DSSSQLQuery |
16 | 16 | from .dss.discussion import DSSObjectDiscussions |
@@ -629,6 +629,48 @@ def create_global_api_key(self, label=None, description=None, admin=False): |
629 | 629 | key = resp.get('key', '') |
630 | 630 | return DSSGlobalApiKey(self, key) |
631 | 631 |
|
| 632 | + ######################################################## |
| 633 | + # Personal API Keys |
| 634 | + ######################################################## |
| 635 | + |
| 636 | + def list_personal_api_keys(self): |
| 637 | + """ |
| 638 | + List all personal API keys: |
| 639 | + - not admin: only the keys belonging to the owner of the key |
| 640 | + - admin: All the personal keys |
| 641 | +
|
| 642 | + :returns: All personal API keys, as a list of dicts |
| 643 | + """ |
| 644 | + return self._perform_json( |
| 645 | + "GET", "/personal-api-keys/") |
| 646 | + |
| 647 | + def get_personal_api_key(self, key): |
| 648 | + """ |
| 649 | + Get a specific API key from the user doing the request |
| 650 | +
|
| 651 | + :param str key: the secret key of the desired API key |
| 652 | + :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle |
| 653 | + """ |
| 654 | + return DSSPersonalApiKey(self, key) |
| 655 | + |
| 656 | + def create_personal_api_key(self, label=""): |
| 657 | + """ |
| 658 | + Create a Personal API key corresponding to the user doing the request, and return a handle to interact with it |
| 659 | +
|
| 660 | + :param: label string (optional): Label for the new API key |
| 661 | + :returns: A :class:`dataikuapi.dss.admin.DSSPersonalApiKey` API key handle |
| 662 | + """ |
| 663 | + resp = self._perform_json( |
| 664 | + "POST", "/personal-api-keys/", body={"label": label}) |
| 665 | + if resp is None: |
| 666 | + raise Exception('API key creation returned no data') |
| 667 | + if resp.get('messages', {}).get('error', False): |
| 668 | + raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 669 | + if not resp.get('id', False): |
| 670 | + raise Exception('API key creation returned no key') |
| 671 | + key = resp.get('key', '') |
| 672 | + return DSSPersonalApiKey(self, key) |
| 673 | + |
632 | 674 | ######################################################## |
633 | 675 | # Meanings |
634 | 676 | ######################################################## |
@@ -961,19 +1003,6 @@ def get_ticket_from_browser_headers(self, headers_dict): |
961 | 1003 | """ |
962 | 1004 | return self._perform_json("POST", "/auth/ticket-from-browser-headers", body=headers_dict) |
963 | 1005 |
|
964 | | - def create_personal_api_key(self, label): |
965 | | - """ |
966 | | - Creates a personal API key corresponding to the user doing the request. |
967 | | - This can be called if the DSSClient was initialized with an internal |
968 | | - ticket or with a personal API key |
969 | | -
|
970 | | - :param: label string: Label for the new API key |
971 | | - :returns: a dict of the new API key, containing at least "secret", i.e. the actual secret API key |
972 | | - :rtype: dict |
973 | | - """ |
974 | | - return self._perform_json("POST", "/auth/personal-api-keys", |
975 | | - params={"label": label}) |
976 | | - |
977 | 1006 | ######################################################## |
978 | 1007 | # Container execution |
979 | 1008 | ######################################################## |
|
0 commit comments