oncall-engine/engine/apps/api/serializers
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
..
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
alert.py Add alert detail view (#385) 2022-08-19 14:03:07 +05:00
alert_group.py Feat 549 - add telegram permalink to alert groups http response (#551) 2022-09-28 16:59:57 +02:00
alert_receive_channel.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
channel_filter.py Fix channel filter updates when there are multiple backends 2022-09-02 14:26:47 -03:00
custom_button.py Allow non-JSON custom webhook templates, provided they render as valid JSON (#639) 2022-10-19 12:32:21 +01:00
custom_serializers.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
escalation_chain.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
escalation_policy.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
integration_heartbeat.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
live_setting.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
on_call_shifts.py Remove user group rotation reordering 2022-09-06 12:59:38 +03:00
organization.py Improve version mismatch warning (#469) 2022-09-02 15:16:00 +01:00
organization_slack_settings.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
public_api_token.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
resolution_note.py Optimize alert group list view (#299) 2022-07-27 14:14:59 +03:00
schedule_base.py Add related escalation chains details to schedule API 2022-09-05 15:00:14 -03:00
schedule_calendar.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
schedule_ical.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
schedule_polymorphic.py Initial web schedule model and serializers. Add override shift type. 2022-07-05 12:41:55 -03:00
schedule_reminder.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
schedule_web.py Initial web schedule model and serializers. Add override shift type. 2022-07-05 12:41:55 -03:00
slack_channel.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
slack_user_identity.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
team.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
telegram.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
user.py Add hiding personal phone numbers (#411) 2022-09-09 12:42:40 +05:00
user_group.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
user_notification_policy.py World, meet OnCall! 2022-06-03 08:09:47 -06:00