databricks-sdk 0.0.7__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of databricks-sdk might be problematic. Click here for more details.

Files changed (41) hide show
  1. databricks/sdk/__init__.py +121 -104
  2. databricks/sdk/core.py +76 -16
  3. databricks/sdk/dbutils.py +18 -17
  4. databricks/sdk/mixins/compute.py +6 -6
  5. databricks/sdk/mixins/dbfs.py +6 -6
  6. databricks/sdk/oauth.py +28 -14
  7. databricks/sdk/service/{unitycatalog.py → catalog.py} +375 -1146
  8. databricks/sdk/service/{clusters.py → compute.py} +2176 -61
  9. databricks/sdk/service/{dbfs.py → files.py} +6 -6
  10. databricks/sdk/service/{scim.py → iam.py} +567 -27
  11. databricks/sdk/service/jobs.py +44 -34
  12. databricks/sdk/service/{mlflow.py → ml.py} +976 -1071
  13. databricks/sdk/service/oauth2.py +3 -3
  14. databricks/sdk/service/pipelines.py +46 -30
  15. databricks/sdk/service/{deployment.py → provisioning.py} +47 -29
  16. databricks/sdk/service/settings.py +849 -0
  17. databricks/sdk/service/sharing.py +1176 -0
  18. databricks/sdk/service/sql.py +15 -15
  19. databricks/sdk/service/workspace.py +917 -22
  20. databricks/sdk/version.py +1 -1
  21. {databricks_sdk-0.0.7.dist-info → databricks_sdk-0.1.1.dist-info}/METADATA +3 -1
  22. databricks_sdk-0.1.1.dist-info/RECORD +37 -0
  23. databricks/sdk/service/clusterpolicies.py +0 -399
  24. databricks/sdk/service/commands.py +0 -478
  25. databricks/sdk/service/gitcredentials.py +0 -202
  26. databricks/sdk/service/globalinitscripts.py +0 -262
  27. databricks/sdk/service/instancepools.py +0 -757
  28. databricks/sdk/service/ipaccesslists.py +0 -340
  29. databricks/sdk/service/libraries.py +0 -282
  30. databricks/sdk/service/permissions.py +0 -470
  31. databricks/sdk/service/repos.py +0 -250
  32. databricks/sdk/service/secrets.py +0 -472
  33. databricks/sdk/service/tokenmanagement.py +0 -182
  34. databricks/sdk/service/tokens.py +0 -137
  35. databricks/sdk/service/workspaceconf.py +0 -50
  36. databricks_sdk-0.0.7.dist-info/RECORD +0 -48
  37. /databricks/sdk/service/{endpoints.py → serving.py} +0 -0
  38. {databricks_sdk-0.0.7.dist-info → databricks_sdk-0.1.1.dist-info}/LICENSE +0 -0
  39. {databricks_sdk-0.0.7.dist-info → databricks_sdk-0.1.1.dist-info}/NOTICE +0 -0
  40. {databricks_sdk-0.0.7.dist-info → databricks_sdk-0.1.1.dist-info}/WHEEL +0 -0
  41. {databricks_sdk-0.0.7.dist-info → databricks_sdk-0.1.1.dist-info}/top_level.txt +0 -0
