Struct CratestackContext
pub struct CratestackContext {
pub auth: Option<CratestackAuthIdentity>,
pub principal: Option<PrincipalContext>,
pub extensions: BTreeMap<String, Value>,
/* private fields */
}Fields§
§auth: Option<CratestackAuthIdentity>§principal: Option<PrincipalContext>§extensions: BTreeMap<String, Value>Implementations§
§impl CratestackContext
impl CratestackContext
pub fn builder(sub: impl Into<String>) -> CratestackContextBuilder
pub fn builder(sub: impl Into<String>) -> CratestackContextBuilder
Start a context for the subject sub (the sub claim).
§impl CratestackContext
impl CratestackContext
pub fn subject(&self) -> Option<Cow<'_, str>>
pub fn subject(&self) -> Option<Cow<'_, str>>
Who the caller is, for every framework read of “who” (audit actor,
MCP admission, the sync principal). Reads sub (a string), then
actor.id, then id; for the last two an integer renders as its
decimal digits. A candidate of any other type reads as absent and
the next one is tried.
pub fn roles(&self) -> Option<Vec<&str>>
pub fn roles(&self) -> Option<Vec<&str>>
The roles claim. None when absent or when any element is not a
string.
pub fn auth_time(&self) -> Option<i64>
pub fn auth_time(&self) -> Option<i64>
The auth_time claim: when the user last actively authenticated, in
seconds since the epoch.
pub fn cnf(&self, member: &str) -> Option<&Value>
pub fn cnf(&self, member: &str) -> Option<&Value>
A member of the cnf (proof-of-possession confirmation) map, by its
RFC 7800 name. None when cnf is absent or is not a map.
pub fn key_role(&self) -> Option<KeyRole>
pub fn key_role(&self) -> Option<KeyRole>
The key_role claim; None for any value but ambient or
user_present.
pub fn expires_at(&self) -> Option<i64>
pub fn expires_at(&self) -> Option<i64>
The exp claim: when the authentication expires, in seconds since
the epoch.
§impl CratestackContext
impl CratestackContext
pub fn record_verified_signer(&mut self, signer: VerifiedSigner)
pub fn record_verified_signer(&mut self, signer: VerifiedSigner)
Record the signer an envelope just verified, replacing any earlier one. Call it only after verification succeeded.
This is public because envelope implementations live in other crates.
It is therefore trusted exactly as far as any in-process layer is,
the same trust level as inserting cratestack-axum’s
VerifiedPrincipal extension. What makes it unforgeable from the
wire is that the backing field is private and #[serde(skip)]: a
context deserialized from a payload never carries a signer.
pub fn verified_signer(&self) -> Option<&VerifiedSigner>
pub fn verified_signer(&self) -> Option<&VerifiedSigner>
The signer recorded by the envelope, if the body was signed and
verified. None for unsigned traffic, including every body that
NoEnvelope opened.
§impl CratestackContext
impl CratestackContext
pub fn anonymous() -> CratestackContext
pub fn authenticated( fields: impl IntoIterator<Item = (String, Value)>, ) -> CratestackContext
pub fn is_authenticated(&self) -> bool
pub fn is_system(&self) -> bool
pub fn is_system(&self) -> bool
Backs the auth().isSystem() policy builtin. true only for a
context minted through SystemContext; never true for
anything an AuthProvider produced from a request, and never
true after a deserialization round-trip. See the field doc on
CratestackContext::system for the structural argument, not just the
convention, behind that guarantee.
pub fn auth_field(&self, name: &str) -> Option<&Value>
pub fn from_principal<P>(
principal: Option<P>,
) -> Result<CratestackContext, CratestackError>where
P: Serialize,
pub fn with_principal(principal: PrincipalContext) -> CratestackContext
pub fn principal_actor_id(&self) -> Option<Cow<'_, str>>
pub fn principal_actor_id(&self) -> Option<Cow<'_, str>>
The caller’s identity for audit rows: Self::subject (sub,
then actor.id, then id, an integer as its decimal digits).
Kept as a name for existing callers; it answers exactly what
subject() answers.
pub fn client_ip(&self) -> Option<&str>
pub fn client_ip(&self) -> Option<&str>
Client IP, if the auth provider injected one (e.g. from
X-Forwarded-For or the socket remote-addr).
pub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
W3C traceparent value, if surfaced into the context by the
correlation-id middleware.
pub fn audit_claims_snapshot(&self) -> BTreeMap<String, Value>
pub fn audit_claims_snapshot(&self) -> BTreeMap<String, Value>
Snapshot of principal claims for audit recording — full map regardless of nesting depth. Empty for anonymous contexts.
pub fn with_request_id(self, request_id: impl Into<String>) -> CratestackContext
pub fn with_request_id(self, request_id: impl Into<String>) -> CratestackContext
Attach a W3C traceparent-style request id to the context.
Surfaces in tracing spans and is recorded on audit events so
SIEM tools can stitch the trail across systems.
pub fn with_client_ip(self, ip: impl Into<String>) -> CratestackContext
pub fn with_client_ip(self, ip: impl Into<String>) -> CratestackContext
Attach a client IP for the same reasons as
Self::with_request_id. Banks generally derive this from
X-Forwarded-For or the socket address inside the auth
provider.
Trait Implementations§
§impl AsRef<CratestackContext> for SystemContext
impl AsRef<CratestackContext> for SystemContext
§fn as_ref(&self) -> &CratestackContext
fn as_ref(&self) -> &CratestackContext
§impl Clone for CratestackContext
impl Clone for CratestackContext
§fn clone(&self) -> CratestackContext
fn clone(&self) -> CratestackContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for CratestackContext
impl Debug for CratestackContext
§impl Default for CratestackContext
impl Default for CratestackContext
§fn default() -> CratestackContext
fn default() -> CratestackContext
§impl<'de> Deserialize<'de> for CratestackContext
impl<'de> Deserialize<'de> for CratestackContext
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CratestackContext, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CratestackContext, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl PartialEq for CratestackContext
impl PartialEq for CratestackContext
§fn eq(&self, other: &CratestackContext) -> bool
fn eq(&self, other: &CratestackContext) -> bool
self and other values to be equal, and is used by ==.§impl Serialize for CratestackContext
impl Serialize for CratestackContext
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for CratestackContext
Auto Trait Implementations§
impl !Freeze for CratestackContext
impl RefUnwindSafe for CratestackContext
impl Send for CratestackContext
impl Sync for CratestackContext
impl Unpin for CratestackContext
impl UnsafeUnpin for CratestackContext
impl UnwindSafe for CratestackContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> MaybeSend for T
impl<T> MaybeSendSync for T
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].