oncall-engine/engine/apps/api
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
..
permissions World, meet OnCall! 2022-06-03 08:09:47 -06:00
serializers Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
tests Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
throttlers World, meet OnCall! 2022-06-03 08:09:47 -06:00
views Allow enabling schedules alpha per organization 2022-10-05 14:06:42 -03:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
response_renderers.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
urls.py Insight logs (#348) 2022-08-24 12:04:44 +05:00