Skip to main content

AuditEvent

Struct AuditEvent 

Source
pub struct AuditEvent {
Show 14 fields pub timestamp: DateTime<Utc>, pub user: String, pub session_id: Option<String>, pub event_type: AuditEventType, pub resource: String, pub outcome: AuditOutcome, pub metadata: Option<Value>, pub workspace_id: Option<String>, pub tenant_id: Option<String>, pub request_id: Option<String>, pub ip_address: Option<String>, pub resource_id: Option<String>, pub action: Option<String>, pub prev_hash: Option<String>,
}
Available on crate feature auth only.
Expand description

An audit event with enterprise multi-tenant context.

All fields beyond timestamp, user, event_type, resource, and outcome are optional for backward compatibility. Enterprise platforms populate the additional context fields for multi-tenancy, tracing, and compliance.

Fields§

§timestamp: DateTime<Utc>

Timestamp of the event.

§user: String

User ID (email, subject, or system identifier).

§session_id: Option<String>

Session ID (if available).

§event_type: AuditEventType

Type of event.

§resource: String

Resource being accessed (tool name, agent name, or descriptive path).

§outcome: AuditOutcome

Outcome of the operation.

§metadata: Option<Value>

Additional metadata (arbitrary JSON).

§workspace_id: Option<String>

Workspace ID for multi-tenant scoping.

§tenant_id: Option<String>

Tenant ID for multi-tenant scoping (higher level than workspace).

§request_id: Option<String>

Request ID for distributed tracing correlation.

§ip_address: Option<String>

Client IP address.

§resource_id: Option<String>

Resource UUID (distinct from the human-readable resource name).

§action: Option<String>

Action verb (e.g., “read”, “write”, “delete”, “execute”).

§prev_hash: Option<String>

SHA-256 hash of the previous event (for cryptographic chaining).

Implementations§

Source§

impl AuditEvent

Source

pub fn new( event_type: AuditEventType, user: impl Into<String>, resource: impl Into<String>, outcome: AuditOutcome, ) -> AuditEvent

Create a new audit event with the given type, user, resource, and outcome.

Source

pub fn tool_access( user: &str, tool_name: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a new tool access event.

Source

pub fn agent_access( user: &str, agent_name: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a new agent access event.

Source

pub fn authentication(user: &str, outcome: AuditOutcome) -> AuditEvent

Create an authentication event.

Source

pub fn resource_event( event_type: AuditEventType, user: &str, resource: &str, resource_id: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a resource lifecycle event.

Source

pub fn secret_accessed( user: &str, secret_name: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a secret access event.

Source

pub fn config_changed( user: &str, config_key: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a configuration change event.

Source

pub fn custom( event_type: &str, user: &str, resource: &str, outcome: AuditOutcome, ) -> AuditEvent

Create a custom event type for platform extensions.

Source

pub fn with_session(self, session_id: impl Into<String>) -> AuditEvent

Set the session ID.

Source

pub fn with_metadata(self, metadata: Value) -> AuditEvent

Set metadata.

Source

pub fn with_workspace(self, workspace_id: impl Into<String>) -> AuditEvent

Set workspace ID for multi-tenant scoping.

Source

pub fn with_tenant(self, tenant_id: impl Into<String>) -> AuditEvent

Set tenant ID for multi-tenant scoping.

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> AuditEvent

Set request ID for distributed tracing.

Source

pub fn with_ip_address(self, ip: impl Into<String>) -> AuditEvent

Set client IP address.

Source

pub fn with_resource_id(self, id: impl Into<String>) -> AuditEvent

Set resource UUID.

Source

pub fn with_action(self, action: impl Into<String>) -> AuditEvent

Set action verb.

Source

pub fn with_prev_hash(self, prev_event_json: &str) -> AuditEvent

Compute and set the cryptographic hash chain link.

The hash is SHA-256 of the JSON-serialized previous event. Call this before logging to maintain an append-only chain.

Source

pub fn to_json(&self) -> Result<String, Error>

Serialize this event to JSON (for hash chaining).

Trait Implementations§

Source§

impl Clone for AuditEvent

Source§

fn clone(&self) -> AuditEvent

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 AuditEvent

Source§

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

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

impl<'de> Deserialize<'de> for AuditEvent

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<AuditEvent, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AuditEvent

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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 = Infallible

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,