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

Method run

contrib/core/actions/inject_trigger.py:24–54  ·  view source on GitHub ↗
(self, trigger=None, trigger_name=None, payload=None, trace_tag=None)

Source from the content-addressed store, hash-verified

22
23class InjectTriggerAction(Action):
24 def run(self, trigger=None, trigger_name=None, payload=None, trace_tag=None):
25 payload = payload or {}
26
27 datastore_service = self.action_service.datastore_service
28 client = datastore_service.get_api_client()
29
30 # Dispatch the trigger using the /webhooks/st2 API endpoint
31 # NOTE: Webhooks API endpoint is asynchronous so we don't know if the actual injection
32 # results in a TriggerInstanceDB database object creation or not. The object is created
33 # inside rulesengine service and could fail due to the user providing an invalid trigger
34 # reference or similar.
35
36 # Raise an error if both trigger and trigger_name are specified
37 if trigger and trigger_name:
38 raise ValueError(
39 "Parameters `trigger` and `trigger_name` are mutually exclusive."
40 )
41
42 # Raise an error if neither trigger nor trigger_name are specified
43 if not trigger and not trigger_name:
44 raise ValueError("You must include the `trigger_name` parameter.")
45
46 trigger = trigger if trigger else trigger_name
47 self.logger.debug(
48 'Injecting trigger "%s" with payload="%s"' % (trigger, str(payload))
49 )
50 result = client.webhooks.post_generic_webhook(
51 trigger=trigger, payload=payload, trace_tag=trace_tag
52 )
53
54 return result

Callers

nothing calls this directly

Calls 2

post_generic_webhookMethod · 0.80
get_api_clientMethod · 0.45

Tested by

no test coverage detected