Skip to main content

Ctx

Struct Ctx 

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

The request context handed to a facade method’s &Ctx parameter: the authenticated caller (tenant + permissions) plus the operation coordinates and an optional idempotency key.

Implementations§

Source§

impl Ctx

Source

pub fn new(principal: Principal) -> Self

Builds a context around principal with no request coordinates and no idempotency key (the transport fills those in via the extractor; this constructor is what a direct caller or a test uses).

Source

pub fn with_request( self, method: impl Into<String>, path: impl Into<String>, idempotency_key: Option<IdempotencyKey>, ) -> Self

Attaches the request’s method + path and an optional idempotency key — used by the extractor, and by a test that drives a handler directly.

Source

pub fn principal(&self) -> &Principal

The authenticated caller.

Source

pub fn tenant(&self) -> Option<&str>

The caller’s tenant, if any — the value a handler scopes its queries by. None for an untenanted or anonymous caller (which must then see nothing tenant-scoped).

Source

pub fn subject(&self) -> &str

The caller’s stable subject (empty for anonymous).

Source

pub fn scope(&self) -> Option<Scope>

The data Scope this request runs under, derived server-side from the authenticated caller — never from the request body (OWASP API1). A caller bound to a tenant yields Some(Scope::Tenant), so every tenant_scoped write in the use case is constrained to that tenant automatically.

Fail-closed (SG1, ADR 0029 BOLA): a tenant-less or anonymous caller yields None, not Scope::Global. The handler must treat None as a refusal (the accounts/notes scope_of shape: ctx.scope().ok_or(..)?) so a tenant-scoped command can never silently run cross-tenant. Scope::Global is a deliberate, audited cross-tenant choice a caller writes explicitly (the seiva:allow-global fitness-lint allowlist) — never a fallback this method hands out.

Source

pub fn has(&self, permission: &str) -> bool

Whether the caller holds permission.

Source

pub fn method(&self) -> &str

The request method (e.g. POST), empty when built without a request.

Source

pub fn path(&self) -> &str

The request path (e.g. /v1/catalogs), empty when built without a request.

Source

pub fn idempotency_key(&self) -> Option<&IdempotencyKey>

The validated Idempotency-Key the caller sent, if any. Idempotency is opt-in per request; absent (or malformed — see the extractor) means a plain, non-deduplicated call.

Trait Implementations§

Source§

impl Clone for Ctx

Source§

fn clone(&self) -> Self

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 Ctx

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<S: Sync> FromRequestParts<S> for Ctx

Source§

type Rejection = !

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Self, Self::Rejection>

Perform the extraction.

Auto Trait Implementations§

§

impl Forget for Ctx

§

impl Freeze for Ctx

§

impl Move for Ctx

§

impl RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl UnwindSafe for Ctx

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<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
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> 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, !>

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