-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathadmin_blueprint_designer.py
460 lines (361 loc) · 18.5 KB
/
admin_blueprint_designer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
class GovernAdminBlueprintDesigner(object):
"""
Handle to interact with the blueprint designer
Do not create this directly, use :meth:`~dataikuapi.govern_client.GovernClient.get_blueprint_designer`
"""
def __init__(self, client):
self.client = client
def list_blueprints(self):
"""
List blueprints
:return: the list of blueprints
:rtype: list of :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintListItem`
"""
blueprints = self.client._perform_json("GET", "/admin/blueprints")
return [GovernAdminBlueprintListItem(self.client, blueprint) for blueprint in blueprints]
def get_blueprint(self, blueprint_id):
"""
Get a specific blueprint.
:param str blueprint_id: the ID of the blueprint
:return: a blueprint object
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint`
"""
return GovernAdminBlueprint(self.client, blueprint_id)
def create_blueprint(self, new_identifier, blueprint):
"""
Create a new blueprint and returns a handle to interact with it.
:param str new_identifier: the new identifier for the blueprint. Allowed characters are letters, digits, hyphen, and underscore.
:param dict blueprint: the blueprint definition
:return: The handle for the newly created blueprint
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint`
"""
result = self.client._perform_json("POST", "/admin/blueprints", params={"newIdentifier": new_identifier}, body=blueprint)
return GovernAdminBlueprint(self.client, result["blueprint"]["id"])
class GovernAdminBlueprintListItem(object):
"""
An item in a list of blueprints.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintDesigner.list_blueprints`
"""
def __init__(self, client, data):
self.client = client
self._data = data
def get_raw(self):
"""
Get the raw content of the blueprint list item
:return: the raw content of the blueprint list item as a dict
:rtype: dict
"""
return self._data
def to_blueprint(self):
"""
Gets the :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint` corresponding to this blueprint object
:return: the blueprint object
:rtype: a :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint`
"""
return GovernAdminBlueprint(self.client, self._data["blueprint"]["id"])
class GovernAdminBlueprint(object):
"""
A handle to interact with a blueprint as an admin on the Govern instance.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintDesigner.get_blueprint`
"""
def __init__(self, client, blueprint_id):
self.client = client
self.blueprint_id = blueprint_id
def get_definition(self):
"""
Get the definition of the blueprint as an object. To modify the definition, call :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintDefinition.save`
on the returned object.
:return: The blueprint definition as an object.
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintDefinition`
"""
blueprint = self.client._perform_json("GET", "/admin/blueprint/%s" % self.blueprint_id)
return GovernAdminBlueprintDefinition(self.client, self.blueprint_id, blueprint["blueprint"])
def list_versions(self):
"""
List versions of this blueprint.
:return: The list of the versions of the blueprint
:rtype: list of :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersionListItem`
"""
versions = self.client._perform_json("GET", "/admin/blueprint/%s/versions" % self.blueprint_id)
return [GovernAdminBlueprintVersionListItem(self.client, self.blueprint_id, version) for version in versions]
def create_version(self, new_identifier, name=None, origin_version_id=None):
"""
Create a new blueprint version and returns a handle to interact with it.
:param str new_identifier: The new identifier of the blueprint version. Allowed characters are letters, digits, hyphen, and underscore.
:param str name: (Optional) The name of the blueprint version.
:param str origin_version_id: (Optional) The blueprint version ID of the origin version ID if there is one.
:return: The handle of the newly created blueprint
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion`
"""
params = {"newIdentifier": new_identifier}
if name is not None:
params["name"] = name
if origin_version_id is not None:
params["originVersionId"] = origin_version_id
version = self.client._perform_json("POST", "/admin/blueprint/%s/versions" % self.blueprint_id, params=params)
return GovernAdminBlueprintVersion(self.client, self.blueprint_id, version["blueprintVersion"]["id"]["versionId"])
def get_version(self, version_id):
"""
Get a blueprint version and return a handle to interact with it.
:param str version_id: ID of the version
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion`
"""
return GovernAdminBlueprintVersion(self.client, self.blueprint_id, version_id)
def delete(self):
"""
Delete the blueprint.
To delete a blueprint, all related blueprint versions and artifacts must be deleted beforehand.
:return: None
"""
self.client._perform_empty("DELETE", "/admin/blueprint/%s" % self.blueprint_id)
class GovernAdminBlueprintDefinition(object):
"""
The definition of a blueprint.
Do not create this class directly, instead use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint.get_definition`
"""
def __init__(self, client, blueprint_id, definition):
self.client = client
self.blueprint_id = blueprint_id
self.definition = definition
def get_raw(self):
"""
Get raw definition of the blueprint
:return: the raw definition of blueprint, as a dict. Modifications made to the returned object are reflected when saving
:rtype: dict
"""
return self.definition
def save(self):
"""
Save this settings back to the blueprint.
:return: None
"""
self.definition = self.client._perform_json("PUT", "/admin/blueprint/%s" % self.blueprint_id, body=self.definition)["blueprint"]
class GovernAdminBlueprintVersionListItem(object):
"""
An item in a list of blueprint versions.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint.list_versions`
"""
def __init__(self, client, blueprint_id, data):
self.client = client
self.blueprint_id = blueprint_id
self._data = data
def get_raw(self):
"""
Get the raw content of the blueprint version list item
:return: the raw content of the blueprint version list item as a dict
:rtype: dict
"""
return self._data
def to_blueprint_version(self):
"""
Gets the :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion` corresponding to this blueprint version object
:return: the blueprint object
:rtype: a :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion`
"""
return GovernAdminBlueprintVersion(self.client, self.blueprint_id, self._data["blueprintVersion"]["id"]["versionId"])
class GovernAdminBlueprintVersion(object):
"""
A handle to interact with a blueprint version.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprint.get_version`
"""
def __init__(self, client, blueprint_id, version_id):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
def get_definition(self):
"""
Get the definition of this blueprint version. To modify the definition, call :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersionDefinition.save`
on the returned object.
:return: The definition of the blueprint version as an object.
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersionDefinition`.
"""
version = self.client._perform_json("GET", "/admin/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id))
return GovernAdminBlueprintVersionDefinition(self.client, self.blueprint_id, self.version_id, version["blueprintVersion"])
def get_trace(self):
"""
Get a handle of the blueprint version trace containing information about its lineage and its status.
:return: the trace of the blueprint version.
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersionTrace`.
"""
version = self.client._perform_json("GET", "/admin/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id))
return GovernAdminBlueprintVersionTrace(self.client, self.blueprint_id, self.version_id, version["blueprintVersionTrace"])
def list_signoff_configurations(self):
"""
Get the blueprint sign-off configurations of this blueprint version.
:return: The list of sign-off configurations
:rtype: list of :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfigurationListItem`
"""
configurations = self.client._perform_json("GET", "/admin/blueprint/%s/version/%s/signoffs" % (self.blueprint_id, self.version_id))
return [GovernAdminSignoffConfigurationListItem(self.client, self.blueprint_id, self.version_id, configuration) for configuration in configurations]
def get_signoff_configuration(self, step_id):
"""
Get the sign-off configurations for a specific step
:param str step_id: The step ID of the sign-off
:return: The sign-off configuration as an object
:rtype: a :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfiguration`
"""
return GovernAdminSignoffConfiguration(self.client, self.blueprint_id, self.version_id, step_id)
def create_signoff_configuration(self, step_id, signoff_configuration):
"""
Create a new sign-off for a specific step of the workflow and return a handle to interact with it.
:param str step_id: The step ID of the workflow on which the sign-off will be added.
:param dict signoff_configuration: The configuration of the sign-off
:return: The newly created sign-off configuration as an object
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfiguration`
"""
self.client._perform_json("POST", "/admin/blueprint/%s/version/%s/workflow/step/%s/signoff" % (self.blueprint_id, self.version_id, step_id),
body=signoff_configuration)
return GovernAdminSignoffConfiguration(self.client, self.blueprint_id, self.version_id, step_id)
def delete(self):
"""
Delete the blueprint version. To delete a blueprint, all related artifacts must be deleted beforehand.
:return: None
"""
self.client._perform_empty("DELETE", "/admin/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id))
class GovernAdminBlueprintVersionDefinition(object):
"""
The blueprint version definition.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion.get_definition`
"""
def __init__(self, client, blueprint_id, version_id, definition):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
self.definition = definition
def get_raw(self):
"""
Get raw definition of the blueprint version.
:return: the raw definition of blueprint version, as a dict. Modifications made to the returned object are reflected when saving
:rtype: dict
"""
return self.definition
def save(self, danger_zone_accepted=None):
"""
Save this definition back to the blueprint version definition.
:param boolean danger_zone_accepted: ignore the warning about existing artifacts.
If there are existing artifacts using this blueprint version,
modifying it may break them (ie. removing artifact field values).
By default, the save call will fail in this case.
If this parameter is set to true, the call will ignore the warning and be run anyway.
:return: None
"""
params = {}
if danger_zone_accepted is not None:
params["dangerZoneAccepted"] = danger_zone_accepted
self.definition = self.client._perform_json("PUT", "/admin/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id),
params=params, body=self.definition)["blueprintVersion"]
class GovernAdminBlueprintVersionTrace(object):
"""
The trace of a blueprint version containing information about its lineage and its status.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion.get_trace`
"""
def __init__(self, client, blueprint_id, version_id, trace):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
self.trace = trace
def get_raw(self):
"""
Get raw trace of the blueprint version.
:return: The raw trace of blueprint version, as a dict.
:rtype: dict
"""
return self.trace
@property
def status(self):
"""
Get the status of the blueprint version among (DRAFT, ACTIVE, or ARCHIVED)
:rtype: str
"""
return self.trace.get("status")
@property
def origin_version_id(self):
"""
Get the origin version ID of this blueprint version
:rtype: str
"""
return self.trace.get("originVersionId")
def set_status(self, status):
"""
Directly update the status of the blueprint version.
:param str status: DRAFT, ACTIVE, or ARCHIVED
:return: None
"""
version = self.client._perform_json("PUT", "/admin/blueprint/%s/version/%s/status" % (self.blueprint_id, self.version_id), body=status)
self.trace = version["blueprintVersionTrace"]
class GovernAdminSignoffConfigurationListItem(object):
"""
An item in a list of sign-off configurations.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion.list_signoff_configurations`
"""
def __init__(self, client, blueprint_id, version_id, data):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
self._data = data
def get_raw(self):
"""
Get the raw content of the sign-off configuration list item
:return: the raw content of the sign-off configuration list item as a dict
:rtype: dict
"""
return self._data
def to_signoff_configuration(self):
"""
Gets the :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfiguration` corresponding to this sign-off configuration object
:return: the sign-off configuration object
:rtype: a :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfiguration`
"""
return GovernAdminSignoffConfiguration(self.client, self.blueprint_id, self.version_id, self._data["id"]["stepId"])
class GovernAdminSignoffConfiguration(object):
"""
A handle to interact with the sign-off configuration of a specific step of a workflow.
Do not create this directly, use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintVersion.get_signoff_configuration`
"""
def __init__(self, client, blueprint_id, version_id, step_id):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
self.step_id = step_id
def get_definition(self):
"""
Get the definition of the configuration, to modify the configuration call :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfigurationDefinition.save`
on the returned object.
:return: The blueprint definition as an object.
:rtype: :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfigurationDefinition`
"""
definition = self.client._perform_json("GET", "/admin/blueprint/%s/version/%s/workflow/step/%s/signoff" % (self.blueprint_id, self.version_id, self.step_id))
return GovernAdminSignoffConfigurationDefinition(self.client, self.blueprint_id, self.version_id, self.step_id, definition)
def delete(self):
"""
Delete the sign-off configuration.
:return: None
"""
self.client._perform_empty("DELETE", "/admin/blueprint/%s/version/%s/workflow/step/%s/signoff" % (self.blueprint_id, self.version_id, self.step_id))
class GovernAdminSignoffConfigurationDefinition(object):
"""
The definition of sign-off configuration.
Do not create this class directly, instead use :meth:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminSignoffConfiguration.get_definition`
"""
def __init__(self, client, blueprint_id, version_id, step_id, definition):
self.client = client
self.blueprint_id = blueprint_id
self.version_id = version_id
self.step_id = step_id
self.definition = definition
def get_raw(self):
"""
Get raw definition of the sign-off configuration
:return: the raw configuration of the sign-off, as a dict. Modifications made to the returned object are reflected
when saving
:rtype: dict
"""
return self.definition
def save(self):
"""
Save this settings back to the sign-off configuration.
:return: None
"""
self.definition = self.client._perform_json(
"PUT", "/admin/blueprint/%s/version/%s/workflow/step/%s/signoff" % (self.blueprint_id, self.version_id, self.step_id),
body=self.definition)