Skip to content

Commit 2729e97

Browse files
committed
more feedback from @smklein
This addresses the suggestion from #10555 (comment)
1 parent e5e0787 commit 2729e97

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

nexus/db-model/src/webhook_delivery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl WebhookDelivery {
113113

114114
pub fn to_api_delivery(
115115
&self,
116-
alert_class: AlertClass,
116+
alert_class: impl Into<AlertClass>,
117117
attempts: &[WebhookDeliveryAttempt],
118118
) -> alert::AlertDelivery {
119119
let mut attempts: Vec<_> =
@@ -126,7 +126,7 @@ impl WebhookDelivery {
126126
alert::AlertDelivery {
127127
id: self.id.into_untyped_uuid(),
128128
receiver_id: self.rx_id.into(),
129-
alert_class: alert_class.as_str().to_owned(),
129+
alert_class: alert_class.into().as_str().to_owned(),
130130
alert_id: self.alert_id.into(),
131131
state: self.state.into(),
132132
trigger: self.triggered_by.into(),

nexus/src/app/webhook.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use nexus_db_lookup::LookupPath;
3838
use nexus_db_lookup::lookup;
3939
use nexus_db_queries::authz;
4040
use nexus_db_queries::context::OpContext;
41-
use nexus_db_queries::db::model::AlertClass;
4241
use nexus_db_queries::db::model::AlertDeliveryState;
4342
use nexus_db_queries::db::model::AlertDeliveryTrigger;
4443
use nexus_db_queries::db::model::AlertReceiver;
@@ -49,6 +48,8 @@ use nexus_db_queries::db::model::WebhookDeliveryAttemptResult;
4948
use nexus_db_queries::db::model::WebhookReceiverConfig;
5049
use nexus_db_queries::db::model::WebhookSecret;
5150
use nexus_types::alert as alert_types;
51+
use nexus_types::alert::AlertClass;
52+
use nexus_types::alert::AlertPayload;
5253
use nexus_types::external_api::alert;
5354
use nexus_types::identity::Asset;
5455
use nexus_types::identity::Resource;
@@ -192,11 +193,13 @@ impl Nexus {
192193
)?;
193194
let mut delivery = WebhookDelivery::new_probe(&rx_id, &self.id);
194195

195-
const CLASS: AlertClass = AlertClass::Probe;
196-
const VERSION: u32 =
197-
<alert_types::Probe as alert_types::AlertPayload>::VERSION;
198-
static DATA: LazyLock<serde_json::Value> =
199-
LazyLock::new(|| serde_json::json!({}));
196+
const CLASS: AlertClass = <alert_types::Probe as AlertPayload>::CLASS;
197+
const VERSION: u32 = <alert_types::Probe as AlertPayload>::VERSION;
198+
static DATA: LazyLock<serde_json::Value> = LazyLock::new(|| {
199+
serde_json::to_value(&alert_types::Probe {}).expect(
200+
"a struct with no fields should always serialize properly",
201+
)
202+
});
200203

201204
let attempt = match client
202205
.send_delivery_request(opctx, &delivery, CLASS, VERSION, &DATA)
@@ -378,7 +381,7 @@ impl<'a> ReceiverClient<'a> {
378381
&mut self,
379382
opctx: &OpContext,
380383
delivery: &WebhookDelivery,
381-
alert_class: AlertClass,
384+
alert_class: impl Into<AlertClass>,
382385
alert_version: u32,
383386
data: &serde_json::Value,
384387
) -> Result<WebhookDeliveryAttempt, anyhow::Error> {
@@ -415,6 +418,7 @@ impl<'a> ReceiverClient<'a> {
415418
}
416419

417420
// okay, actually do the thing...
421+
let alert_class = alert_class.into();
418422
let time_attempted = Utc::now();
419423
let sent_at = time_attempted.to_rfc3339();
420424
let payload = Payload {

0 commit comments

Comments
 (0)