From f00c1c1b22c85ab596f05985214ba3e7f6eee2fc Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Wed, 28 Jan 2026 14:31:58 +0100 Subject: [PATCH] When address is empty, detail is explicitly set to an empty array to clear any existing detail items in pfSense --- internal/integrations/pfsense.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/internal/integrations/pfsense.go b/internal/integrations/pfsense.go index 8f4626e..d5f94b5 100644 --- a/internal/integrations/pfsense.go +++ b/internal/integrations/pfsense.go @@ -313,27 +313,25 @@ func (p *pfSenseIntegration) updateAlias(client *http.Client, baseURL, apiToken apiURL := baseURL + "/api/v2/firewall/alias" // Prepare PATCH payload - include id in the request body + // pfSense requires that detail cannot have more items than address + // Always include detail array to ensure it matches address length + detailToSend := alias.Detail + if len(detailToSend) > len(alias.Address) { + // Truncate detail to match address length + detailToSend = detailToSend[:len(alias.Address)] + } + // If address is empty, detail must also be empty + if len(alias.Address) == 0 { + detailToSend = []string{} + } + patchPayload := map[string]interface{}{ "id": alias.ID, "name": alias.Name, "type": alias.Type, "descr": alias.Descr, "address": alias.Address, - } - // pfSense requires that detail cannot have more items than address - // If address is empty, detail must also be empty - if len(alias.Address) > 0 { - // Only include detail if address has items, and ensure detail length matches address length - detailToSend := alias.Detail - if len(detailToSend) > len(alias.Address) { - // Truncate detail to match address length - detailToSend = detailToSend[:len(alias.Address)] - } - // Always include detail array when address has items (even if empty) to maintain consistency - patchPayload["detail"] = detailToSend - } else { - // When address is empty, explicitly set detail to empty array - patchPayload["detail"] = []string{} + "detail": detailToSend, // Always include detail to ensure it's cleared when address is empty } data, err := json.Marshal(patchPayload)