1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use fce::HostImportDescriptor;
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::PathBuf;
#[derive(Default)]
pub struct FaaSConfig {
pub modules_dir: Option<PathBuf>,
pub modules_config: Vec<(String, FaaSModuleConfig)>,
pub default_modules_config: Option<FaaSModuleConfig>,
}
#[derive(Default)]
pub struct FaaSModuleConfig {
pub mem_pages_count: Option<u32>,
pub logger_enabled: bool,
pub host_imports: HashMap<String, HostImportDescriptor>,
pub wasi: Option<FaaSWASIConfig>,
pub logging_mask: i64,
}
impl FaaSModuleConfig {
pub fn extend_wasi_envs(&mut self, new_envs: HashMap<Vec<u8>, Vec<u8>>) {
match &mut self.wasi {
Some(FaaSWASIConfig { envs, .. }) => envs.extend(new_envs),
w @ None => {
*w = Some(FaaSWASIConfig {
envs: new_envs,
preopened_files: HashSet::new(),
mapped_dirs: HashMap::new(),
})
}
};
}
pub fn extend_wasi_files(
&mut self,
new_preopened_files: HashSet<PathBuf>,
new_mapped_dirs: HashMap<String, PathBuf>,
) {
match &mut self.wasi {
Some(FaaSWASIConfig {
preopened_files,
mapped_dirs,
..
}) => {
preopened_files.extend(new_preopened_files);
mapped_dirs.extend(new_mapped_dirs);
}
w @ None => {
*w = Some(FaaSWASIConfig {
envs: HashMap::new(),
preopened_files: new_preopened_files,
mapped_dirs: new_mapped_dirs,
})
}
};
}
}
#[derive(Debug, Clone, Default)]
pub struct FaaSWASIConfig {
pub envs: HashMap<Vec<u8>, Vec<u8>>,
pub preopened_files: HashSet<PathBuf>,
pub mapped_dirs: HashMap<String, PathBuf>,
}