oncall-engine/engine
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
..
apps Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
common Use create_engine_url to add prefix to previous/next links (#553) 2022-09-23 10:45:28 +01:00
config_integrations fetch item with ?from_organization=true 2022-09-16 16:48:05 +03:00
engine Fix default value for OSS_INSTALLATION 2022-06-08 20:23:26 +04:00
settings Add middleware to catch exception for missing integration, reduce spamminess of logs 2022-10-13 17:18:22 -06:00
static/images World, meet OnCall! 2022-06-03 08:09:47 -06:00
celery_with_exporter.sh Change flags position for celery 5 2022-09-01 13:54:19 +03:00
conftest.py Remove auto-recreating logic for UserNotificationPolicy (#414) 2022-08-26 13:46:50 +05:00
Dockerfile Allow multiple database and celery broker types (#582) 2022-10-04 09:25:53 +01:00
manage.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
pyproject.toml World, meet OnCall! 2022-06-03 08:09:47 -06:00
requirements.txt Bump cryptography vertsion 2022-10-04 16:58:35 +08:00
tox.ini World, meet OnCall! 2022-06-03 08:09:47 -06:00
uwsgi.ini Update uwsgi.ini 2022-06-15 19:13:50 +03:00
wait_for_test_mysql_start.sh World, meet OnCall! 2022-06-03 08:09:47 -06:00