Skip to content

Commit

Permalink
update to match RFD 538
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jan 2, 2025
1 parent f26b052 commit 3aee3cd
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 14 deletions.
3 changes: 2 additions & 1 deletion nexus/external-api/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ OPERATION ID METHOD URL PATH
webhook_create POST /experimental/v1/webhooks
webhook_delete DELETE /experimental/v1/webhooks/{webhook_id}
webhook_delivery_list GET /experimental/v1/webhooks/{webhook_id}/deliveries
webhook_delivery_resend POST /experimental/v1/webhooks/{webhook_id}/deliveries/{delivery_id}/resend
webhook_delivery_resend POST /experimental/v1/webhooks/{webhook_id}/deliveries/{event_id}/resend
webhook_secrets_add POST /experimental/v1/webhooks/{webhook_id}/secrets
webhook_secrets_list GET /experimental/v1/webhooks/{webhook_id}/secrets
webhook_update PUT /experimental/v1/webhooks/{webhook_id}
webhook_view GET /experimental/v1/webhooks/{webhook_id}

API operations found with tag "vpcs"
Expand Down
14 changes: 13 additions & 1 deletion nexus/external-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,18 @@ pub trait NexusExternalApi {
params: TypedBody<params::WebhookCreate>,
) -> Result<HttpResponseCreated<views::Webhook>, HttpError>;

/// Update the configuration of an existing webhook receiver.
#[endpoint {
method = PUT,
path = "/experimental/v1/webhooks/{webhook_id}",
tags = ["system/webhooks"],
}]
async fn webhook_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::WebhookPath>,
params: TypedBody<params::WebhookUpdate>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

/// Delete a webhook receiver.
#[endpoint {
method = DELETE,
Expand Down Expand Up @@ -3168,7 +3180,7 @@ pub trait NexusExternalApi {
/// Request re-delivery of a webhook event.
#[endpoint {
method = POST,
path = "/experimental/v1/webhooks/{webhook_id}/deliveries/{delivery_id}/resend",
path = "/experimental/v1/webhooks/{webhook_id}/deliveries/{event_id}/resend",
tags = ["system/webhooks"],
}]
async fn webhook_delivery_resend(
Expand Down
24 changes: 24 additions & 0 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6345,6 +6345,30 @@ impl NexusExternalApi for NexusExternalApiImpl {
.await
}

async fn webhook_update(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::WebhookPath>,
_params: TypedBody<params::WebhookUpdate>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;

let opctx =
crate::context::op_context_for_external_api(&rqctx).await?;

Err(nexus
.unimplemented_todo(&opctx, crate::app::Unimpl::Public)
.await
.into())
};
apictx
.context
.external_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}

async fn webhook_delete(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::WebhookPath>,
Expand Down
35 changes: 34 additions & 1 deletion nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2284,10 +2284,43 @@ pub struct DeviceAccessTokenRequest {

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WebhookCreate {
/// An identifier for this webhook receiver, which must be unique.
pub name: String,

/// The URL that webhook notification requests should be sent to
pub endpoint: Url,

/// A non-empty list of secret keys used to sign webhook payloads.
pub secrets: Vec<String>,

/// A list of webhook event classes to subscribe to.
///
/// If this list is empty or is not included in the request body, the
/// webhook will not be subscribed to any events.
#[serde(default)]
pub events: Vec<String>,

/// If `true`, liveness probe requests will not be sent to this webhook receiver.
#[serde(default)]
pub disable_probes: bool,
}

/// Parameters to update a webhook configuration.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WebhookUpdate {
/// An identifier for this webhook receiver, which must be unique.
pub name: String,

/// The URL that webhook notification requests should be sent to
pub endpoint: Url,

/// A list of webhook event classes to subscribe to.
///
/// If this list is empty, the webhook will not be subscribed to any events.
pub events: Vec<String>,

/// If `true`, liveness probe requests will not be sent to this webhook receiver.
pub disable_probes: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
Expand All @@ -2298,5 +2331,5 @@ pub struct WebhookSecret {
#[derive(Deserialize, JsonSchema)]
pub struct WebhookDeliveryPath {
pub webhook_id: Uuid,
pub delivery_id: Uuid,
pub event_id: Uuid,
}
18 changes: 15 additions & 3 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,13 +1033,22 @@ pub struct OxqlQueryResult {
/// The configuration for a webhook.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct Webhook {
/// The UUID of this webhook receiver.
pub id: WebhookUuid,
/// The identifier assigned to this webhook receiver upon creation.
pub name: String,
/// The URL that webhook notification requests are sent to.
pub endpoint: Url,
/// The UUID of the user associated with this webhook receiver for
/// role-based ccess control.
pub actor_id: Uuid,
// A list containing the IDs of the secret keys used to sign payloads sent
// to this receiver.
pub secrets: Vec<WebhookSecretId>,
// XXX(eliza): should eventually be an enum?
/// The list of event classes to which this receiver is subscribed.
pub events: Vec<String>,
// TODO(eliza): roles?
/// If `true`, liveness probe requests are not sent to this receiver.
pub disable_probes: bool,
}

/// A list of the IDs of secrets associated with a webhook.
Expand All @@ -1065,7 +1074,7 @@ pub struct WebhookDelivery {
pub webhook_id: WebhookUuid,

/// The event class.
pub event: String,
pub event_class: String,

/// The UUID of the event.
pub event_id: EventUuid,
Expand Down Expand Up @@ -1105,6 +1114,9 @@ pub enum WebhookDeliveryState {
FailedHttpError,
/// The webhook request could not be sent to the receiver endpoint.
FailedUnreachable,
/// A connection to the receiver endpoint was successfully established, but
/// no response was received within the delivery timeout.
FailedTimeout,
}

/// The response received from a webhook receiver endpoint.
Expand Down
Loading

0 comments on commit 3aee3cd

Please sign in to comment.