-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathblueprint.py
243 lines (188 loc) · 8 KB
/
blueprint.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
class GovernBlueprintListItem(object):
"""
An item in a list of blueprints.
Do not create this directly, use :meth:`~dataikuapi.govern_client.GovernClient.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.blueprint.GovernBlueprint` corresponding to this blueprint object
:return: the blueprint object
:rtype: a :class:`~dataikuapi.govern.blueprint.GovernBlueprint`
"""
return GovernBlueprint(self.client, self._data["blueprint"]["id"])
class GovernBlueprint(object):
"""
A handle to read a blueprint on the Govern instance. If you wish to edit blueprints or the blueprint versions, use
the blueprint designer object :class:`~dataikuapi.govern.admin_blueprint_designer.GovernAdminBlueprintDesigner`.
Do not create this directly, use :meth:`~dataikuapi.govern_client.GovernClient.get_blueprint`
"""
def __init__(self, client, blueprint_id):
self.client = client
self.blueprint_id = blueprint_id
def get_definition(self):
"""
Return the definition of the blueprint as an object.
:return: The blueprint definition as an object.
:rtype: :class:`~dataikuapi.govern.blueprint.GovernBlueprintDefinition`
"""
blueprint = self.client._perform_json("GET", "/blueprint/%s" % self.blueprint_id)
return GovernBlueprintDefinition(self.client, self.blueprint_id, blueprint["blueprint"])
def list_versions(self):
"""
List versions of this blueprint.
:return: the list of blueprint versions
:rtype: list of :class:`~dataikuapi.govern.blueprint.GovernBlueprintVersionListItem`
"""
versions = self.client._perform_json("GET", "/blueprint/%s/versions" % self.blueprint_id)
return [GovernBlueprintVersionListItem(self.client, self.blueprint_id, version) for version in versions]
def get_version(self, version_id):
"""
Return a handle to interact with a blueprint version
:param str version_id: ID of the version
:rtype: :class:`~dataikuapi.govern.blueprint.GovernBlueprintVersion`
"""
return GovernBlueprintVersion(self.client, self.blueprint_id, version_id)
class GovernBlueprintDefinition(object):
"""
The definition of a blueprint.
Do not create this class directly, instead use :meth:`~dataikuapi.govern.blueprint.GovernBlueprint.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 a blueprint
:return: The raw definition of blueprint, as a dict.
:rtype: dict
"""
return self.definition
class GovernBlueprintVersionListItem(object):
"""
An item in a list of blueprint versions.
Do not create this directly, use :meth:`~dataikuapi.govern.blueprint.GovernBlueprint.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.blueprint.GovernBlueprintVersion` corresponding to this blueprint version object
:return: the blueprint object
:rtype: a :class:`~dataikuapi.govern.blueprint.GovernBlueprintVersion`
"""
return GovernBlueprintVersion(self.client, self.blueprint_id, self._data["blueprintVersion"]["id"]["versionId"])
class GovernBlueprintVersion(object):
"""
A handle to interact with a blueprint version on the Govern instance.
Do not create this directly, use :meth:`~dataikuapi.govern.blueprint.GovernBlueprint.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_blueprint(self):
"""
Retrieve the blueprint handle of this blueprint version.
:return: the corresponding blueprint handle
:rtype: :class:`~dataikuapi.govern.blueprint.GovernBlueprint`
"""
return GovernBlueprint(self.client, self.blueprint_id)
def get_trace(self):
"""
Get the trace of this blueprint version (info about its status and origin blueprint version lineage).
:return: The trace of this blueprint version.
:rtype: :class:`~dataikuapi.govern.blueprint.GovernBlueprintVersionTrace`
"""
version = self.client._perform_json("GET", "/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id))
return GovernBlueprintVersionTrace(self.client, self.blueprint_id, self.version_id, version["blueprintVersionTrace"])
def get_definition(self):
"""
Get the definition of this blueprint version.
:return: The definition of the blueprint version as an object.
:rtype: :class:`~dataikuapi.govern.blueprint.GovernBlueprintVersionDefinition`
"""
version = self.client._perform_json("GET", "/blueprint/%s/version/%s" % (self.blueprint_id, self.version_id))
return GovernBlueprintVersionDefinition(self.client, self.blueprint_id, self.version_id, version["blueprintVersion"])
class GovernBlueprintVersionTrace(object):
"""
The trace of a blueprint version containing information about its lineage and its status.
Do not create this directly, use :meth:`~dataikuapi.govern.blueprint.GovernBlueprintVersion.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")
class GovernBlueprintVersionDefinition(object):
"""
The definition of a blueprint version.
Do not create this directly, use :meth:`~dataikuapi.govern.blueprint.GovernBlueprintVersion.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.
:rtype: dict
"""
return self.definition
class GovernBlueprintVersionId(object):
"""
A Blueprint Version ID builder
:param str blueprint_id: the Blueprint ID
:param str version_id: the Version ID
"""
def __init__(self, blueprint_id, version_id):
self.blueprint_id = blueprint_id
self.version_id = version_id
def build(self):
"""
:return: the built blueprint version ID definition
:rtype: dict
"""
return {"blueprintId": self.blueprint_id, "versionId": self.version_id}