greentic_component_runtime/
policy.rs1use std::collections::HashMap;
2use std::sync::{Arc, Mutex};
3
4use greentic_component_store::ComponentStore;
5use greentic_component_store::VerificationPolicy;
6
7#[derive(Debug, Clone)]
8pub struct HostPolicy {
9 pub allow_http_fetch: bool,
10 pub allow_telemetry: bool,
11 pub allow_state_read: bool,
12 pub allow_state_write: bool,
13 pub allow_state_delete: bool,
14 pub state_store: Arc<Mutex<HashMap<String, Vec<u8>>>>,
15}
16
17impl Default for HostPolicy {
18 fn default() -> Self {
19 Self {
20 allow_http_fetch: false,
21 allow_telemetry: true,
22 allow_state_read: false,
23 allow_state_write: false,
24 allow_state_delete: false,
25 state_store: Arc::new(Mutex::new(HashMap::new())),
26 }
27 }
28}
29
30#[derive(Debug, Clone)]
31pub struct LoadPolicy {
32 pub store: Arc<ComponentStore>,
33 pub verification: VerificationPolicy,
34 pub host: HostPolicy,
35}
36
37impl LoadPolicy {
38 pub fn new(store: Arc<ComponentStore>) -> Self {
39 Self {
40 store,
41 verification: VerificationPolicy::default(),
42 host: HostPolicy::default(),
43 }
44 }
45
46 pub fn with_verification(mut self, policy: VerificationPolicy) -> Self {
47 self.verification = policy;
48 self
49 }
50
51 pub fn with_host_policy(mut self, host: HostPolicy) -> Self {
52 self.host = host;
53 self
54 }
55}