use std::collections::HashMap;
use std::fmt;
use std::sync::Arc;
use std::time::Duration;
use greentic_types::TenantCtx;
use crate::store::ToolStore;
#[derive(Clone)]
pub struct ExecConfig {
pub store: ToolStore,
pub security: VerifyPolicy,
pub runtime: RuntimePolicy,
pub http_enabled: bool,
pub secrets_store: Option<DynSecretsStore>,
}
#[derive(Clone, Debug, Default)]
pub struct VerifyPolicy {
pub allow_unverified: bool,
pub required_digests: HashMap<String, String>,
pub trusted_signers: Vec<String>,
}
#[derive(Clone, Debug)]
pub struct RuntimePolicy {
pub fuel: Option<u64>,
pub max_memory: Option<u64>,
pub wallclock_timeout: Duration,
pub per_call_timeout: Duration,
pub max_attempts: u32,
pub base_backoff: Duration,
}
impl Default for RuntimePolicy {
fn default() -> Self {
Self {
fuel: None,
max_memory: None,
wallclock_timeout: Duration::from_secs(30),
per_call_timeout: Duration::from_secs(10),
max_attempts: 1,
base_backoff: Duration::from_millis(100),
}
}
}
pub trait SecretsStore: Send + Sync {
fn read(&self, scope: &TenantCtx, name: &str) -> Result<Vec<u8>, String>;
fn write(&self, scope: &TenantCtx, name: &str, bytes: &[u8]) -> Result<(), String> {
let _ = (scope, name, bytes);
Err("write-not-implemented".into())
}
fn delete(&self, scope: &TenantCtx, name: &str) -> Result<(), String> {
let _ = (scope, name);
Err("delete-not-implemented".into())
}
}
pub type DynSecretsStore = Arc<dyn SecretsStore>;
impl fmt::Debug for ExecConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExecConfig")
.field("store", &self.store)
.field("security", &self.security)
.field("runtime", &self.runtime)
.field("http_enabled", &self.http_enabled)
.field(
"secrets_store",
&self.secrets_store.as_ref().map(|_| "<dyn SecretsStore>"),
)
.finish()
}
}