use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use uuid::Uuid;
use crate::entities::User;
mod api_key_store;
mod audit_log_store;
mod run_store;
mod secret_store;
mod user_store;
#[derive(Debug, Default)]
pub(super) struct State {
pub(super) runs: HashMap<Uuid, crate::entities::Run>,
pub(super) steps: HashMap<Uuid, crate::entities::Step>,
pub(super) step_dependencies: Vec<crate::entities::StepDependency>,
pub(super) users: HashMap<Uuid, User>,
pub(super) api_keys: HashMap<Uuid, crate::entities::ApiKey>,
pub(super) secrets: HashMap<String, EncryptedSecret>,
pub(super) audit_logs: Vec<crate::entities::AuditLogEntry>,
}
#[derive(Debug, Clone)]
pub(super) struct EncryptedSecret {
pub(super) id: Uuid,
pub(super) key: String,
#[cfg(feature = "secret-store")]
pub(super) encrypted_value: Vec<u8>,
#[cfg(feature = "secret-store")]
pub(super) nonce: Vec<u8>,
pub(super) created_at: chrono::DateTime<chrono::Utc>,
pub(super) updated_at: chrono::DateTime<chrono::Utc>,
}
#[derive(Debug, Clone)]
pub struct InMemoryStore {
pub(super) state: Arc<RwLock<State>>,
#[cfg(feature = "secret-store")]
pub(super) master_key: Option<Arc<crate::crypto::MasterKey>>,
}
impl InMemoryStore {
pub fn new() -> Self {
Self {
state: Arc::new(RwLock::new(State::default())),
#[cfg(feature = "secret-store")]
master_key: None,
}
}
#[cfg(feature = "secret-store")]
pub fn set_master_key(&mut self, key: crate::crypto::MasterKey) {
self.master_key = Some(Arc::new(key));
}
}
impl Default for InMemoryStore {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use serde_json::json;
use crate::entities::{NewRun, TriggerKind};
pub(crate) fn new_run_req(name: &str) -> NewRun {
NewRun {
workflow_name: name.to_string(),
trigger: TriggerKind::Manual,
payload: json!({}),
max_retries: 3,
handler_version: None,
labels: HashMap::new(),
scheduled_at: None,
}
}
}