diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e644d3bb..46bf14183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.1] - Unreleased +### Fixed +- Allow receiving `trigger_name` key in trigger payload, which is sent by Astarte >= 1.2.0. + ## [0.9.0] - 2024-10-25 ### Fixed - Correctly support automatic login attempts on the frontend regardless of existing auth sessions ([#596](https://github.com/edgehog-device-manager/edgehog/pull/596)). diff --git a/backend/lib/edgehog/triggers/trigger_payload.ex b/backend/lib/edgehog/triggers/trigger_payload.ex index 76c485a3b..58df57386 100644 --- a/backend/lib/edgehog/triggers/trigger_payload.ex +++ b/backend/lib/edgehog/triggers/trigger_payload.ex @@ -41,5 +41,10 @@ defmodule Edgehog.Triggers.TriggerPayload do public? true allow_nil? false end + + # This is sent in Astarte >= 1.2.0, so it can be nil + attribute :trigger_name, :string do + public? true + end end end diff --git a/backend/test/edgehog_web/controllers/astarte_trigger_controller_test.exs b/backend/test/edgehog_web/controllers/astarte_trigger_controller_test.exs index 4d8352fe8..5e7cac0bd 100644 --- a/backend/test/edgehog_web/controllers/astarte_trigger_controller_test.exs +++ b/backend/test/edgehog_web/controllers/astarte_trigger_controller_test.exs @@ -168,6 +168,33 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do } = device end + test "accepts trigger payload without `trigger_name` key (Astarte < 1.2.0)", ctx do + %{ + conn: conn, + path: path, + realm: realm, + tenant: tenant + } = ctx + + %Device{device_id: device_id} = + device_fixture( + tenant: tenant, + realm_id: realm.id, + online: false, + last_connection: DateTime.add(utc_now_second(), -50, :minute), + last_disconnection: DateTime.add(utc_now_second(), -10, :minute) + ) + + timestamp = utc_now_second() + + astarte_pre_1_2_0_event = + device_id + |> connection_trigger(timestamp) + |> Map.delete(:trigger_name) + + assert conn |> post(path, astarte_pre_1_2_0_event) |> response(200) + end + test "disconnection events update an existing device, not calling Astarte", ctx do %{ conn: conn, @@ -395,6 +422,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do path = Routes.astarte_trigger_path(conn, :process_event, tenant.slug) ota_event = %{ + trigger_name: "edgehog-ota-event", device_id: device.device_id, event: %{ type: "incoming_data", @@ -479,6 +507,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do path = Routes.astarte_trigger_path(conn, :process_event, tenant.slug) ota_event = %{ + trigger_name: "edgehog-ota-event", device_id: device.device_id, event: %{ type: "incoming_data", @@ -516,6 +545,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do defp connection_trigger(device_id, timestamp) do %{ + trigger_name: "edgehog-connection", device_id: device_id, event: %{ type: "device_connected", @@ -527,6 +557,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do defp disconnection_trigger(device_id, timestamp) do %{ + trigger_name: "edgehog-disconnection", device_id: device_id, event: %{ type: "device_disconnected" @@ -539,6 +570,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do defp part_number_trigger(device_id, part_number) do %{ + trigger_name: "edgehog-system-info", device_id: device_id, event: %{ type: "incoming_data", @@ -552,6 +584,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do defp serial_number_trigger(device_id, serial_number) do %{ + trigger_name: "edgehog-system-info", device_id: device_id, event: %{ type: "incoming_data", @@ -565,6 +598,7 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do defp unknown_trigger(device_id) do %{ + trigger_name: "other-trigger", device_id: device_id, event: %{ type: "incoming_data",