pub struct CoolContext {
pub auth: Option<CoolAuthIdentity>,
pub principal: Option<PrincipalContext>,
pub extensions: BTreeMap<String, Value>,
}Fields§
§auth: Option<CoolAuthIdentity>§principal: Option<PrincipalContext>§extensions: BTreeMap<String, Value>Implementations§
Source§impl CoolContext
impl CoolContext
pub fn anonymous() -> Self
pub fn authenticated(fields: impl IntoIterator<Item = (String, Value)>) -> Self
pub fn is_authenticated(&self) -> bool
pub fn auth_field(&self, name: &str) -> Option<&Value>
pub fn from_principal<P: Serialize>( principal: Option<P>, ) -> Result<Self, CoolError>
pub fn with_principal(principal: PrincipalContext) -> Self
Sourcepub fn principal_actor_id(&self) -> Option<&str>
pub fn principal_actor_id(&self) -> Option<&str>
Convenience accessor for the principal’s actor id. Falls back
from principal.actor.id to principal.claims.id to
auth.fields.id so audit rows capture an identity regardless
of which builder the caller used.
Sourcepub 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).
Sourcepub 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.
Sourcepub 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.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
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.
Sourcepub fn with_client_ip(self, ip: impl Into<String>) -> Self
pub fn with_client_ip(self, ip: impl Into<String>) -> Self
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§
Source§impl Clone for CoolContext
impl Clone for CoolContext
Source§fn clone(&self) -> CoolContext
fn clone(&self) -> CoolContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more