Skip to content

Commit 630cc10

Browse files
authored
[nexus] rename webhook alert headers (#8195)
Somehow, while working on renaming "webhook events" to "alerts" in PR #8169, I managed to overlook the names of the headers `x-oxide-event-id` and `x-oxide-event-class` that we set on webhook delivery requests. These should probably also be renamed to `alert`, so I did that. I also renamed `x-oxide-webhook-id` to `x-oxide-alert-id`, as that seemed clearer.
1 parent 6d30600 commit 630cc10

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

nexus/src/app/webhook.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,11 @@ impl<'a> ReceiverClient<'a> {
381381
const HDR_DELIVERY_ID: HeaderName =
382382
HeaderName::from_static("x-oxide-delivery-id");
383383
const HDR_RX_ID: HeaderName =
384-
HeaderName::from_static("x-oxide-webhook-id");
385-
const HDR_EVENT_ID: HeaderName =
386-
HeaderName::from_static("x-oxide-event-id");
387-
const HDR_EVENT_CLASS: HeaderName =
388-
HeaderName::from_static("x-oxide-event-class");
384+
HeaderName::from_static("x-oxide-receiver-id");
385+
const HDR_ALERT_ID: HeaderName =
386+
HeaderName::from_static("x-oxide-alert-id");
387+
const HDR_ALERT_CLASS: HeaderName =
388+
HeaderName::from_static("x-oxide-alert-class");
389389
const HDR_SIG: HeaderName =
390390
HeaderName::from_static("x-oxide-signature");
391391

@@ -400,7 +400,7 @@ impl<'a> ReceiverClient<'a> {
400400
#[derive(serde::Serialize, Debug)]
401401
struct DeliveryMetadata<'a> {
402402
id: WebhookDeliveryUuid,
403-
webhook_id: AlertReceiverUuid,
403+
receiver_id: AlertReceiverUuid,
404404
sent_at: &'a str,
405405
trigger: views::AlertDeliveryTrigger,
406406
}
@@ -414,7 +414,7 @@ impl<'a> ReceiverClient<'a> {
414414
data,
415415
delivery: DeliveryMetadata {
416416
id: delivery.id.into(),
417-
webhook_id: self.rx.id(),
417+
receiver_id: self.rx.id(),
418418
sent_at: &sent_at,
419419
trigger: delivery.triggered_by.into(),
420420
},
@@ -427,7 +427,7 @@ impl<'a> ReceiverClient<'a> {
427427
Ok(body) => body,
428428
Err(e) => {
429429
const MSG: &'static str =
430-
"event payload could not be serialized";
430+
"alert payload could not be serialized";
431431
slog::error!(
432432
&opctx.log,
433433
"webhook {MSG}";
@@ -438,10 +438,10 @@ impl<'a> ReceiverClient<'a> {
438438
"error" => %e,
439439
);
440440

441-
// This really shouldn't happen --- we expect the event
441+
// This really shouldn't happen --- we expect the alert
442442
// payload will always be valid JSON. We could *probably*
443443
// just panic here unconditionally, but it seems nicer to
444-
// try and do the other events. But, if there's ever a bug
444+
// try and do the other alerts. But, if there's ever a bug
445445
// that breaks serialization for *all* webhook payloads,
446446
// I'd like the tests to fail in a more obvious way than
447447
// eventually timing out waiting for the event to be
@@ -457,8 +457,8 @@ impl<'a> ReceiverClient<'a> {
457457
.post(&self.rx.endpoint)
458458
.header(HDR_RX_ID, self.hdr_rx_id.clone())
459459
.header(HDR_DELIVERY_ID, delivery.id.to_string())
460-
.header(HDR_EVENT_ID, delivery.alert_id.to_string())
461-
.header(HDR_EVENT_CLASS, alert_class.to_string())
460+
.header(HDR_ALERT_ID, delivery.alert_id.to_string())
461+
.header(HDR_ALERT_CLASS, alert_class.to_string())
462462
.header(http::header::CONTENT_TYPE, "application/json");
463463

464464
// For each secret assigned to this webhook, calculate the HMAC and add a signature header.

nexus/tests/integration_tests/webhooks.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn is_valid_for_webhook(
264264
let id = webhook.identity.id.to_string();
265265
move |when| {
266266
when.path(path)
267-
.header("x-oxide-webhook-id", id)
267+
.header("x-oxide-receiver-id", id)
268268
.header_exists("x-oxide-delivery-id")
269269
.header_exists("x-oxide-signature")
270270
.header("content-type", "application/json")
@@ -514,8 +514,8 @@ async fn test_event_delivery(cptestctx: &ControlPlaneTestContext) {
514514
})
515515
.to_string();
516516
when.method(POST)
517-
.header("x-oxide-event-class", "test.foo")
518-
.header("x-oxide-event-id", id.to_string())
517+
.header("x-oxide-alert-class", "test.foo")
518+
.header("x-oxide-alert-id", id.to_string())
519519
.and(is_valid_for_webhook(&webhook))
520520
.is_true(signature_verifies(
521521
webhook.config.secrets[0].id,
@@ -627,8 +627,8 @@ async fn test_multiple_secrets(cptestctx: &ControlPlaneTestContext) {
627627
let mock = server
628628
.mock_async(|when, then| {
629629
when.method(POST)
630-
.header("x-oxide-event-class", "test.foo")
631-
.header("x-oxide-event-id", id.to_string())
630+
.header("x-oxide-alert-class", "test.foo")
631+
.header("x-oxide-alert-id", id.to_string())
632632
.and(is_valid_for_webhook(&webhook))
633633
// There should be a signature header present for all three
634634
// secrets, and they should all verify the contents of the
@@ -716,8 +716,8 @@ async fn test_multiple_receivers(cptestctx: &ControlPlaneTestContext) {
716716
srv_bar
717717
.mock_async(move |when, then| {
718718
when.method(POST)
719-
.header("x-oxide-event-class", "test.foo.bar")
720-
.header("x-oxide-event-id", bar_alert_id.to_string())
719+
.header("x-oxide-alert-class", "test.foo.bar")
720+
.header("x-oxide-alert-id", bar_alert_id.to_string())
721721
.and(is_valid_for_webhook(&webhook))
722722
.is_true(signature_verifies(
723723
webhook.config.secrets[0].id,
@@ -757,8 +757,8 @@ async fn test_multiple_receivers(cptestctx: &ControlPlaneTestContext) {
757757
srv_baz
758758
.mock_async(move |when, then| {
759759
when.method(POST)
760-
.header("x-oxide-event-class", "test.foo.baz")
761-
.header("x-oxide-event-id", baz_alert_id.to_string())
760+
.header("x-oxide-alert-class", "test.foo.baz")
761+
.header("x-oxide-alert-id", baz_alert_id.to_string())
762762
.and(is_valid_for_webhook(&webhook))
763763
.is_true(signature_verifies(
764764
webhook.config.secrets[0].id,
@@ -800,10 +800,10 @@ async fn test_multiple_receivers(cptestctx: &ControlPlaneTestContext) {
800800
.mock_async(move |when, then| {
801801
when.method(POST)
802802
.header_matches(
803-
"x-oxide-event-class",
803+
"x-oxide-alert-class",
804804
"test\\.foo\\.ba[rz]",
805805
)
806-
.header_exists("x-oxide-event-id")
806+
.header_exists("x-oxide-alert-id")
807807
.and(is_valid_for_webhook(&webhook))
808808
.is_true(signature_verifies(
809809
webhook.config.secrets[0].id,
@@ -883,8 +883,8 @@ async fn test_retry_backoff(cptestctx: &ControlPlaneTestContext) {
883883
})
884884
.to_string();
885885
when.method(POST)
886-
.header("x-oxide-event-class", "test.foo")
887-
.header("x-oxide-event-id", id.to_string())
886+
.header("x-oxide-alert-class", "test.foo")
887+
.header("x-oxide-alert-id", id.to_string())
888888
.and(is_valid_for_webhook(&webhook))
889889
.is_true(signature_verifies(
890890
webhook.config.secrets[0].id,
@@ -962,8 +962,8 @@ async fn test_retry_backoff(cptestctx: &ControlPlaneTestContext) {
962962
})
963963
.to_string();
964964
when.method(POST)
965-
.header("x-oxide-event-class", "test.foo")
966-
.header("x-oxide-event-id", id.to_string())
965+
.header("x-oxide-alert-class", "test.foo")
966+
.header("x-oxide-alert-id", id.to_string())
967967
.and(is_valid_for_webhook(&webhook))
968968
.is_true(signature_verifies(
969969
webhook.config.secrets[0].id,
@@ -1032,8 +1032,8 @@ async fn test_retry_backoff(cptestctx: &ControlPlaneTestContext) {
10321032
})
10331033
.to_string();
10341034
when.method(POST)
1035-
.header("x-oxide-event-class", "test.foo")
1036-
.header("x-oxide-event-id", id.to_string())
1035+
.header("x-oxide-alert-class", "test.foo")
1036+
.header("x-oxide-alert-id", id.to_string())
10371037
.and(is_valid_for_webhook(&webhook))
10381038
.is_true(signature_verifies(
10391039
webhook.config.secrets[0].id,
@@ -1116,7 +1116,7 @@ async fn test_probe(cptestctx: &ControlPlaneTestContext) {
11161116
server
11171117
.mock_async(move |when, then| {
11181118
when.method(POST)
1119-
.header("x-oxide-event-class", "probe")
1119+
.header("x-oxide-alert-class", "probe")
11201120
.and(is_valid_for_webhook(&webhook))
11211121
.is_true(signature_verifies(
11221122
webhook.config.secrets[0].id,
@@ -1170,7 +1170,7 @@ async fn test_probe(cptestctx: &ControlPlaneTestContext) {
11701170
server
11711171
.mock_async(move |when, then| {
11721172
when.method(POST)
1173-
.header("x-oxide-event-class", "probe")
1173+
.header("x-oxide-alert-class", "probe")
11741174
.and(is_valid_for_webhook(&webhook))
11751175
.is_true(signature_verifies(
11761176
webhook.config.secrets[0].id,
@@ -1219,7 +1219,7 @@ async fn test_probe(cptestctx: &ControlPlaneTestContext) {
12191219
server
12201220
.mock_async(move |when, then| {
12211221
when.method(POST)
1222-
.header("x-oxide-event-class", "probe")
1222+
.header("x-oxide-alert-class", "probe")
12231223
.and(is_valid_for_webhook(&webhook))
12241224
.is_true(signature_verifies(
12251225
webhook.config.secrets[0].id,
@@ -1289,10 +1289,10 @@ async fn test_probe_resends_failed_deliveries(
12891289
server
12901290
.mock_async(move |when, then| {
12911291
when.method(POST)
1292-
.header("x-oxide-event-class", "test.foo")
1292+
.header("x-oxide-alert-class", "test.foo")
12931293
// either event
12941294
.header_matches(
1295-
"x-oxide-event-id",
1295+
"x-oxide-alert-id",
12961296
format!("({event1_id})|({event2_id})"),
12971297
)
12981298
.and(is_valid_for_webhook(&webhook))
@@ -1363,7 +1363,7 @@ async fn test_probe_resends_failed_deliveries(
13631363
})
13641364
.to_string();
13651365
when.method(POST)
1366-
.header("x-oxide-event-class", "probe")
1366+
.header("x-oxide-alert-class", "probe")
13671367
.and(is_valid_for_webhook(&webhook))
13681368
.is_true(signature_verifies(
13691369
webhook.config.secrets[0].id,
@@ -1381,10 +1381,10 @@ async fn test_probe_resends_failed_deliveries(
13811381
server
13821382
.mock_async(move |when, then| {
13831383
when.method(POST)
1384-
.header("x-oxide-event-class", "test.foo")
1384+
.header("x-oxide-alert-class", "test.foo")
13851385
// either event
13861386
.header_matches(
1387-
"x-oxide-event-id",
1387+
"x-oxide-alert-id",
13881388
format!("({event1_id})|({event2_id})"),
13891389
)
13901390
.and(is_valid_for_webhook(&webhook))
@@ -1453,8 +1453,8 @@ async fn test_api_resends_failed_deliveries(
14531453
server
14541454
.mock_async(move |when, then| {
14551455
when.method(POST)
1456-
.header("x-oxide-event-class", "test.foo")
1457-
.header("x-oxide-event-id", event1_id.to_string())
1456+
.header("x-oxide-alert-class", "test.foo")
1457+
.header("x-oxide-alert-id", event1_id.to_string())
14581458
.and(is_valid_for_webhook(&webhook))
14591459
.is_true(signature_verifies(
14601460
webhook.config.secrets[0].id,
@@ -1513,8 +1513,8 @@ async fn test_api_resends_failed_deliveries(
15131513
server
15141514
.mock_async(move |when, then| {
15151515
when.method(POST)
1516-
.header("x-oxide-event-class", "test.foo")
1517-
.header("x-oxide-event-id", event1_id.to_string())
1516+
.header("x-oxide-alert-class", "test.foo")
1517+
.header("x-oxide-alert-id", event1_id.to_string())
15181518
.and(is_valid_for_webhook(&webhook))
15191519
.is_true(signature_verifies(
15201520
webhook.config.secrets[0].id,
@@ -1592,8 +1592,8 @@ async fn subscription_add_test(
15921592
})
15931593
.to_string();
15941594
when.method(POST)
1595-
.header("x-oxide-event-class", "test.foo.bar")
1596-
.header("x-oxide-event-id", id2.to_string())
1595+
.header("x-oxide-alert-class", "test.foo.bar")
1596+
.header("x-oxide-alert-id", id2.to_string())
15971597
.and(is_valid_for_webhook(&webhook))
15981598
.is_true(signature_verifies(
15991599
webhook.config.secrets[0].id,
@@ -1724,8 +1724,8 @@ async fn subscription_remove_test(
17241724
})
17251725
.to_string();
17261726
when.method(POST)
1727-
.header("x-oxide-event-class", "test.foo.bar")
1728-
.header("x-oxide-event-id", id1.to_string())
1727+
.header("x-oxide-alert-class", "test.foo.bar")
1728+
.header("x-oxide-alert-id", id1.to_string())
17291729
.and(is_valid_for_webhook(&webhook))
17301730
.is_true(signature_verifies(
17311731
webhook.config.secrets[0].id,
@@ -1805,8 +1805,8 @@ async fn subscription_remove_test(
18051805
})
18061806
.to_string();
18071807
when.method(POST)
1808-
.header("x-oxide-event-class", "test.foo")
1809-
.header("x-oxide-event-id", id3.to_string())
1808+
.header("x-oxide-alert-class", "test.foo")
1809+
.header("x-oxide-alert-id", id3.to_string())
18101810
.and(is_valid_for_webhook(&webhook))
18111811
.is_true(signature_verifies(
18121812
webhook.config.secrets[0].id,

0 commit comments

Comments
 (0)