pub struct PostgresAuditStore { /* private fields */ }audit only.Expand description
An AuditStore in PostgreSQL tables a2a_audit_records,
a2a_audit_checkpoints, a2a_audit_holds and a2a_audit_subject_keys,
created if absent.
Replicas may share it: the (chain, seq) primary key is what keeps two of
them from forking one chain, and each append takes a per-chain advisory lock
and reads the head under it, so replicas queue for the chain instead of
racing for a position and retrying (audit E-F18). That costs one connection
held for the length of an append, and no second one: the log reads the
store (the keys of the people a record names, the anchor of an empty chain)
before the append begins, and the sealer it hands the store reads nothing
(adversarial review A2). A pool handed to from_pool
should still have two or more, so that one slow statement does not hold
up every other. The records are timed by
the database’s clock, so one chain’s times do not run backwards when its
writers’ clocks disagree. It can share a database
(and a pool) with PostgresTaskStore;
it touches only its own tables. Each record is stored as the exact JSON
it was sealed with, so it reads back byte-for-byte equal and its hash
still verifies.
Implementations§
Source§impl PostgresAuditStore
impl PostgresAuditStore
Sourcepub async fn new(url: &str) -> Result<PostgresAuditStore, Error>
pub async fn new(url: &str) -> Result<PostgresAuditStore, Error>
Connects to url and creates the audit tables if absent.
§Errors
Returns an error if the database cannot be reached or the tables created.
Sourcepub async fn from_pool(
pool: Pool<Postgres>,
) -> Result<PostgresAuditStore, Error>
pub async fn from_pool( pool: Pool<Postgres>, ) -> Result<PostgresAuditStore, Error>
Uses an existing pool, creating the audit tables if absent.
§Errors
Returns an error if the tables cannot be created.
Trait Implementations§
Source§impl AuditStore for PostgresAuditStore
impl AuditStore for PostgresAuditStore
Source§fn append_next<'a>(
&'a self,
chain: &'a str,
seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync),
) -> Pin<Box<dyn Future<Output = Result<Option<AuditRecord>, A2aError>> + Send + 'a>>
fn append_next<'a>( &'a self, chain: &'a str, seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<Option<AuditRecord>, A2aError>> + Send + 'a>>
Reads the head and stores the record that follows it in one transaction that holds the chain’s advisory lock, so no other appender that takes the lock can take the position in between.
Cancellation: dropping this future drops the transaction, which sqlx rolls back when the connection is returned to the pool (it pings the connection on release), and the rollback releases the lock. A writer that does not take the lock (another implementation, or SQL of one’s own) is still turned away by the primary key.
Source§fn delete_through_unless_held<'a>(
&'a self,
chain: &'a str,
seq: u64,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
fn delete_through_unless_held<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
Under the chain’s advisory lock, the one place_hold and
release_hold take too, so a hold and a deletion of one chain happen
one after the other, on whichever replica each runs.
Source§fn append_next_naming<'a>(
&'a self,
chain: &'a str,
sids: &'a [String],
seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync),
) -> Pin<Box<dyn Future<Output = Result<NamedAppend, A2aError>> + Send + 'a>>
fn append_next_naming<'a>( &'a self, chain: &'a str, sids: &'a [String], seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<NamedAppend, A2aError>> + Send + 'a>>
Under the chain’s advisory lock, which the two deletions below take too.
Source§fn head<'a>(
&'a self,
chain: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>
fn head<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>
seq stored in chain and that record’s hash.Source§fn append<'a>(
&'a self,
record: &'a AuditRecord,
) -> Pin<Box<dyn Future<Output = Result<Appended, A2aError>> + Send + 'a>>
fn append<'a>( &'a self, record: &'a AuditRecord, ) -> Pin<Box<dyn Future<Output = Result<Appended, A2aError>> + Send + 'a>>
(chain, seq) is already taken.Source§fn read<'a>(
&'a self,
chain: &'a str,
after: u64,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<AuditRecord>, A2aError>> + Send + 'a>>
fn read<'a>( &'a self, chain: &'a str, after: u64, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<AuditRecord>, A2aError>> + Send + 'a>>
limit records of chain with seq above after, in order.Source§fn chains(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, A2aError>> + Send + '_>>
fn chains( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, A2aError>> + Send + '_>>
Source§fn put_checkpoint<'a>(
&'a self,
checkpoint: &'a Checkpoint,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn put_checkpoint<'a>( &'a self, checkpoint: &'a Checkpoint, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
seq and kind.Source§fn checkpoints<'a>(
&'a self,
chain: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Checkpoint>, A2aError>> + Send + 'a>>
fn checkpoints<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Checkpoint>, A2aError>> + Send + 'a>>
chain, in seq order.Source§fn last_before<'a>(
&'a self,
chain: &'a str,
cutoff_ms: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>
fn last_before<'a>( &'a self, chain: &'a str, cutoff_ms: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>
chain sealed before cutoff_ms (Unix
milliseconds), as (seq, hash).Source§fn delete_through<'a>(
&'a self,
chain: &'a str,
seq: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn delete_through<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
chain up to and including seq, and the
checkpoints below seq (an anchor at seq itself is kept). Returns
how many records went.Source§fn place_hold<'a>(
&'a self,
hold: &'a LegalHold,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn place_hold<'a>( &'a self, hold: &'a LegalHold, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
chain, replacing any reason already given.Source§fn release_hold<'a>(
&'a self,
chain: &'a str,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn release_hold<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
chain; returns whether there was one.Source§fn holds(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<LegalHold>, A2aError>> + Send + '_>>
fn holds( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<LegalHold>, A2aError>> + Send + '_>>
Source§fn supports_subject_keys(&self) -> bool
fn supports_subject_keys(&self) -> bool
AuditLog::with_privacy
refuses a store that answers false.Source§fn subject_key<'a>(
&'a self,
chain: &'a str,
lookup: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>
fn subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>
Source§fn subject_key_by_sid<'a>(
&'a self,
chain: &'a str,
sid: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>
fn subject_key_by_sid<'a>( &'a self, chain: &'a str, sid: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>
Source§fn subject_keys<'a>(
&'a self,
chain: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<SubjectKey>, A2aError>> + Send + 'a>>
fn subject_keys<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<SubjectKey>, A2aError>> + Send + 'a>>
chain, for dropping those no record names. Read moreSource§fn put_subject_key<'a>(
&'a self,
chain: &'a str,
key: &'a SubjectKey,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn put_subject_key<'a>( &'a self, chain: &'a str, key: &'a SubjectKey, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
key for chain unless a key with its lookup is there;
false when one was, and nothing was stored. Atomic: of two writers
racing on one lookup, exactly one stores. Read moreSource§fn delete_subject_key<'a>(
&'a self,
chain: &'a str,
lookup: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, A2aError>> + Send + 'a>>
fn delete_subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, A2aError>> + Send + 'a>>
chain whose lookup is lookup, returning its
sid, or None when there was none. Must not leave a copy: what it
deletes is what erasure destroys. Read moreSource§fn delete_subject_key_unless_named<'a>(
&'a self,
chain: &'a str,
lookup: &'a str,
sid: &'a str,
scanned_through: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn delete_subject_key_unless_named<'a>( &'a self, chain: &'a str, lookup: &'a str, sid: &'a str, scanned_through: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
chain whose lookup is lookup and handle sid,
unless a record with seq above scanned_through references sid
(sid_marker); true when it was deleted. For dropping keys no
record names: the caller has read the chain through
scanned_through, found no record naming sid, and this checks the
records stored since, atomically with the deletion (see
append_next_naming). Read moreSource§fn delete_subject_keys_unless_held<'a>(
&'a self,
chain: &'a str,
lookups: &'a [String],
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, A2aError>> + Send + 'a>>
fn delete_subject_keys_unless_held<'a>( &'a self, chain: &'a str, lookups: &'a [String], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, A2aError>> + Send + 'a>>
chain whose lookup is in lookups, unless a
legal hold is placed on chain: None when one is, with nothing
deleted; otherwise the sid of each key deleted. All or nothing, and
the hold is read atomically with the deletion, as
delete_through_unless_held
reads it. Read moreSource§fn is_process_local(&self) -> bool
fn is_process_local(&self) -> bool
Source§impl Clone for PostgresAuditStore
impl Clone for PostgresAuditStore
Source§fn clone(&self) -> PostgresAuditStore
fn clone(&self) -> PostgresAuditStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for PostgresAuditStore
impl !UnwindSafe for PostgresAuditStore
impl Forget for PostgresAuditStore
impl Freeze for PostgresAuditStore
impl Move for PostgresAuditStore
impl Send for PostgresAuditStore
impl Sync for PostgresAuditStore
impl Unpin for PostgresAuditStore
impl UnsafeUnpin for PostgresAuditStore
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].