oncall-engine/engine/apps
Ben Sully e36757b293
Allow non-JSON custom webhook templates, provided they render as valid JSON (#639)
* Allow non-JSON custom webhook templates, provided they render as valid JSON

Previously, both the provided template _and_ the rendered template had
to be valid JSON in order for validation to pass. This was unnecessarily
restrictive: really, only the rendered template needs to be valid JSON.
It also disallowed using templates such as:

    {
      "labels": {{ alert_payload.labels | tojson }}
    }

even though this would be valid JSON after rendering.

This commit relaxes the validation of custom webhook templates so that
they don't need to be valid JSON, provided that the rendered template
_is_ valid JSON. This is checked using a dummy dictionary of render
params, which use a constant string for the `alert_group_id` field
and a `defaultdict(dict)` for the `alert_payload` field. This should
permit templates like the one above, but still deny templates such as

    {
      "labels": {{ alert_payload.labels }}
    }

which would otherwise fail later if `labels` is not valid JSON.

This should resolve #638.

* Use defaultdict(str) instead of defaultdict(lambda: "")

* Add missing comment to resolution note validation code

* Update validation of resolution notes in public API, too

* Add extra test cases for JSON webhook templates endpoint of public API
2022-10-19 12:32:21 +01:00
..
alerts Merge pull request #651 from grafana/mderynck/handle-channel-filter-exception 2022-10-18 09:43:08 -06:00
api Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
api_for_grafana_incident World, meet OnCall! 2022-06-03 08:09:47 -06:00
auth_token Insight logs (#348) 2022-08-24 12:04:44 +05:00
base Handle parse exception 2022-09-21 12:36:52 -06:00
grafana_plugin Tweaks from code review, add schedule and queue assignment 2022-09-07 07:58:44 -06:00
grafana_plugin_management World, meet OnCall! 2022-06-03 08:09:47 -06:00
heartbeat Insight logs (#348) 2022-08-24 12:04:44 +05:00
integrations Add middleware to catch exception for missing integration, reduce spamminess of logs 2022-10-13 17:18:22 -06:00
migration_tool World, meet OnCall! 2022-06-03 08:09:47 -06:00
oss_installation Conform URLs (#281) 2022-07-25 09:12:50 -06:00
public_api Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
schedules Merge branch 'dev' into web-schedule-fixes 2022-10-04 11:23:52 +03:00
sendgridapp World, meet OnCall! 2022-06-03 08:09:47 -06:00
slack remove wasted condition check. 2022-10-03 18:54:56 +09:00
social_auth user_id -> linked_user_id (#410) 2022-08-25 13:34:19 +05:00
telegram Retry on exception first 5 times 2022-09-02 15:03:08 -06:00
twilioapp Use stack-slug instead of org-title 2022-09-06 13:45:34 -06:00
user_management Merge pull request #514 from grafana/fix-delete-organization-log-message 2022-09-13 08:33:25 -06:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00