start_command/
isolation_metadata.rs1use crate::args_parser::WrapperOptions;
11use std::collections::HashMap;
12
13pub fn docker_runtime_status_lines(
17 volumes: &[String],
18 mounts: &[String],
19 env: &[String],
20 privileged: bool,
21) -> Vec<String> {
22 let mut lines = Vec::new();
23 if !volumes.is_empty() {
24 lines.push(format!("[Isolation] Volumes: {}", volumes.join(", ")));
25 }
26 if !mounts.is_empty() {
27 lines.push(format!("[Isolation] Mounts: {}", mounts.join(", ")));
28 }
29 if !env.is_empty() {
30 lines.push(format!("[Isolation] Env: {}", env.join(", ")));
31 }
32 if privileged {
33 lines.push("[Isolation] Privileged: true".to_string());
34 }
35 lines
36}
37
38pub fn docker_runtime_metadata(
42 volumes: &[String],
43 mounts: &[String],
44 env: &[String],
45 privileged: bool,
46) -> Vec<(String, serde_json::Value)> {
47 let arr = |items: &[String]| {
48 serde_json::Value::Array(
49 items
50 .iter()
51 .map(|s| serde_json::Value::String(s.clone()))
52 .collect(),
53 )
54 };
55 let mut entries = Vec::new();
56 if !volumes.is_empty() {
57 entries.push(("volumes".to_string(), arr(volumes)));
58 }
59 if !mounts.is_empty() {
60 entries.push(("mounts".to_string(), arr(mounts)));
61 }
62 if !env.is_empty() {
63 entries.push(("env".to_string(), arr(env)));
64 }
65 if privileged {
66 entries.push(("privileged".to_string(), serde_json::Value::Bool(true)));
67 }
68 entries
69}
70
71pub fn build_isolation_options_map(
76 environment: Option<&str>,
77 mode: &str,
78 session_name: &str,
79 effective_image: Option<&str>,
80 options: &WrapperOptions,
81 created_user: Option<&str>,
82) -> HashMap<String, serde_json::Value> {
83 let str_val = |s: &str| serde_json::Value::String(s.to_string());
84 let mut opts_map = HashMap::new();
85 if let Some(env) = environment {
86 opts_map.insert("isolated".to_string(), str_val(env));
87 }
88 opts_map.insert("isolationMode".to_string(), str_val(mode));
89 opts_map.insert("sessionName".to_string(), str_val(session_name));
90 if let Some(v) = effective_image {
91 opts_map.insert("image".to_string(), str_val(v));
92 }
93 for (k, v) in docker_runtime_metadata(
94 &options.volumes,
95 &options.mounts,
96 &options.env,
97 options.privileged,
98 ) {
99 opts_map.insert(k, v);
100 }
101 if let Some(v) = &options.endpoint {
102 opts_map.insert("endpoint".to_string(), str_val(v));
103 }
104 if let Some(v) = created_user {
105 opts_map.insert("user".to_string(), str_val(v));
106 }
107 opts_map.insert(
108 "keepAlive".to_string(),
109 serde_json::Value::Bool(options.keep_alive),
110 );
111 opts_map.insert(
112 "autoRemoveDockerContainer".to_string(),
113 serde_json::Value::Bool(options.auto_remove_docker_container),
114 );
115 opts_map.insert(
116 "alwaysCleanupContainer".to_string(),
117 serde_json::Value::Bool(options.always_cleanup_container),
118 );
119 opts_map.insert(
120 "keepContainer".to_string(),
121 serde_json::Value::Bool(options.keep_container),
122 );
123 opts_map.insert(
124 "keepContainerOnFail".to_string(),
125 serde_json::Value::Bool(options.keep_container_on_fail),
126 );
127 opts_map
128}
129
130#[cfg(test)]
131#[path = "isolation_metadata_cases.rs"]
132mod tests;