pub struct Partitions { /* private fields */ }Expand description
The partition table and its crossings (spec 3.2 §7.8): reads and changes partitions
with kernel.partition.created and kernel.partition.changed records, builds each
partition’s PartitionPolicy, and keeps the crossing ledger the policy and the crossing
tools write and the run’s approvals are read from. Cloning shares it.
§Example
use adk_core::audit_log::AuditActor;
use adk_kernel::{CrossPartition, Partition, Partitions};
let partitions = Partitions::in_memory();
let by = AuditActor::default();
partitions.put(Partition::new("home", "home").with_cross_partition(CrossPartition::CoordinatorWithApproval), by.clone()).await?;
partitions.put(Partition::new("work", "work").with_cross_partition(CrossPartition::CoordinatorWithApproval), by.clone()).await?;
let home = partitions.block("home", "work", by).await?;
assert!(home.blocked_crossings.contains(&"work".into()));Implementations§
Source§impl Partitions
impl Partitions
Sourcepub fn new(store: Arc<dyn PartitionStore>) -> Self
pub fn new(store: Arc<dyn PartitionStore>) -> Self
The partitions in store.
Sourcepub fn in_memory() -> Self
pub fn in_memory() -> Self
The partitions in a new InMemoryPartitionStore.
Sourcepub fn with_audit(self, trail: AuditTrail) -> Self
pub fn with_audit(self, trail: AuditTrail) -> Self
Writes the partition and crossing records to trail (spec 3.2 §9.3).
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
Reads crossing times from clock instead of the system clock.
Sourcepub fn attach_audit(&self, trail: AuditTrail)
pub fn attach_audit(&self, trail: AuditTrail)
Sets the audit trail when none is set yet; the kernel attaches its own at build.
Sourcepub fn store(&self) -> &Arc<dyn PartitionStore> ⓘ
pub fn store(&self) -> &Arc<dyn PartitionStore> ⓘ
The store.
Sourcepub async fn put(&self, partition: Partition, by: AuditActor) -> Result<()>
pub async fn put(&self, partition: Partition, by: AuditActor) -> Result<()>
Creates or changes partition, recording kernel.partition.created or
kernel.partition.changed with the fields that changed.
§Errors
Returns KernelError::Config when the record is invalid, or the store’s error.
Sourcepub async fn set_mode(
&self,
id: impl Into<PartitionId>,
mode: PartitionMode,
by: AuditActor,
) -> Result<Partition>
pub async fn set_mode( &self, id: impl Into<PartitionId>, mode: PartitionMode, by: AuditActor, ) -> Result<Partition>
Sets the mode of partition id.
§Errors
Returns a 404 error when there is no such partition, or the store’s error.
Sourcepub async fn block(
&self,
from: impl Into<PartitionId>,
to: impl Into<PartitionId>,
by: AuditActor,
) -> Result<Partition>
pub async fn block( &self, from: impl Into<PartitionId>, to: impl Into<PartitionId>, by: AuditActor, ) -> Result<Partition>
Blocks crossings from from into to: the prompt’s “deny and block crossings to
to from this partition”. The block stays until the partition record is changed.
§Errors
Returns a 404 error when from is not a partition, or the store’s error.
Sourcepub async fn crossings(
&self,
filter: &CrossingFilter,
) -> Result<Vec<CrossingRecord>>
pub async fn crossings( &self, filter: &CrossingFilter, ) -> Result<Vec<CrossingRecord>>
Sourcepub fn policy(&self, home: impl Into<PartitionId>) -> PartitionPolicy
pub fn policy(&self, home: impl Into<PartitionId>) -> PartitionPolicy
The policy of partition home’s harness (PartitionPolicy).
Sourcepub async fn admit(
&self,
crossing: &Crossing,
coordinator: bool,
) -> Result<(), String>
pub async fn admit( &self, crossing: &Crossing, coordinator: bool, ) -> Result<(), String>
Why crossing may not happen, or Ok when it may ask for approval: both
partitions exist and take part in crossings, the caller is the coordinator, and the
source has not blocked the target (spec 3.2 §7.8, K-I15).
§Errors
The refusal’s reason, also when the partition table cannot be read: a crossing fails closed.
Sourcepub async fn granted(&self, run: &CrossingRun, fingerprint: &str) -> bool
pub async fn granted(&self, run: &CrossingRun, fingerprint: &str) -> bool
Whether the read fingerprint (a Crossing::fingerprint) was approved earlier in
run and the run still holds the grant, so the coordinator’s identical read needs no
approval for the rest of the run (spec 3.2 §13 Q3). A failed read of the store answers
false: the crossing asks again.
Sourcepub async fn release_run(&self, run: &CrossingRun) -> Result<u64>
pub async fn release_run(&self, run: &CrossingRun) -> Result<u64>
Drops every grant of run, which finished, so no later run can reuse one (spec 3.2
§13 Q3): the kernel’s worker calls it when a durable run ends, the partition’s
harness when an invocation outside a durable run ends. Answers how many it dropped.
§Errors
Returns the store’s error for a durable run.
Sourcepub async fn executed(
&self,
crossing: &Crossing,
fingerprint: &str,
run: &CrossingRun,
agent: &str,
tool: &str,
) -> Result<()>
pub async fn executed( &self, crossing: &Crossing, fingerprint: &str, run: &CrossingRun, agent: &str, tool: &str, ) -> Result<()>
Records that crossing ran in run after its approval, and, for a read, keeps the
approval the coordinator’s identical reads reuse for the rest of the run. A write is
never kept: it is approved one call at a time. A crossing tool calls it after the
governed path authorized the call.
§Errors
Returns the store’s error; the tool then reports the crossing unrecorded.
Sourcepub async fn recurring_crossings(
&self,
since: DateTime<Utc>,
at_least: usize,
) -> Result<Vec<RecurringCrossing>>
pub async fn recurring_crossings( &self, since: DateTime<Utc>, at_least: usize, ) -> Result<Vec<RecurringCrossing>>
The crossings since since that recur at least at_least times, by source, target,
resource and name, most frequent first (spec 3.2 §7.8): what the maintenance process
reports, with partition membership as the remedy. A request counts once: held, denied,
or let through by its run’s approval; the approval of a held request is not counted
again.
§Errors
Returns the store’s error.
Trait Implementations§
Source§impl Clone for Partitions
impl Clone for Partitions
Auto Trait Implementations§
impl !RefUnwindSafe for Partitions
impl !UnwindSafe for Partitions
impl Forget for Partitions
impl Freeze for Partitionswhere
*const ArcInner<PartitionsInner> is !null: Freeze,
PhantomData<ArcInner<PartitionsInner>>: Freeze,
impl Move for Partitions
impl Send for Partitions
impl Sync for Partitions
impl Unpin for Partitions
impl UnsafeUnpin for Partitionswhere
*const ArcInner<PartitionsInner> is !null: UnsafeUnpin,
PhantomData<ArcInner<PartitionsInner>>: UnsafeUnpin,
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,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.