@@ -1,472 +0,0 @@
1
- # Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import logging
4
- from dataclasses import dataclass
5
- from enum import Enum
6
- from typing import Dict, Iterator, List
7
-
8
- from ._internal import _enum, _from_dict, _repeated
9
-
10
- _LOG = logging.getLogger('databricks.sdk')
11
-
12
- # all definitions in this file are in alphabetical order
13
-
14
-
15
- @dataclass
16
- class AclItem:
17
- principal: str
18
- permission: 'AclPermission'
19
-
20
- def as_dict(self) -> dict:
21
- body = {}
22
- if self.permission: body['permission'] = self.permission.value
23
- if self.principal: body['principal'] = self.principal
24
- return body
25
-
26
- @classmethod
27
- def from_dict(cls, d: Dict[str, any]) -> 'AclItem':
28
- return cls(permission=_enum(d, 'permission', AclPermission), principal=d.get('principal', None))
29
-
30
-
31
- class AclPermission(Enum):
32
-
33
- MANAGE = 'MANAGE'
34
- READ = 'READ'
35
- WRITE = 'WRITE'
36
-
37
-
38
- @dataclass
39
- class AzureKeyVaultSecretScopeMetadata:
40
- resource_id: str
41
- dns_name: str
42
-
43
- def as_dict(self) -> dict:
44
- body = {}
45
- if self.dns_name: body['dns_name'] = self.dns_name
46
- if self.resource_id: body['resource_id'] = self.resource_id
47
- return body
48
-
49
- @classmethod
50
- def from_dict(cls, d: Dict[str, any]) -> 'AzureKeyVaultSecretScopeMetadata':
51
- return cls(dns_name=d.get('dns_name', None), resource_id=d.get('resource_id', None))
52
-
53
-
54
- @dataclass
55
- class CreateScope:
56
- scope: str
57
- initial_manage_principal: str = None
58
- keyvault_metadata: 'AzureKeyVaultSecretScopeMetadata' = None
59
- scope_backend_type: 'ScopeBackendType' = None
60
-
61
- def as_dict(self) -> dict:
62
- body = {}
63
- if self.initial_manage_principal: body['initial_manage_principal'] = self.initial_manage_principal
64
- if self.keyvault_metadata: body['keyvault_metadata'] = self.keyvault_metadata.as_dict()
65
- if self.scope: body['scope'] = self.scope
66
- if self.scope_backend_type: body['scope_backend_type'] = self.scope_backend_type.value
67
- return body
68
-
69
- @classmethod
70
- def from_dict(cls, d: Dict[str, any]) -> 'CreateScope':
71
- return cls(initial_manage_principal=d.get('initial_manage_principal', None),
72
- keyvault_metadata=_from_dict(d, 'keyvault_metadata', AzureKeyVaultSecretScopeMetadata),
73
- scope=d.get('scope', None),
74
- scope_backend_type=_enum(d, 'scope_backend_type', ScopeBackendType))
75
-
76
-
77
- @dataclass
78
- class DeleteAcl:
79
- scope: str
80
- principal: str
81
-
82
- def as_dict(self) -> dict:
83
- body = {}
84
- if self.principal: body['principal'] = self.principal
85
- if self.scope: body['scope'] = self.scope
86
- return body
87
-
88
- @classmethod
89
- def from_dict(cls, d: Dict[str, any]) -> 'DeleteAcl':
90
- return cls(principal=d.get('principal', None), scope=d.get('scope', None))
91
-
92
-
93
- @dataclass
94
- class DeleteScope:
95
- scope: str
96
-
97
- def as_dict(self) -> dict:
98
- body = {}
99
- if self.scope: body['scope'] = self.scope
100
- return body
101
-
102
- @classmethod
103
- def from_dict(cls, d: Dict[str, any]) -> 'DeleteScope':
104
- return cls(scope=d.get('scope', None))
105
-
106
-
107
- @dataclass
108
- class DeleteSecret:
109
- scope: str
110
- key: str
111
-
112
- def as_dict(self) -> dict:
113
- body = {}
114
- if self.key: body['key'] = self.key
115
- if self.scope: body['scope'] = self.scope
116
- return body
117
-
118
- @classmethod
119
- def from_dict(cls, d: Dict[str, any]) -> 'DeleteSecret':
120
- return cls(key=d.get('key', None), scope=d.get('scope', None))
121
-
122
-
123
- @dataclass
124
- class GetAcl:
125
- """Get secret ACL details"""
126
-
127
- scope: str
128
- principal: str
129
-
130
-
131
- @dataclass
132
- class ListAcls:
133
- """Lists ACLs"""
134
-
135
- scope: str
136
-
137
-
138
- @dataclass
139
- class ListAclsResponse:
140
- items: 'List[AclItem]' = None
141
-
142
- def as_dict(self) -> dict:
143
- body = {}
144
- if self.items: body['items'] = [v.as_dict() for v in self.items]
145
- return body
146
-
147
- @classmethod
148
- def from_dict(cls, d: Dict[str, any]) -> 'ListAclsResponse':
149
- return cls(items=_repeated(d, 'items', AclItem))
150
-
151
-
152
- @dataclass
153
- class ListScopesResponse:
154
- scopes: 'List[SecretScope]' = None
155
-
156
- def as_dict(self) -> dict:
157
- body = {}
158
- if self.scopes: body['scopes'] = [v.as_dict() for v in self.scopes]
159
- return body
160
-
161
- @classmethod
162
- def from_dict(cls, d: Dict[str, any]) -> 'ListScopesResponse':
163
- return cls(scopes=_repeated(d, 'scopes', SecretScope))
164
-
165
-
166
- @dataclass
167
- class ListSecrets:
168
- """List secret keys"""
169
-
170
- scope: str
171
-
172
-
173
- @dataclass
174
- class ListSecretsResponse:
175
- secrets: 'List[SecretMetadata]' = None
176
-
177
- def as_dict(self) -> dict:
178
- body = {}
179
- if self.secrets: body['secrets'] = [v.as_dict() for v in self.secrets]
180
- return body
181
-
182
- @classmethod
183
- def from_dict(cls, d: Dict[str, any]) -> 'ListSecretsResponse':
184
- return cls(secrets=_repeated(d, 'secrets', SecretMetadata))
185
-
186
-
187
- @dataclass
188
- class PutAcl:
189
- scope: str
190
- principal: str
191
- permission: 'AclPermission'
192
-
193
- def as_dict(self) -> dict:
194
- body = {}
195
- if self.permission: body['permission'] = self.permission.value
196
- if self.principal: body['principal'] = self.principal
197
- if self.scope: body['scope'] = self.scope
198
- return body
199
-
200
- @classmethod
201
- def from_dict(cls, d: Dict[str, any]) -> 'PutAcl':
202
- return cls(permission=_enum(d, 'permission', AclPermission),
203
- principal=d.get('principal', None),
204
- scope=d.get('scope', None))
205
-
206
-
207
- @dataclass
208
- class PutSecret:
209
- scope: str
210
- key: str
211
- bytes_value: str = None
212
- string_value: str = None
213
-
214
- def as_dict(self) -> dict:
215
- body = {}
216
- if self.bytes_value: body['bytes_value'] = self.bytes_value
217
- if self.key: body['key'] = self.key
218
- if self.scope: body['scope'] = self.scope
219
- if self.string_value: body['string_value'] = self.string_value
220
- return body
221
-
222
- @classmethod
223
- def from_dict(cls, d: Dict[str, any]) -> 'PutSecret':
224
- return cls(bytes_value=d.get('bytes_value', None),
225
- key=d.get('key', None),
226
- scope=d.get('scope', None),
227
- string_value=d.get('string_value', None))
228
-
229
-
230
- class ScopeBackendType(Enum):
231
-
232
- AZURE_KEYVAULT = 'AZURE_KEYVAULT'
233
- DATABRICKS = 'DATABRICKS'
234
-
235
-
236
- @dataclass
237
- class SecretMetadata:
238
- key: str = None
239
- last_updated_timestamp: int = None
240
-
241
- def as_dict(self) -> dict:
242
- body = {}
243
- if self.key: body['key'] = self.key
244
- if self.last_updated_timestamp: body['last_updated_timestamp'] = self.last_updated_timestamp
245
- return body
246
-
247
- @classmethod
248
- def from_dict(cls, d: Dict[str, any]) -> 'SecretMetadata':
249
- return cls(key=d.get('key', None), last_updated_timestamp=d.get('last_updated_timestamp', None))
250
-
251
-
252
- @dataclass
253
- class SecretScope:
254
- backend_type: 'ScopeBackendType' = None
255
- keyvault_metadata: 'AzureKeyVaultSecretScopeMetadata' = None
256
- name: str = None
257
-
258
- def as_dict(self) -> dict:
259
- body = {}
260
- if self.backend_type: body['backend_type'] = self.backend_type.value
261
- if self.keyvault_metadata: body['keyvault_metadata'] = self.keyvault_metadata.as_dict()
262
- if self.name: body['name'] = self.name
263
- return body
264
-
265
- @classmethod
266
- def from_dict(cls, d: Dict[str, any]) -> 'SecretScope':
267
- return cls(backend_type=_enum(d, 'backend_type', ScopeBackendType),
268
- keyvault_metadata=_from_dict(d, 'keyvault_metadata', AzureKeyVaultSecretScopeMetadata),
269
- name=d.get('name', None))
270
-
271
-
272
- class SecretsAPI:
273
- """The Secrets API allows you to manage secrets, secret scopes, and access permissions.
274
-
275
- Sometimes accessing data requires that you authenticate to external data sources through JDBC. Instead of
276
- directly entering your credentials into a notebook, use Databricks secrets to store your credentials and
277
- reference them in notebooks and jobs.
278
-
279
- Administrators, secret creators, and users granted permission can read Databricks secrets. While
280
- Databricks makes an effort to redact secret values that might be displayed in notebooks, it is not
281
- possible to prevent such users from reading secrets."""
282
-
283
- def __init__(self, api_client):
284
- self._api = api_client
285
-
286
- def create_scope(self,
287
- scope: str,
288
- *,
289
- initial_manage_principal: str = None,
290
- keyvault_metadata: AzureKeyVaultSecretScopeMetadata = None,
291
- scope_backend_type: ScopeBackendType = None,
292
- **kwargs):
293
- """Create a new secret scope.
294
-
295
- The scope name must consist of alphanumeric characters, dashes, underscores, and periods, and may not
296
- exceed 128 characters. The maximum number of scopes in a workspace is 100."""
297
- request = kwargs.get('request', None)
298
- if not request: # request is not given through keyed args
299
- request = CreateScope(initial_manage_principal=initial_manage_principal,
300
- keyvault_metadata=keyvault_metadata,
301
- scope=scope,
302
- scope_backend_type=scope_backend_type)
303
- body = request.as_dict()
304
- self._api.do('POST', '/api/2.0/secrets/scopes/create', body=body)
305
-
306
- def delete_acl(self, scope: str, principal: str, **kwargs):
307
- """Delete an ACL.
308
-
309
- Deletes the given ACL on the given scope.
310
-
311
- Users must have the `MANAGE` permission to invoke this API. Throws `RESOURCE_DOES_NOT_EXIST` if no
312
- such secret scope, principal, or ACL exists. Throws `PERMISSION_DENIED` if the user does not have
313
- permission to make this API call."""
314
- request = kwargs.get('request', None)
315
- if not request: # request is not given through keyed args
316
- request = DeleteAcl(principal=principal, scope=scope)
317
- body = request.as_dict()
318
- self._api.do('POST', '/api/2.0/secrets/acls/delete', body=body)
319
-
320
- def delete_scope(self, scope: str, **kwargs):
321
- """Delete a secret scope.
322
-
323
- Deletes a secret scope.
324
-
325
- Throws `RESOURCE_DOES_NOT_EXIST` if the scope does not exist. Throws `PERMISSION_DENIED` if the user
326
- does not have permission to make this API call."""
327
- request = kwargs.get('request', None)
328
- if not request: # request is not given through keyed args
329
- request = DeleteScope(scope=scope)
330
- body = request.as_dict()
331
- self._api.do('POST', '/api/2.0/secrets/scopes/delete', body=body)
332
-
333
- def delete_secret(self, scope: str, key: str, **kwargs):
334
- """Delete a secret.
335
-
336
- Deletes the secret stored in this secret scope. You must have `WRITE` or `MANAGE` permission on the
337
- secret scope.
338
-
339
- Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope or secret exists. Throws `PERMISSION_DENIED`
340
- if the user does not have permission to make this API call."""
341
- request = kwargs.get('request', None)
342
- if not request: # request is not given through keyed args
343
- request = DeleteSecret(key=key, scope=scope)
344
- body = request.as_dict()
345
- self._api.do('POST', '/api/2.0/secrets/delete', body=body)
346
-
347
- def get_acl(self, scope: str, principal: str, **kwargs) -> AclItem:
348
- """Get secret ACL details.
349
-
350
- Gets the details about the given ACL, such as the group and permission. Users must have the `MANAGE`
351
- permission to invoke this API.
352
-
353
- Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws `PERMISSION_DENIED` if the
354
- user does not have permission to make this API call."""
355
- request = kwargs.get('request', None)
356
- if not request: # request is not given through keyed args
357
- request = GetAcl(principal=principal, scope=scope)
358
-
359
- query = {}
360
- if principal: query['principal'] = request.principal
361
- if scope: query['scope'] = request.scope
362
-
363
- json = self._api.do('GET', '/api/2.0/secrets/acls/get', query=query)
364
- return AclItem.from_dict(json)
365
-
366
- def list_acls(self, scope: str, **kwargs) -> Iterator[AclItem]:
367
- """Lists ACLs.
368
-
369
- List the ACLs for a given secret scope. Users must have the `MANAGE` permission to invoke this API.
370
-
371
- Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws `PERMISSION_DENIED` if the
372
- user does not have permission to make this API call."""
373
- request = kwargs.get('request', None)
374
- if not request: # request is not given through keyed args
375
- request = ListAcls(scope=scope)
376
-
377
- query = {}
378
- if scope: query['scope'] = request.scope
379
-
380
- json = self._api.do('GET', '/api/2.0/secrets/acls/list', query=query)
381
- return [AclItem.from_dict(v) for v in json.get('items', [])]
382
-
383
- def list_scopes(self) -> Iterator[SecretScope]:
384
- """List all scopes.
385
-
386
- Lists all secret scopes available in the workspace.
387
-
388
- Throws `PERMISSION_DENIED` if the user does not have permission to make this API call."""
389
-
390
- json = self._api.do('GET', '/api/2.0/secrets/scopes/list')
391
- return [SecretScope.from_dict(v) for v in json.get('scopes', [])]
392
-
393
- def list_secrets(self, scope: str, **kwargs) -> Iterator[SecretMetadata]:
394
- """List secret keys.
395
-
396
- Lists the secret keys that are stored at this scope. This is a metadata-only operation; secret data
397
- cannot be retrieved using this API. Users need the READ permission to make this call.
398
-
399
- The lastUpdatedTimestamp returned is in milliseconds since epoch. Throws `RESOURCE_DOES_NOT_EXIST` if
400
- no such secret scope exists. Throws `PERMISSION_DENIED` if the user does not have permission to make
401
- this API call."""
402
- request = kwargs.get('request', None)
403
- if not request: # request is not given through keyed args
404
- request = ListSecrets(scope=scope)
405
-
406
- query = {}
407
- if scope: query['scope'] = request.scope
408
-
409
- json = self._api.do('GET', '/api/2.0/secrets/list', query=query)
410
- return [SecretMetadata.from_dict(v) for v in json.get('secrets', [])]
411
-
412
- def put_acl(self, scope: str, principal: str, permission: AclPermission, **kwargs):
413
- """Create/update an ACL.
414
-
415
- Creates or overwrites the Access Control List (ACL) associated with the given principal (user or
416
- group) on the specified scope point.
417
-
418
- In general, a user or group will use the most powerful permission available to them, and permissions
419
- are ordered as follows:
420
-
421
- * `MANAGE` - Allowed to change ACLs, and read and write to this secret scope. * `WRITE` - Allowed to
422
- read and write to this secret scope. * `READ` - Allowed to read this secret scope and list what
423
- secrets are available.
424
-
425
- Note that in general, secret values can only be read from within a command on a cluster (for example,
426
- through a notebook). There is no API to read the actual secret value material outside of a cluster.
427
- However, the user's permission will be applied based on who is executing the command, and they must
428
- have at least READ permission.
429
-
430
- Users must have the `MANAGE` permission to invoke this API.
431
-
432
- The principal is a user or group name corresponding to an existing Databricks principal to be granted
433
- or revoked access.
434
-
435
- Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws `RESOURCE_ALREADY_EXISTS` if a
436
- permission for the principal already exists. Throws `INVALID_PARAMETER_VALUE` if the permission is
437
- invalid. Throws `PERMISSION_DENIED` if the user does not have permission to make this API call."""
438
- request = kwargs.get('request', None)
439
- if not request: # request is not given through keyed args
440
- request = PutAcl(permission=permission, principal=principal, scope=scope)
441
- body = request.as_dict()
442
- self._api.do('POST', '/api/2.0/secrets/acls/put', body=body)
443
-
444
- def put_secret(self,
445
- scope: str,
446
- key: str,
447
- *,
448
- bytes_value: str = None,
449
- string_value: str = None,
450
- **kwargs):
451
- """Add a secret.
452
-
453
- Inserts a secret under the provided scope with the given name. If a secret already exists with the
454
- same name, this command overwrites the existing secret's value. The server encrypts the secret using
455
- the secret scope's encryption settings before storing it.
456
-
457
- You must have `WRITE` or `MANAGE` permission on the secret scope. The secret key must consist of
458
- alphanumeric characters, dashes, underscores, and periods, and cannot exceed 128 characters. The
459
- maximum allowed secret value size is 128 KB. The maximum number of secrets in a given scope is 1000.
460
-
461
- The input fields "string_value" or "bytes_value" specify the type of the secret, which will determine
462
- the value returned when the secret value is requested. Exactly one must be specified.
463
-
464
- Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws `RESOURCE_LIMIT_EXCEEDED` if
465
- maximum number of secrets in scope is exceeded. Throws `INVALID_PARAMETER_VALUE` if the key name or
466
- value length is invalid. Throws `PERMISSION_DENIED` if the user does not have permission to make this
467
- API call."""
468
- request = kwargs.get('request', None)
469
- if not request: # request is not given through keyed args
470
- request = PutSecret(bytes_value=bytes_value, key=key, scope=scope, string_value=string_value)
471
- body = request.as_dict()
472
- self._api.do('POST', '/api/2.0/secrets/put', body=body)
@@ -1,182 +0,0 @@
1
- # Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import logging
4
- from dataclasses import dataclass
5
- from typing import Dict, Iterator, List
6
-
7
- from ._internal import _from_dict, _repeated
8
-
9
- _LOG = logging.getLogger('databricks.sdk')
10
-
11
- # all definitions in this file are in alphabetical order
12
-
13
-
14
- @dataclass
15
- class CreateOboTokenRequest:
16
- application_id: str
17
- lifetime_seconds: int
18
- comment: str = None
19
-
20
- def as_dict(self) -> dict:
21
- body = {}
22
- if self.application_id: body['application_id'] = self.application_id
23
- if self.comment: body['comment'] = self.comment
24
- if self.lifetime_seconds: body['lifetime_seconds'] = self.lifetime_seconds
25
- return body
26
-
27
- @classmethod
28
- def from_dict(cls, d: Dict[str, any]) -> 'CreateOboTokenRequest':
29
- return cls(application_id=d.get('application_id', None),
30
- comment=d.get('comment', None),
31
- lifetime_seconds=d.get('lifetime_seconds', None))
32
-
33
-
34
- @dataclass
35
- class CreateOboTokenResponse:
36
- token_info: 'TokenInfo' = None
37
- token_value: str = None
38
-
39
- def as_dict(self) -> dict:
40
- body = {}
41
- if self.token_info: body['token_info'] = self.token_info.as_dict()
42
- if self.token_value: body['token_value'] = self.token_value
43
- return body
44
-
45
- @classmethod
46
- def from_dict(cls, d: Dict[str, any]) -> 'CreateOboTokenResponse':
47
- return cls(token_info=_from_dict(d, 'token_info', TokenInfo), token_value=d.get('token_value', None))
48
-
49
-
50
- @dataclass
51
- class Delete:
52
- """Delete a token"""
53
-
54
- token_id: str
55
-
56
-
57
- @dataclass
58
- class Get:
59
- """Get token info"""
60
-
61
- token_id: str
62
-
63
-
64
- @dataclass
65
- class ListRequest:
66
- """List all tokens"""
67
-
68
- created_by_id: str = None
69
- created_by_username: str = None
70
-
71
-
72
- @dataclass
73
- class ListTokensResponse:
74
- token_infos: 'List[TokenInfo]' = None
75
-
76
- def as_dict(self) -> dict:
77
- body = {}
78
- if self.token_infos: body['token_infos'] = [v.as_dict() for v in self.token_infos]
79
- return body
80
-
81
- @classmethod
82
- def from_dict(cls, d: Dict[str, any]) -> 'ListTokensResponse':
83
- return cls(token_infos=_repeated(d, 'token_infos', TokenInfo))
84
-
85
-
86
- @dataclass
87
- class TokenInfo:
88
- comment: str = None
89
- created_by_id: int = None
90
- created_by_username: str = None
91
- creation_time: int = None
92
- expiry_time: int = None
93
- owner_id: int = None
94
- token_id: str = None
95
-
96
- def as_dict(self) -> dict:
97
- body = {}
98
- if self.comment: body['comment'] = self.comment
99
- if self.created_by_id: body['created_by_id'] = self.created_by_id
100
- if self.created_by_username: body['created_by_username'] = self.created_by_username
101
- if self.creation_time: body['creation_time'] = self.creation_time
102
- if self.expiry_time: body['expiry_time'] = self.expiry_time
103
- if self.owner_id: body['owner_id'] = self.owner_id
104
- if self.token_id: body['token_id'] = self.token_id
105
- return body
106
-
107
- @classmethod
108
- def from_dict(cls, d: Dict[str, any]) -> 'TokenInfo':
109
- return cls(comment=d.get('comment', None),
110
- created_by_id=d.get('created_by_id', None),
111
- created_by_username=d.get('created_by_username', None),
112
- creation_time=d.get('creation_time', None),
113
- expiry_time=d.get('expiry_time', None),
114
- owner_id=d.get('owner_id', None),
115
- token_id=d.get('token_id', None))
116
-
117
-
118
- class TokenManagementAPI:
119
- """Enables administrators to get all tokens and delete tokens for other users. Admins can either get every
120
- token, get a specific token by ID, or get all tokens for a particular user."""
121
-
122
- def __init__(self, api_client):
123
- self._api = api_client
124
-
125
- def create_obo_token(self,
126
- application_id: str,
127
- lifetime_seconds: int,
128
- *,
129
- comment: str = None,
130
- **kwargs) -> CreateOboTokenResponse:
131
- """Create on-behalf token.
132
-
133
- Creates a token on behalf of a service principal."""
134
- request = kwargs.get('request', None)
135
- if not request: # request is not given through keyed args
136
- request = CreateOboTokenRequest(application_id=application_id,
137
- comment=comment,
138
- lifetime_seconds=lifetime_seconds)
139
- body = request.as_dict()
140
-
141
- json = self._api.do('POST', '/api/2.0/token-management/on-behalf-of/tokens', body=body)
142
- return CreateOboTokenResponse.from_dict(json)
143
-
144
- def delete(self, token_id: str, **kwargs):
145
- """Delete a token.
146
-
147
- Deletes a token, specified by its ID."""
148
- request = kwargs.get('request', None)
149
- if not request: # request is not given through keyed args
150
- request = Delete(token_id=token_id)
151
-
152
- self._api.do('DELETE', f'/api/2.0/token-management/tokens/{request.token_id}')
153
-
154
- def get(self, token_id: str, **kwargs) -> TokenInfo:
155
- """Get token info.
156
-
157
- Gets information about a token, specified by its ID."""
158
- request = kwargs.get('request', None)
159
- if not request: # request is not given through keyed args
160
- request = Get(token_id=token_id)
161
-
162
- json = self._api.do('GET', f'/api/2.0/token-management/tokens/{request.token_id}')
163
- return TokenInfo.from_dict(json)
164
-
165
- def list(self,
166
- *,
167
- created_by_id: str = None,
168
- created_by_username: str = None,
169
- **kwargs) -> Iterator[TokenInfo]:
170
- """List all tokens.
171
-
172
- Lists all tokens associated with the specified workspace or user."""
173
- request = kwargs.get('request', None)
174
- if not request: # request is not given through keyed args
175
- request = ListRequest(created_by_id=created_by_id, created_by_username=created_by_username)
176
-
177
- query = {}
178
- if created_by_id: query['created_by_id'] = request.created_by_id
179
- if created_by_username: query['created_by_username'] = request.created_by_username
180
-
181
- json = self._api.do('GET', '/api/2.0/token-management/tokens', query=query)
182
- return [TokenInfo.from_dict(v) for v in json.get('token_infos', [])]