StackStorm-Exchange / stackstorm-st2

StackStorm pack management
https://exchange.stackstorm.org/
Apache License 2.0
5 stars 18 forks source link

Add "inquiry respond" action and alias #7

Closed Mierdin closed 6 years ago

Mierdin commented 6 years ago

This PR introduces a new action, st2.inquiry.respond, and an accompanying action-alias for use in chatops. With these, a user can respond to inquiries via chatops (though they will still have to put together the JSON payload themselves).

Usage

The action can certainly be used on its own or in a workflow, using the Inquiry ID and the response payload:

vagrant@st2vagrant:~$ st2 run examples.mistral-ask-basic
.
id: 5a1f4411c4da5f4486b09361
action.ref: examples.mistral-ask-basic
parameters: None
status: pausing
start_timestamp: Wed, 29 Nov 2017 23:34:41 UTC
end_timestamp:
+--------------------------+---------+-------+----------+-------------------------------+
| id                       | status  | task  | action   | start_timestamp               |
+--------------------------+---------+-------+----------+-------------------------------+
| 5a1f4411c4da5f4486b09364 | pending | task1 | core.ask | Wed, 29 Nov 2017 23:34:41 UTC |
+--------------------------+---------+-------+----------+-------------------------------+
vagrant@st2vagrant:~$ st2 inquiry list
+--------------------------+-------+-------+------------+------+
| id                       | roles | users | route      | ttl  |
+--------------------------+-------+-------+------------+------+
| 5a1f4411c4da5f4486b09364 |       |       | developers | 1440 |
+--------------------------+-------+-------+------------+------+
vagrant@st2vagrant:~$ st2 inquiry get 5a1f4411c4da5f4486b09364
+----------+--------------------------------------------------------------+
| Property | Value                                                        |
+----------+--------------------------------------------------------------+
| id       | 5a1f4411c4da5f4486b09364                                     |
| roles    |                                                              |
| users    |                                                              |
| route    | developers                                                   |
| ttl      | 1440                                                         |
| schema   | {                                                            |
|          |     "type": "object",                                        |
|          |     "properties": {                                          |
|          |         "secondfactor": {                                    |
|          |             "required": true,                                |
|          |             "type": "string",                                |
|          |             "description": "Please enter second factor for   |
|          | authenticating to "foo" service"                             |
|          |         }                                                    |
|          |     }                                                        |
|          | }                                                            |
+----------+--------------------------------------------------------------+
vagrant@st2vagrant:~$ st2 run st2.inquiry.respond id=5a1f4411c4da5f4486b09364 response='{"secondfactor": "foo"}'
.
id: 5a1f444ec4da5f4486b09366
status: succeeded
parameters:
  id: 5a1f4411c4da5f4486b09364
  response:
    secondfactor: '********'
result:
  exit_code: 0
  result: null
  stderr: ''
  stdout: ''
vagrant@st2vagrant:~$ st2 inquiry list
+----+-------+-------+-------+-----+
| id | roles | users | route | ttl |
+----+-------+-------+-------+-----+
+----+-------+-------+-------+-----+

In addition, the provided action-alias makes it possible to call this action from Slack (or another chatops-capable application). The result template also provides a bit of feedback to the user on whether or not their response was accepted:

screenshot 2017-11-29 15 53 47

Currently, the UX isn't the greatest, since the user will have to manually construct the JSON payload within their chat program, but it's better than nothing for now.

Dependencies

Some st2 work needed to take place to prepare for this action, so this should not be merged before the below PRs are merged:

Documentation

I opened https://github.com/StackStorm/st2docs/pull/672 to explain the new action and action-alias in the Inquiries section, as well as to explain the masking behavior introduced in https://github.com/StackStorm/st2/pull/3868