pub trait EnvelopePolicy:
Send
+ Sync
+ 'static {
// Required method
fn mode(&self, request: &PolicyRequest<'_>) -> EnvelopeMode;
// Provided method
fn unresolved_mode(&self) -> EnvelopeMode { ... }
}Expand description
Picks the EnvelopeMode for a request, from the op it addresses.
EnvelopeMode implements it (one mode for every op), and so does any
Fn(&PolicyRequest<'_>) -> EnvelopeMode, so a per-op policy is a
closure:
use cratestack_axum::envelope_layer::{EnvelopeMode, PolicyRequest};
let policy = |request: &PolicyRequest<'_>| {
if request.is_subscription() { EnvelopeMode::Optional } else { EnvelopeMode::Required }
};There is no default: the layer’s builder refuses to build without one
(decision D9). A policy sees no header (PolicyRequest), so no
request can talk it into a weaker mode.
What the layer enforces whatever this returns: a request with a
COSE body is opened (or, under Off, refused) regardless; under
Required no unsigned request reaches the router and no response leaves
unsealed; a /rpc/batch call runs under the strictest mode of batch
and every frame’s op (decision B1). A policy can only choose how strict
to be for plain traffic, never make the layer accept an unverified
envelope.
Required Methods§
Sourcefn mode(&self, request: &PolicyRequest<'_>) -> EnvelopeMode
fn mode(&self, request: &PolicyRequest<'_>) -> EnvelopeMode
The mode for this op.
Provided Methods§
Sourcefn unresolved_mode(&self) -> EnvelopeMode
fn unresolved_mode(&self) -> EnvelopeMode
The mode for traffic the layer cannot attribute to one op: a route
the router matched but the resolver cannot bind (a wrong mount
prefix, a hand-written route; decision S2), or a /rpc/batch body
whose frames it cannot read (B1). Under Required the first fails
closed with a 500 unless the route is allow-listed
(super::EnvelopeLayerBuilder::allow_unresolved), and the second
is refused. Under a non-Required answer, both pass through, and so
does a method the schema does not generate on a generated path
(otherwise the layer’s 405), unsigned.
The default is Required, which fails closed: a per-op closure
cannot say what it would have answered for an op nobody can name.
An EnvelopeMode used as the policy answers itself. For a
closure, super::EnvelopeLayerBuilder::unresolved_mode replaces
it explicitly, without writing a type.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".