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,478 +0,0 @@
1
- # Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import logging
4
- import random
5
- import time
6
- from dataclasses import dataclass
7
- from datetime import timedelta
8
- from enum import Enum
9
- from typing import Any, Callable, Dict, List
10
-
11
- from ..errors import OperationFailed
12
- from ._internal import Wait, _enum, _from_dict
13
-
14
- _LOG = logging.getLogger('databricks.sdk')
15
-
16
- # all definitions in this file are in alphabetical order
17
-
18
-
19
- @dataclass
20
- class CancelCommand:
21
- cluster_id: str = None
22
- command_id: str = None
23
- context_id: str = None
24
-
25
- def as_dict(self) -> dict:
26
- body = {}
27
- if self.cluster_id: body['clusterId'] = self.cluster_id
28
- if self.command_id: body['commandId'] = self.command_id
29
- if self.context_id: body['contextId'] = self.context_id
30
- return body
31
-
32
- @classmethod
33
- def from_dict(cls, d: Dict[str, any]) -> 'CancelCommand':
34
- return cls(cluster_id=d.get('clusterId', None),
35
- command_id=d.get('commandId', None),
36
- context_id=d.get('contextId', None))
37
-
38
-
39
- @dataclass
40
- class Command:
41
- cluster_id: str = None
42
- command: str = None
43
- context_id: str = None
44
- language: 'Language' = None
45
-
46
- def as_dict(self) -> dict:
47
- body = {}
48
- if self.cluster_id: body['clusterId'] = self.cluster_id
49
- if self.command: body['command'] = self.command
50
- if self.context_id: body['contextId'] = self.context_id
51
- if self.language: body['language'] = self.language.value
52
- return body
53
-
54
- @classmethod
55
- def from_dict(cls, d: Dict[str, any]) -> 'Command':
56
- return cls(cluster_id=d.get('clusterId', None),
57
- command=d.get('command', None),
58
- context_id=d.get('contextId', None),
59
- language=_enum(d, 'language', Language))
60
-
61
-
62
- class CommandStatus(Enum):
63
-
64
- Cancelled = 'Cancelled'
65
- Cancelling = 'Cancelling'
66
- Error = 'Error'
67
- Finished = 'Finished'
68
- Queued = 'Queued'
69
- Running = 'Running'
70
-
71
-
72
- @dataclass
73
- class CommandStatusRequest:
74
- """Get command info"""
75
-
76
- cluster_id: str
77
- context_id: str
78
- command_id: str
79
-
80
-
81
- @dataclass
82
- class CommandStatusResponse:
83
- id: str = None
84
- results: 'Results' = None
85
- status: 'CommandStatus' = None
86
-
87
- def as_dict(self) -> dict:
88
- body = {}
89
- if self.id: body['id'] = self.id
90
- if self.results: body['results'] = self.results.as_dict()
91
- if self.status: body['status'] = self.status.value
92
- return body
93
-
94
- @classmethod
95
- def from_dict(cls, d: Dict[str, any]) -> 'CommandStatusResponse':
96
- return cls(id=d.get('id', None),
97
- results=_from_dict(d, 'results', Results),
98
- status=_enum(d, 'status', CommandStatus))
99
-
100
-
101
- class ContextStatus(Enum):
102
-
103
- Error = 'Error'
104
- Pending = 'Pending'
105
- Running = 'Running'
106
-
107
-
108
- @dataclass
109
- class ContextStatusRequest:
110
- """Get status"""
111
-
112
- cluster_id: str
113
- context_id: str
114
-
115
-
116
- @dataclass
117
- class ContextStatusResponse:
118
- id: str = None
119
- status: 'ContextStatus' = None
120
-
121
- def as_dict(self) -> dict:
122
- body = {}
123
- if self.id: body['id'] = self.id
124
- if self.status: body['status'] = self.status.value
125
- return body
126
-
127
- @classmethod
128
- def from_dict(cls, d: Dict[str, any]) -> 'ContextStatusResponse':
129
- return cls(id=d.get('id', None), status=_enum(d, 'status', ContextStatus))
130
-
131
-
132
- @dataclass
133
- class CreateContext:
134
- cluster_id: str = None
135
- language: 'Language' = None
136
-
137
- def as_dict(self) -> dict:
138
- body = {}
139
- if self.cluster_id: body['clusterId'] = self.cluster_id
140
- if self.language: body['language'] = self.language.value
141
- return body
142
-
143
- @classmethod
144
- def from_dict(cls, d: Dict[str, any]) -> 'CreateContext':
145
- return cls(cluster_id=d.get('clusterId', None), language=_enum(d, 'language', Language))
146
-
147
-
148
- @dataclass
149
- class Created:
150
- id: str = None
151
-
152
- def as_dict(self) -> dict:
153
- body = {}
154
- if self.id: body['id'] = self.id
155
- return body
156
-
157
- @classmethod
158
- def from_dict(cls, d: Dict[str, any]) -> 'Created':
159
- return cls(id=d.get('id', None))
160
-
161
-
162
- @dataclass
163
- class DestroyContext:
164
- cluster_id: str
165
- context_id: str
166
-
167
- def as_dict(self) -> dict:
168
- body = {}
169
- if self.cluster_id: body['clusterId'] = self.cluster_id
170
- if self.context_id: body['contextId'] = self.context_id
171
- return body
172
-
173
- @classmethod
174
- def from_dict(cls, d: Dict[str, any]) -> 'DestroyContext':
175
- return cls(cluster_id=d.get('clusterId', None), context_id=d.get('contextId', None))
176
-
177
-
178
- class Language(Enum):
179
-
180
- python = 'python'
181
- scala = 'scala'
182
- sql = 'sql'
183
-
184
-
185
- class ResultType(Enum):
186
-
187
- error = 'error'
188
- image = 'image'
189
- images = 'images'
190
- table = 'table'
191
- text = 'text'
192
-
193
-
194
- @dataclass
195
- class Results:
196
- cause: str = None
197
- data: Any = None
198
- file_name: str = None
199
- file_names: 'List[str]' = None
200
- is_json_schema: bool = None
201
- pos: int = None
202
- result_type: 'ResultType' = None
203
- schema: 'List[Dict[str,Any]]' = None
204
- summary: str = None
205
- truncated: bool = None
206
-
207
- def as_dict(self) -> dict:
208
- body = {}
209
- if self.cause: body['cause'] = self.cause
210
- if self.data: body['data'] = self.data
211
- if self.file_name: body['fileName'] = self.file_name
212
- if self.file_names: body['fileNames'] = [v for v in self.file_names]
213
- if self.is_json_schema: body['isJsonSchema'] = self.is_json_schema
214
- if self.pos: body['pos'] = self.pos
215
- if self.result_type: body['resultType'] = self.result_type.value
216
- if self.schema: body['schema'] = [v for v in self.schema]
217
- if self.summary: body['summary'] = self.summary
218
- if self.truncated: body['truncated'] = self.truncated
219
- return body
220
-
221
- @classmethod
222
- def from_dict(cls, d: Dict[str, any]) -> 'Results':
223
- return cls(cause=d.get('cause', None),
224
- data=d.get('data', None),
225
- file_name=d.get('fileName', None),
226
- file_names=d.get('fileNames', None),
227
- is_json_schema=d.get('isJsonSchema', None),
228
- pos=d.get('pos', None),
229
- result_type=_enum(d, 'resultType', ResultType),
230
- schema=d.get('schema', None),
231
- summary=d.get('summary', None),
232
- truncated=d.get('truncated', None))
233
-
234
-
235
- class CommandExecutionAPI:
236
- """This API allows execution of Python, Scala, SQL, or R commands on running Databricks Clusters."""
237
-
238
- def __init__(self, api_client):
239
- self._api = api_client
240
-
241
- def wait_command_status_command_execution_cancelled(
242
- self,
243
- cluster_id: str,
244
- command_id: str,
245
- context_id: str,
246
- timeout=timedelta(minutes=20),
247
- callback: Callable[[CommandStatusResponse], None] = None) -> CommandStatusResponse:
248
- deadline = time.time() + timeout.total_seconds()
249
- target_states = (CommandStatus.Cancelled, )
250
- failure_states = (CommandStatus.Error, )
251
- status_message = 'polling...'
252
- attempt = 1
253
- while time.time() < deadline:
254
- poll = self.command_status(cluster_id=cluster_id, command_id=command_id, context_id=context_id)
255
- status = poll.status
256
- status_message = f'current status: {status}'
257
- if poll.results:
258
- status_message = poll.results.cause
259
- if status in target_states:
260
- return poll
261
- if callback:
262
- callback(poll)
263
- if status in failure_states:
264
- msg = f'failed to reach Cancelled, got {status}: {status_message}'
265
- raise OperationFailed(msg)
266
- prefix = f"cluster_id={cluster_id}, command_id={command_id}, context_id={context_id}"
267
- sleep = attempt
268
- if sleep > 10:
269
- # sleep 10s max per attempt
270
- sleep = 10
271
- _LOG.debug(f'{prefix}: ({status}) {status_message} (sleeping ~{sleep}s)')
272
- time.sleep(sleep + random.random())
273
- attempt += 1
274
- raise TimeoutError(f'timed out after {timeout}: {status_message}')
275
-
276
- def wait_command_status_command_execution_finished_or_error(
277
- self,
278
- cluster_id: str,
279
- command_id: str,
280
- context_id: str,
281
- timeout=timedelta(minutes=20),
282
- callback: Callable[[CommandStatusResponse], None] = None) -> CommandStatusResponse:
283
- deadline = time.time() + timeout.total_seconds()
284
- target_states = (CommandStatus.Finished, CommandStatus.Error, )
285
- failure_states = (CommandStatus.Cancelled, CommandStatus.Cancelling, )
286
- status_message = 'polling...'
287
- attempt = 1
288
- while time.time() < deadline:
289
- poll = self.command_status(cluster_id=cluster_id, command_id=command_id, context_id=context_id)
290
- status = poll.status
291
- status_message = f'current status: {status}'
292
- if status in target_states:
293
- return poll
294
- if callback:
295
- callback(poll)
296
- if status in failure_states:
297
- msg = f'failed to reach Finished or Error, got {status}: {status_message}'
298
- raise OperationFailed(msg)
299
- prefix = f"cluster_id={cluster_id}, command_id={command_id}, context_id={context_id}"
300
- sleep = attempt
301
- if sleep > 10:
302
- # sleep 10s max per attempt
303
- sleep = 10
304
- _LOG.debug(f'{prefix}: ({status}) {status_message} (sleeping ~{sleep}s)')
305
- time.sleep(sleep + random.random())
306
- attempt += 1
307
- raise TimeoutError(f'timed out after {timeout}: {status_message}')
308
-
309
- def wait_context_status_command_execution_running(
310
- self,
311
- cluster_id: str,
312
- context_id: str,
313
- timeout=timedelta(minutes=20),
314
- callback: Callable[[ContextStatusResponse], None] = None) -> ContextStatusResponse:
315
- deadline = time.time() + timeout.total_seconds()
316
- target_states = (ContextStatus.Running, )
317
- failure_states = (ContextStatus.Error, )
318
- status_message = 'polling...'
319
- attempt = 1
320
- while time.time() < deadline:
321
- poll = self.context_status(cluster_id=cluster_id, context_id=context_id)
322
- status = poll.status
323
- status_message = f'current status: {status}'
324
- if status in target_states:
325
- return poll
326
- if callback:
327
- callback(poll)
328
- if status in failure_states:
329
- msg = f'failed to reach Running, got {status}: {status_message}'
330
- raise OperationFailed(msg)
331
- prefix = f"cluster_id={cluster_id}, context_id={context_id}"
332
- sleep = attempt
333
- if sleep > 10:
334
- # sleep 10s max per attempt
335
- sleep = 10
336
- _LOG.debug(f'{prefix}: ({status}) {status_message} (sleeping ~{sleep}s)')
337
- time.sleep(sleep + random.random())
338
- attempt += 1
339
- raise TimeoutError(f'timed out after {timeout}: {status_message}')
340
-
341
- def cancel(self,
342
- *,
343
- cluster_id: str = None,
344
- command_id: str = None,
345
- context_id: str = None,
346
- **kwargs) -> Wait[CommandStatusResponse]:
347
- """Cancel a command.
348
-
349
- Cancels a currently running command within an execution context.
350
-
351
- The command ID is obtained from a prior successful call to __execute__."""
352
- request = kwargs.get('request', None)
353
- if not request: # request is not given through keyed args
354
- request = CancelCommand(cluster_id=cluster_id, command_id=command_id, context_id=context_id)
355
- body = request.as_dict()
356
- self._api.do('POST', '/api/1.2/commands/cancel', body=body)
357
- return Wait(self.wait_command_status_command_execution_cancelled,
358
- cluster_id=request.cluster_id,
359
- command_id=request.command_id,
360
- context_id=request.context_id)
361
-
362
- def cancel_and_wait(self,
363
- *,
364
- cluster_id: str = None,
365
- command_id: str = None,
366
- context_id: str = None,
367
- timeout=timedelta(minutes=20)) -> CommandStatusResponse:
368
- return self.cancel(cluster_id=cluster_id, command_id=command_id,
369
- context_id=context_id).result(timeout=timeout)
370
-
371
- def command_status(self, cluster_id: str, context_id: str, command_id: str,
372
- **kwargs) -> CommandStatusResponse:
373
- """Get command info.
374
-
375
- Gets the status of and, if available, the results from a currently executing command.
376
-
377
- The command ID is obtained from a prior successful call to __execute__."""
378
- request = kwargs.get('request', None)
379
- if not request: # request is not given through keyed args
380
- request = CommandStatusRequest(cluster_id=cluster_id,
381
- command_id=command_id,
382
- context_id=context_id)
383
-
384
- query = {}
385
- if cluster_id: query['clusterId'] = request.cluster_id
386
- if command_id: query['commandId'] = request.command_id
387
- if context_id: query['contextId'] = request.context_id
388
-
389
- json = self._api.do('GET', '/api/1.2/commands/status', query=query)
390
- return CommandStatusResponse.from_dict(json)
391
-
392
- def context_status(self, cluster_id: str, context_id: str, **kwargs) -> ContextStatusResponse:
393
- """Get status.
394
-
395
- Gets the status for an execution context."""
396
- request = kwargs.get('request', None)
397
- if not request: # request is not given through keyed args
398
- request = ContextStatusRequest(cluster_id=cluster_id, context_id=context_id)
399
-
400
- query = {}
401
- if cluster_id: query['clusterId'] = request.cluster_id
402
- if context_id: query['contextId'] = request.context_id
403
-
404
- json = self._api.do('GET', '/api/1.2/contexts/status', query=query)
405
- return ContextStatusResponse.from_dict(json)
406
-
407
- def create(self,
408
- *,
409
- cluster_id: str = None,
410
- language: Language = None,
411
- **kwargs) -> Wait[ContextStatusResponse]:
412
- """Create an execution context.
413
-
414
- Creates an execution context for running cluster commands.
415
-
416
- If successful, this method returns the ID of the new execution context."""
417
- request = kwargs.get('request', None)
418
- if not request: # request is not given through keyed args
419
- request = CreateContext(cluster_id=cluster_id, language=language)
420
- body = request.as_dict()
421
- op_response = self._api.do('POST', '/api/1.2/contexts/create', body=body)
422
- return Wait(self.wait_context_status_command_execution_running,
423
- response=Created.from_dict(op_response),
424
- cluster_id=request.cluster_id,
425
- context_id=op_response['id'])
426
-
427
- def create_and_wait(self,
428
- *,
429
- cluster_id: str = None,
430
- language: Language = None,
431
- timeout=timedelta(minutes=20)) -> ContextStatusResponse:
432
- return self.create(cluster_id=cluster_id, language=language).result(timeout=timeout)
433
-
434
- def destroy(self, cluster_id: str, context_id: str, **kwargs):
435
- """Delete an execution context.
436
-
437
- Deletes an execution context."""
438
- request = kwargs.get('request', None)
439
- if not request: # request is not given through keyed args
440
- request = DestroyContext(cluster_id=cluster_id, context_id=context_id)
441
- body = request.as_dict()
442
- self._api.do('POST', '/api/1.2/contexts/destroy', body=body)
443
-
444
- def execute(self,
445
- *,
446
- cluster_id: str = None,
447
- command: str = None,
448
- context_id: str = None,
449
- language: Language = None,
450
- **kwargs) -> Wait[CommandStatusResponse]:
451
- """Run a command.
452
-
453
- Runs a cluster command in the given execution context, using the provided language.
454
-
455
- If successful, it returns an ID for tracking the status of the command's execution."""
456
- request = kwargs.get('request', None)
457
- if not request: # request is not given through keyed args
458
- request = Command(cluster_id=cluster_id,
459
- command=command,
460
- context_id=context_id,
461
- language=language)
462
- body = request.as_dict()
463
- op_response = self._api.do('POST', '/api/1.2/commands/execute', body=body)
464
- return Wait(self.wait_command_status_command_execution_finished_or_error,
465
- response=Created.from_dict(op_response),
466
- cluster_id=request.cluster_id,
467
- command_id=op_response['id'],
468
- context_id=request.context_id)
469
-
470
- def execute_and_wait(self,
471
- *,
472
- cluster_id: str = None,
473
- command: str = None,
474
- context_id: str = None,
475
- language: Language = None,
476
- timeout=timedelta(minutes=20)) -> CommandStatusResponse:
477
- return self.execute(cluster_id=cluster_id, command=command, context_id=context_id,
478
- language=language).result(timeout=timeout)
@@ -1,202 +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 _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 CreateCredentials:
16
- git_provider: str
17
- git_username: str = None
18
- personal_access_token: str = None
19
-
20
- def as_dict(self) -> dict:
21
- body = {}
22
- if self.git_provider: body['git_provider'] = self.git_provider
23
- if self.git_username: body['git_username'] = self.git_username
24
- if self.personal_access_token: body['personal_access_token'] = self.personal_access_token
25
- return body
26
-
27
- @classmethod
28
- def from_dict(cls, d: Dict[str, any]) -> 'CreateCredentials':
29
- return cls(git_provider=d.get('git_provider', None),
30
- git_username=d.get('git_username', None),
31
- personal_access_token=d.get('personal_access_token', None))
32
-
33
-
34
- @dataclass
35
- class CreateCredentialsResponse:
36
- credential_id: int = None
37
- git_provider: str = None
38
- git_username: str = None
39
-
40
- def as_dict(self) -> dict:
41
- body = {}
42
- if self.credential_id: body['credential_id'] = self.credential_id
43
- if self.git_provider: body['git_provider'] = self.git_provider
44
- if self.git_username: body['git_username'] = self.git_username
45
- return body
46
-
47
- @classmethod
48
- def from_dict(cls, d: Dict[str, any]) -> 'CreateCredentialsResponse':
49
- return cls(credential_id=d.get('credential_id', None),
50
- git_provider=d.get('git_provider', None),
51
- git_username=d.get('git_username', None))
52
-
53
-
54
- @dataclass
55
- class CredentialInfo:
56
- credential_id: int = None
57
- git_provider: str = None
58
- git_username: str = None
59
-
60
- def as_dict(self) -> dict:
61
- body = {}
62
- if self.credential_id: body['credential_id'] = self.credential_id
63
- if self.git_provider: body['git_provider'] = self.git_provider
64
- if self.git_username: body['git_username'] = self.git_username
65
- return body
66
-
67
- @classmethod
68
- def from_dict(cls, d: Dict[str, any]) -> 'CredentialInfo':
69
- return cls(credential_id=d.get('credential_id', None),
70
- git_provider=d.get('git_provider', None),
71
- git_username=d.get('git_username', None))
72
-
73
-
74
- @dataclass
75
- class Delete:
76
- """Delete a credential"""
77
-
78
- credential_id: int
79
-
80
-
81
- @dataclass
82
- class Get:
83
- """Get a credential entry"""
84
-
85
- credential_id: int
86
-
87
-
88
- @dataclass
89
- class GetCredentialsResponse:
90
- credentials: 'List[CredentialInfo]' = None
91
-
92
- def as_dict(self) -> dict:
93
- body = {}
94
- if self.credentials: body['credentials'] = [v.as_dict() for v in self.credentials]
95
- return body
96
-
97
- @classmethod
98
- def from_dict(cls, d: Dict[str, any]) -> 'GetCredentialsResponse':
99
- return cls(credentials=_repeated(d, 'credentials', CredentialInfo))
100
-
101
-
102
- @dataclass
103
- class UpdateCredentials:
104
- credential_id: int
105
- git_provider: str = None
106
- git_username: str = None
107
- personal_access_token: str = None
108
-
109
- def as_dict(self) -> dict:
110
- body = {}
111
- if self.credential_id: body['credential_id'] = self.credential_id
112
- if self.git_provider: body['git_provider'] = self.git_provider
113
- if self.git_username: body['git_username'] = self.git_username
114
- if self.personal_access_token: body['personal_access_token'] = self.personal_access_token
115
- return body
116
-
117
- @classmethod
118
- def from_dict(cls, d: Dict[str, any]) -> 'UpdateCredentials':
119
- return cls(credential_id=d.get('credential_id', None),
120
- git_provider=d.get('git_provider', None),
121
- git_username=d.get('git_username', None),
122
- personal_access_token=d.get('personal_access_token', None))
123
-
124
-
125
- class GitCredentialsAPI:
126
- """Registers personal access token for Databricks to do operations on behalf of the user.
127
-
128
- See [more info].
129
-
130
- [more info]: https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html"""
131
-
132
- def __init__(self, api_client):
133
- self._api = api_client
134
-
135
- def create(self,
136
- git_provider: str,
137
- *,
138
- git_username: str = None,
139
- personal_access_token: str = None,
140
- **kwargs) -> CreateCredentialsResponse:
141
- """Create a credential entry.
142
-
143
- Creates a Git credential entry for the user. Only one Git credential per user is supported, so any
144
- attempts to create credentials if an entry already exists will fail. Use the PATCH endpoint to update
145
- existing credentials, or the DELETE endpoint to delete existing credentials."""
146
- request = kwargs.get('request', None)
147
- if not request: # request is not given through keyed args
148
- request = CreateCredentials(git_provider=git_provider,
149
- git_username=git_username,
150
- personal_access_token=personal_access_token)
151
- body = request.as_dict()
152
-
153
- json = self._api.do('POST', '/api/2.0/git-credentials', body=body)
154
- return CreateCredentialsResponse.from_dict(json)
155
-
156
- def delete(self, credential_id: int, **kwargs):
157
- """Delete a credential.
158
-
159
- Deletes the specified Git credential."""
160
- request = kwargs.get('request', None)
161
- if not request: # request is not given through keyed args
162
- request = Delete(credential_id=credential_id)
163
-
164
- self._api.do('DELETE', f'/api/2.0/git-credentials/{request.credential_id}')
165
-
166
- def get(self, credential_id: int, **kwargs) -> CredentialInfo:
167
- """Get a credential entry.
168
-
169
- Gets the Git credential with the specified credential ID."""
170
- request = kwargs.get('request', None)
171
- if not request: # request is not given through keyed args
172
- request = Get(credential_id=credential_id)
173
-
174
- json = self._api.do('GET', f'/api/2.0/git-credentials/{request.credential_id}')
175
- return CredentialInfo.from_dict(json)
176
-
177
- def list(self) -> Iterator[CredentialInfo]:
178
- """Get Git credentials.
179
-
180
- Lists the calling user's Git credentials. One credential per user is supported."""
181
-
182
- json = self._api.do('GET', '/api/2.0/git-credentials')
183
- return [CredentialInfo.from_dict(v) for v in json.get('credentials', [])]
184
-
185
- def update(self,
186
- credential_id: int,
187
- *,
188
- git_provider: str = None,
189
- git_username: str = None,
190
- personal_access_token: str = None,
191
- **kwargs):
192
- """Update a credential.
193
-
194
- Updates the specified Git credential."""
195
- request = kwargs.get('request', None)
196
- if not request: # request is not given through keyed args
197
- request = UpdateCredentials(credential_id=credential_id,
198
- git_provider=git_provider,
199
- git_username=git_username,
200
- personal_access_token=personal_access_token)
201
- body = request.as_dict()
202
- self._api.do('PATCH', f'/api/2.0/git-credentials/{request.credential_id}', body=body)