#[cfg(feature = "postgres")]
mod postgres;
#[cfg(feature = "postgres")]
mod postgres_authority;
#[cfg(feature = "postgres")]
mod postgres_cases;
#[cfg(feature = "postgres")]
mod postgres_disclosures;
#[cfg(feature = "postgres")]
mod postgres_memory;
#[cfg(all(feature = "postgres", feature = "push"))]
mod postgres_push;
#[cfg(feature = "postgres")]
mod postgres_quota;
#[cfg(all(feature = "postgres", feature = "manifest"))]
mod postgres_registry;
#[cfg(feature = "redb")]
mod redb;
#[cfg(feature = "redb")]
mod redb_authority;
#[cfg(feature = "redb")]
mod redb_batches;
#[cfg(feature = "redb")]
mod redb_cases;
#[cfg(feature = "redb")]
mod redb_disclosures;
#[cfg(feature = "redb")]
mod redb_events;
#[cfg(feature = "redb")]
mod redb_memory;
#[cfg(all(feature = "redb", feature = "push"))]
mod redb_push;
#[cfg(feature = "redb")]
mod redb_quota;
#[cfg(all(feature = "redb", feature = "manifest"))]
mod redb_registry;
#[cfg(feature = "redb")]
mod redb_tasks;
#[cfg(feature = "redb")]
mod redb_timers;
#[cfg(feature = "postgres")]
pub use postgres::PostgresStore;
#[cfg(feature = "redb")]
pub use redb::RedbStore;
pub(crate) fn decode_operator(
actor: &str,
basis: &str,
table: &str,
) -> Result<crate::core::Operator, crate::core::StoreError> {
crate::core::Operator::from_parts(actor, basis).map_err(|e| crate::core::StoreError::Corrupt {
seq: 0,
detail: format!("{table} holds an act this build cannot attribute: {e}"),
})
}
#[derive(serde::Serialize, serde::Deserialize)]
pub(crate) struct HaltRow {
pub reason: String,
pub by: crate::core::Operator,
#[serde(with = "time::serde::rfc3339")]
pub at: crate::core::Timestamp,
}
#[derive(serde::Serialize, serde::Deserialize)]
pub(crate) struct HoldRow {
pub reason: String,
pub by: crate::core::Operator,
}
pub(crate) fn halt_from_row(scope: crate::quota::HaltScope, row: HaltRow) -> crate::quota::Halt {
crate::quota::Halt {
scope,
reason: row.reason,
by: row.by,
at: row.at,
}
}
#[cfg(feature = "redb")]
pub(crate) fn hold_row(h: &crate::core::LegalHold) -> HoldRow {
HoldRow {
reason: h.reason.clone(),
by: h.by.clone(),
}
}
pub(crate) fn hold_from_row(
placed_at: crate::core::Timestamp,
row: HoldRow,
) -> crate::core::LegalHold {
crate::core::LegalHold {
placed_at,
reason: row.reason,
by: row.by,
}
}
#[cfg(any(feature = "redb", feature = "postgres"))]
fn stored_verdict(score: &crate::core::Score) -> (&'static str, &str, f64) {
match score {
crate::core::Score::Pass(true) => ("pass", "", 0.0),
crate::core::Score::Pass(false) => ("fail", "", 0.0),
crate::core::Score::Label(label) => ("label", label.as_str(), 0.0),
crate::core::Score::Number(n) => ("number", "", *n),
}
}
#[cfg(any(feature = "redb", feature = "postgres"))]
fn count_stored(
summary: &mut crate::core::MetricSummary,
kind: &str,
label: &str,
count: u64,
numbers: (f64, f64, f64),
) -> Result<(), crate::core::StoreError> {
match kind {
"pass" => summary.passed += count,
"fail" => summary.failed += count,
"label" => *summary.labels.entry(label.to_owned()).or_default() += count,
"number" => {
let (sum, min, max) = numbers;
let these = crate::core::NumberSummary::new(count, sum, min, max);
match &mut summary.numbers {
Some(held) => held.merge(&these),
None => summary.numbers = Some(these),
}
}
other => {
return Err(crate::core::StoreError::Corrupt {
seq: 0,
detail: format!("run_verdict holds a verdict of unknown kind '{other}'"),
});
}
}
Ok(())
}