1use std::collections::HashMap;
5use std::fmt;
6use std::sync::Arc;
7use std::time::Duration;
8
9use greentic_types::TenantCtx;
10
11use crate::store::ToolStore;
12
13#[derive(Clone)]
15pub struct ExecConfig {
16 pub store: ToolStore,
17 pub security: VerifyPolicy,
18 pub runtime: RuntimePolicy,
19 pub http_enabled: bool,
20 pub secrets_store: Option<DynSecretsStore>,
23}
24
25#[derive(Clone, Debug, Default)]
27pub struct VerifyPolicy {
28 pub allow_unverified: bool,
30 pub required_digests: HashMap<String, String>,
32 pub trusted_signers: Vec<String>,
34}
35
36#[derive(Clone, Debug)]
38pub struct RuntimePolicy {
39 pub fuel: Option<u64>,
40 pub max_memory: Option<u64>,
41 pub wallclock_timeout: Duration,
42 pub per_call_timeout: Duration,
43 pub max_attempts: u32,
44 pub base_backoff: Duration,
45}
46
47impl Default for RuntimePolicy {
48 fn default() -> Self {
49 Self {
50 fuel: None,
51 max_memory: None,
52 wallclock_timeout: Duration::from_secs(30),
53 per_call_timeout: Duration::from_secs(10),
54 max_attempts: 1,
55 base_backoff: Duration::from_millis(100),
56 }
57 }
58}
59
60pub trait SecretsStore: Send + Sync {
62 fn read(&self, scope: &TenantCtx, name: &str) -> Result<Vec<u8>, String>;
64
65 fn write(&self, scope: &TenantCtx, name: &str, bytes: &[u8]) -> Result<(), String> {
67 let _ = (scope, name, bytes);
68 Err("write-not-implemented".into())
69 }
70
71 fn delete(&self, scope: &TenantCtx, name: &str) -> Result<(), String> {
73 let _ = (scope, name);
74 Err("delete-not-implemented".into())
75 }
76}
77
78pub type DynSecretsStore = Arc<dyn SecretsStore>;
80
81impl fmt::Debug for ExecConfig {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 f.debug_struct("ExecConfig")
84 .field("store", &self.store)
85 .field("security", &self.security)
86 .field("runtime", &self.runtime)
87 .field("http_enabled", &self.http_enabled)
88 .field(
89 "secrets_store",
90 &self.secrets_store.as_ref().map(|_| "<dyn SecretsStore>"),
91 )
92 .finish()
93 }
94}