|
6 | 6 | from dss.future import DSSFuture |
7 | 7 | from dss.project import DSSProject |
8 | 8 | from dss.plugin import DSSPlugin |
9 | | -from dss.admin import DSSUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv |
| 9 | +from dss.admin import DSSUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey |
10 | 10 | from dss.meaning import DSSMeaning |
11 | 11 | from dss.sqlquery import DSSSQLQuery |
12 | 12 | from dss.notebook import DSSNotebook |
@@ -412,6 +412,65 @@ def create_code_env(self, env_lang, env_name, deployment_mode, params=None): |
412 | 412 | raise Exception('Env creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
413 | 413 | return DSSCodeEnv(self, env_lang, env_name) |
414 | 414 |
|
| 415 | + ######################################################## |
| 416 | + # Global API Keys |
| 417 | + ######################################################## |
| 418 | + |
| 419 | + def list_global_api_keys(self): |
| 420 | + """ |
| 421 | + List all global API keys set up on the DSS instance |
| 422 | +
|
| 423 | + Note: this call requires an API key with admin rights |
| 424 | +
|
| 425 | + Returns: |
| 426 | + All global API keys, as a list |
| 427 | + """ |
| 428 | + return self._perform_json( |
| 429 | + "GET", "/admin/globalAPIKeys/") |
| 430 | + |
| 431 | + def get_global_api_key(self, key): |
| 432 | + """ |
| 433 | + Get a handle to interact with a specific Global API key |
| 434 | +
|
| 435 | + Args: |
| 436 | + key: the secret key of the desired API key |
| 437 | +
|
| 438 | + Returns: |
| 439 | + A :class:`dataikuapi.dss.admin.DSSGlobalApiKey` API key handle |
| 440 | + """ |
| 441 | + return DSSGlobalApiKey(self, key) |
| 442 | + |
| 443 | + def create_global_api_key(self, label=None, description=None, admin=False): |
| 444 | + """ |
| 445 | + Create a Global API key, and return a handle to interact with it |
| 446 | +
|
| 447 | + Note: this call requires an API key with admin rights |
| 448 | +
|
| 449 | + Args: |
| 450 | + label: the label of the new API key |
| 451 | + description: the description of the new API key |
| 452 | + admin: has the new API key admin rights (True or False) |
| 453 | +
|
| 454 | + Returns: |
| 455 | + A :class:`dataikuapi.dss.admin.DSSGlobalApiKey` API key handle |
| 456 | + """ |
| 457 | + resp = self._perform_json( |
| 458 | + "POST", "/admin/globalAPIKeys/", body={ |
| 459 | + "label" : label, |
| 460 | + "description" : description, |
| 461 | + "globalPermissions": { |
| 462 | + "admin": admin |
| 463 | + } |
| 464 | + }) |
| 465 | + if resp is None: |
| 466 | + raise Exception('API key creation returned no data') |
| 467 | + if resp.get('messages', {}).get('error', False): |
| 468 | + raise Exception('API key creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 469 | + if not resp.get('id', False): |
| 470 | + raise Exception('API key creation returned no key') |
| 471 | + key = resp.get('key', '') |
| 472 | + return DSSGlobalApiKey(self, key) |
| 473 | + |
415 | 474 | ######################################################## |
416 | 475 | # Meanings |
417 | 476 | ######################################################## |
|
0 commit comments