MCPcopy Create free account
hub / github.com/StackStorm/st2 / to_model

Method to_model

st2common/st2common/models/api/action.py:275–313  ·  view source on GitHub ↗
(cls, action)

Source from the content-addressed store, hash-verified

273
274 @classmethod
275 def to_model(cls, action):
276 name = getattr(action, "name", None)
277 description = getattr(action, "description", None)
278 enabled = bool(getattr(action, "enabled", True))
279 entry_point = str(action.entry_point)
280 pack = str(action.pack)
281 runner_type = {"name": str(action.runner_type)}
282 parameters = getattr(action, "parameters", dict())
283 output_schema = getattr(action, "output_schema", dict())
284 tags = TagsHelper.to_model(getattr(action, "tags", []))
285 ref = ResourceReference.to_string_reference(pack=pack, name=name)
286
287 if getattr(action, "notify", None):
288 notify = NotificationsHelper.to_model(action.notify)
289 else:
290 # We use embedded document model for ``notify`` in action model. If notify is
291 # set notify to None, Mongoengine interprets ``None`` as unmodified
292 # field therefore doesn't delete the embedded document. Therefore, we need
293 # to use an empty document.
294 notify = NotificationsHelper.to_model({})
295
296 metadata_file = getattr(action, "metadata_file", None)
297
298 model = cls.model(
299 name=name,
300 description=description,
301 enabled=enabled,
302 entry_point=entry_point,
303 pack=pack,
304 runner_type=runner_type,
305 tags=tags,
306 parameters=parameters,
307 output_schema=output_schema,
308 notify=notify,
309 ref=ref,
310 metadata_file=metadata_file,
311 )
312
313 return model
314
315
316class ActionCreateAPI(ActionAPI, APIUIDMixin):

Callers 1

to_modelMethod · 0.45

Calls 1

to_string_referenceMethod · 0.45

Tested by

no test coverage detected