Skip to main content

WebhookIngress

Struct WebhookIngress 

Source
pub struct WebhookIngress { /* private fields */ }
Expand description

The webhook ingress: spool, secret, and one relay per target.

Why: assembled once at startup and shared by the route handler, the metrics handler, and the background retry sweep, so all three see the same spool. What: cheap to clone (everything behind Arc). Test: constructed directly in tests.rs with a temp-dir spool, so no test mutates a process-global env var.

Implementations§

Source§

impl WebhookIngress

Source

pub fn new( spool: Spool, secret: String, key_id: String, targets: Vec<Target>, ) -> Self

Assemble an ingress from explicit parts.

Test: used by every tests.rs case.

Source

pub fn with_inbox_roots(self, roots: Vec<(String, PathBuf)>) -> Self

Meter these inboxes when reporting health.

Why: an acknowledged delivery leaves the spool, so without this the status goes green while the work sits unprocessed in a target’s inbox. Test: health_is_degraded_while_a_delivery_sits_undrained.

Source

pub fn with_red_after(self, red_after: Duration) -> Self

Override the red-health threshold.

Source

pub fn with_backoff(self, backoff: BackoffPolicy) -> Self

Override the retry schedule.

Test: the sweep_* and backoff_* cases use a zeroed grace so a sweep runs without waiting out the real 5 s hold-off.

Source

pub fn backoff(&self) -> BackoffPolicy

The retry schedule in force.

Source

pub fn from_env() -> Result<Self>

Production wiring: spool under the console data dir, secret from SECRET_ENV, and one target per relay-capable service.

Why: the socket paths come from trusty_common::uds::scratch_socket_dir, the shared entry point #5099 built. That is $TMPDIR/trusty-<uid> with a /tmp fallback — the base ADR-0034 §3 names, but not the exposure it objects to: the uid-keyed subdirectory is created at 0700 and owned by this process, and connect_hardened re-verifies owner and mode before dialling. #5099 supersedes §3’s “use the service state directory instead” path rule by making the scratch path satisfy the property §3 wanted. Nothing binds these sockets until step 4; dialling an absent one is a clean Unreachable. What: creates the spool directory eagerly so a misconfigured data dir fails at startup rather than on the first delivery.

§Errors

When the data directory cannot be resolved or the spool directory cannot be created.

Test: default_spool_root_lives_under_the_console_data_dir, plus the #[ignore]d integration_from_env_* cases, which point TRUSTY_DATA_DIR_OVERRIDE at a temp dir under a lock.

Source

pub fn spool(&self) -> &Spool

The spool this ingress writes to.

Source

pub async fn health(&self) -> SpoolHealth

Scan the spool and classify its health, now.

Deliberately not cached — see health’s module docs. The scan is filesystem work, so it runs off the async runtime.

Source

pub async fn ingest( &self, source: &str, headers: &HeaderMap, body: &[u8], ) -> IngestOutcome

Verify, spool, relay — in that order.

Why: the ordering IS the fix; see the module docs. In particular the spool write happens before this function can return anything a caller would turn into a 202, and a relay failure never propagates as a reason to drop the delivery.

What: returns an IngestOutcome; performs no HTTP.

Test: ingest_rejects_an_unknown_source, ingest_fails_closed_when_no_secret_is_configured, ingest_rejects_a_forged_signature, ingest_returns_spool_failed_and_never_accepts_when_the_write_fails, ingest_accepts_and_deletes_on_an_explicit_ack, relay_failure_leaves_a_pending_entry_with_an_incremented_attempt_count.

Source

pub async fn retry_pending_once(&self) -> SweepReport

Re-attempt every pending delivery that is due, once.

Why: ADR-0034 §2 — “Console retries with backoff.” Three guards, each closing a different failure:

  • Backoff (BackoffPolicy::is_due) — without it every pending entry is re-relayed on every tick and each non-ack rewrites the whole base64 body plus two fsyncs. Until step 4 binds a listener that is every delivery, forever.
  • Claims (schedule::ClaimSet) — without them a tick landing inside the ≤5 s relay window sends a delivery the request path is still sending. One delivery, two relays.
  • [SWEEP_BUDGET] — the pass is serial and each relay can burn its full timeout, so an unbounded pass can outlast its own tick interval.

Nothing any guard skips is dropped: it stays pending, durable, and visible to WebhookIngress::health, which scans on the request rather than trusting this loop to still be alive.

What: relays each due entry, deleting only on an explicit ack. Returns per-sweep counts.

Test: retry_sweep_acks_and_clears_a_pending_entry, retry_sweep_leaves_an_unrelayable_entry_pending_with_more_attempts, sweep_does_not_relay_an_entry_the_request_path_is_still_relaying, sweep_honours_backoff_between_ticks, sweep_stops_relaying_an_exhausted_entry.

Trait Implementations§

Source§

impl Clone for WebhookIngress

Source§

fn clone(&self) -> WebhookIngress

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebhookIngress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more