#![forbid(unsafe_code)]
pub mod chain;
use serde_json::Value;
#[derive(Debug)]
pub struct PutOutcome {
pub id: String,
pub version_id: i64,
pub created: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Audit {
pub actor: String,
pub actor_source: Option<String>,
pub client: Option<String>,
pub request_id: Option<String>,
pub reason: Option<String>,
}
impl Default for Audit {
fn default() -> Self {
Self::unattributed()
}
}
impl Audit {
#[must_use]
pub fn unattributed() -> Self {
Audit {
actor: "unauthenticated".to_string(),
actor_source: None,
client: None,
request_id: None,
reason: None,
}
}
#[must_use]
pub fn cli() -> Self {
let who = std::env::var("USER")
.or_else(|_| std::env::var("USERNAME"))
.unwrap_or_else(|_| "unknown".to_string());
Audit {
actor: format!("cli:{who}"),
actor_source: Some("cli".to_string()),
client: None,
request_id: None,
reason: None,
}
}
#[must_use]
pub fn principal(actor: impl Into<String>, source: impl Into<String>) -> Self {
Audit {
actor: actor.into(),
actor_source: Some(source.into()),
client: None,
request_id: None,
reason: None,
}
}
#[must_use]
pub fn with_client(mut self, client: Option<String>) -> Self {
self.client = client;
self
}
#[must_use]
pub fn with_request_id(mut self, request_id: Option<String>) -> Self {
self.request_id = request_id;
self
}
#[must_use]
pub fn with_reason(mut self, reason: Option<String>) -> Self {
self.reason = reason;
self
}
}
#[derive(Debug, Clone)]
pub struct AccessRecord {
pub audit: Audit,
pub interaction: String,
pub rtype: Option<String>,
pub id: Option<String>,
pub version_id: Option<i64>,
pub outcome: String,
pub result_count: Option<i64>,
}
#[derive(Debug, PartialEq, Eq)]
pub struct PurgeReport {
pub versions_erased: u64,
pub existed: bool,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct ChainBreak {
pub rtype: String,
pub id: String,
pub version_id: i64,
pub algorithm: &'static str,
pub detail: String,
}
impl ChainBreak {
#[must_use]
pub fn new(
rtype: impl Into<String>,
id: impl Into<String>,
version_id: i64,
algorithm: &'static str,
detail: impl Into<String>,
) -> Self {
Self {
rtype: rtype.into(),
id: id.into(),
version_id,
algorithm,
detail: detail.into(),
}
}
}
#[derive(Debug)]
pub struct UpgradeReport {
pub additive: usize,
pub destructive: usize,
pub folded: usize,
pub reshredded: usize,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct UpgradeOpts {
pub allow_destructive: bool,
pub reshred_moved: bool,
}
#[derive(Debug)]
pub struct SearchOutcome {
pub ids: Vec<String>,
pub total: Option<i64>,
}
#[derive(Debug)]
pub enum CondCreate {
Created(PutOutcome),
Existing(String),
Multiple,
}
#[derive(Debug, PartialEq, Eq)]
pub enum CondDelete {
Deleted,
NoMatch,
Multiple,
}
#[derive(Debug)]
pub struct Got {
pub resource: Value,
pub version_id: i64,
}
#[derive(Debug)]
pub enum TxOp {
Put {
resource: Value,
expected: Option<i64>,
},
Delete {
rtype: String,
id: String,
},
}
#[derive(Debug)]
pub enum TxOutcome {
Put(PutOutcome),
Delete(bool),
}
#[derive(Debug, PartialEq, Eq)]
pub enum ResourceStatus {
Active(i64),
Deleted(i64),
Unknown,
}
#[derive(Debug)]
pub struct HistEntry {
pub version_id: i64,
pub last_updated: String,
pub op: char,
pub resource: Option<Value>,
}