From 89f2a89b365f42da1610a70060ef9315fa3a968a Mon Sep 17 00:00:00 2001 From: Brooke Sargent Date: Mon, 2 Dec 2024 10:27:15 -0500 Subject: [PATCH] feat: webhook headers (#586) ## Short description of the changes Support headers on the webhook recipient resource. --- client/recipient.go | 8 +- client/recipient_test.go | 11 +- docs/resources/webhook_recipient.md | 18 +- internal/models/recipients.go | 11 + .../provider/webhook_recipient_resource.go | 121 ++++++++++- .../webhook_recipient_resource_test.go | 188 ++++++++++++++++++ 6 files changed, 346 insertions(+), 11 deletions(-) diff --git a/client/recipient.go b/client/recipient.go index eb4723ef..e5e90e4f 100644 --- a/client/recipient.go +++ b/client/recipient.go @@ -65,7 +65,8 @@ type RecipientDetails struct { WebhookName string `json:"webhook_name,omitempty"` WebhookURL string `json:"webhook_url,omitempty"` // webhook only - WebhookSecret string `json:"webhook_secret,omitempty"` + WebhookSecret string `json:"webhook_secret,omitempty"` + WebhookHeaders []WebhookHeader `json:"webhook_headers"` // custom webhook WebhookPayloads *WebhookPayloads `json:"webhook_payloads,omitempty"` } @@ -94,6 +95,11 @@ type TemplateVariable struct { Default string `json:"default_value"` } +type WebhookHeader struct { + Key string `json:"header"` + Value string `json:"value"` +} + // RecipientType holds all the possible recipient types. type RecipientType string diff --git a/client/recipient_test.go b/client/recipient_test.go index 86a5feba..731f9a9e 100644 --- a/client/recipient_test.go +++ b/client/recipient_test.go @@ -96,9 +96,10 @@ func TestRecipientsCustomWebhook(t *testing.T) { rcpt: client.Recipient{ Type: client.RecipientTypeWebhook, Details: client.RecipientDetails{ - WebhookName: test.RandomStringWithPrefix("test.", 10), - WebhookURL: test.RandomURL(), - WebhookSecret: "secret", + WebhookName: test.RandomStringWithPrefix("test.", 10), + WebhookURL: test.RandomURL(), + WebhookSecret: "secret", + WebhookHeaders: []client.WebhookHeader{{Key: "Authorization", Value: "Bearer 123"}}, WebhookPayloads: &client.WebhookPayloads{ PayloadTemplates: client.PayloadTemplates{Trigger: &client.PayloadTemplate{Body: body}}, TemplateVariables: []client.TemplateVariable{{Name: "severity", Default: "warning"}}, @@ -130,6 +131,10 @@ func TestRecipientsCustomWebhook(t *testing.T) { assert.Equal(t, tr.Details.WebhookSecret, r.Details.WebhookSecret) assert.Equal(t, tr.Details.WebhookPayloads, r.Details.WebhookPayloads) assert.Equal(t, tr.Details.WebhookPayloads.TemplateVariables, r.Details.WebhookPayloads.TemplateVariables) + if assert.Len(t, r.Details.WebhookHeaders, 1) { + assert.Equal(t, tr.Details.WebhookHeaders[0].Key, r.Details.WebhookHeaders[0].Key) + assert.Equal(t, tr.Details.WebhookHeaders[0].Value, r.Details.WebhookHeaders[0].Value) + } }) } } diff --git a/docs/resources/webhook_recipient.md b/docs/resources/webhook_recipient.md index 4dda4673..7e68a242 100644 --- a/docs/resources/webhook_recipient.md +++ b/docs/resources/webhook_recipient.md @@ -19,7 +19,12 @@ resource "honeycombio_webhook_recipient" "prod" { name = "Production Alerts" secret = "a63dab148496ecbe04a1a802ca9b95b8" url = "https://my.url.corp.net" - + + header { + name = "Authorization" + value = "Bearer 123" + } + template { type = "trigger" body = <