pub struct AuditInfo {
pub created_at: Timestamp,
pub updated_at: Timestamp,
pub created_by: Principal,
pub updated_by: Principal,
}Expand description
Audit metadata embedded in API resource structs.
Tracks creation and last-update times (RFC 3339) and the Principal
that performed each action. Both actor fields are non-optional —
system processes are still actors and must declare themselves via
Principal::system.
§Example
use api_bones::{AuditInfo, Principal};
use uuid::Uuid;
let info = AuditInfo::now(Principal::human(Uuid::nil()));Fields§
§created_at: TimestampWhen the resource was created (RFC 3339).
updated_at: TimestampWhen the resource was last updated (RFC 3339).
created_by: PrincipalIdentity of the actor who created the resource.
updated_by: PrincipalIdentity of the actor who last updated the resource.
Implementations§
Source§impl AuditInfo
impl AuditInfo
Sourcepub fn new(
created_at: Timestamp,
updated_at: Timestamp,
created_by: Principal,
updated_by: Principal,
) -> Self
pub fn new( created_at: Timestamp, updated_at: Timestamp, created_by: Principal, updated_by: Principal, ) -> Self
Construct an AuditInfo with explicit timestamps and principals.
§Examples
use api_bones::{AuditInfo, Principal};
use chrono::Utc;
use uuid::Uuid;
let now = Utc::now();
let actor = Principal::human(Uuid::nil());
let info = AuditInfo::new(now, now, actor.clone(), actor);Sourcepub fn now(created_by: Principal) -> Self
pub fn now(created_by: Principal) -> Self
Construct an AuditInfo with created_at and updated_at set to
the current UTC time. updated_by is initialized to a clone of
created_by.
Requires the chrono feature.
§Examples
use api_bones::{AuditInfo, Principal};
let actor = Principal::human(Uuid::nil());
let info = AuditInfo::now(actor.clone());
assert_eq!(info.created_by, actor);
assert_eq!(info.updated_by, actor);Sourcepub fn touch(&mut self, updated_by: Principal)
pub fn touch(&mut self, updated_by: Principal)
Update updated_at to the current UTC time and set updated_by.
Requires the chrono feature.
§Examples
use api_bones::{AuditInfo, Principal};
let mut info = AuditInfo::now(Principal::human(Uuid::nil()));
info.touch(Principal::system("billing.rotation-engine"));
assert_eq!(info.updated_by.as_str(), "billing.rotation-engine");