qemu_command_builder/
sandbox.rs

1use crate::common::OnOff;
2use crate::to_command::{ToArg, ToCommand};
3use bon::Builder;
4
5pub enum AllowDeny {
6    Allow,
7    Deny,
8}
9
10impl ToArg for AllowDeny {
11    fn to_arg(&self) -> &str {
12        match self {
13            AllowDeny::Allow => "allow",
14            AllowDeny::Deny => "deny",
15        }
16    }
17}
18pub enum AllowDenyChildren {
19    Allow,
20    Deny,
21    Children,
22}
23
24impl ToArg for AllowDenyChildren {
25    fn to_arg(&self) -> &str {
26        match self {
27            AllowDenyChildren::Allow => "allow",
28            AllowDenyChildren::Deny => "deny",
29            AllowDenyChildren::Children => "children",
30        }
31    }
32}
33#[derive(Builder)]
34pub struct Sandbox {
35    mode: OnOff,
36    obsolete: Option<AllowDeny>,
37    elevateprivileges: Option<AllowDenyChildren>,
38    spawn: Option<AllowDeny>,
39    resourcecontrol: Option<AllowDeny>,
40}
41
42impl ToCommand for Sandbox {
43    fn to_command(&self) -> Vec<String> {
44        let mut cmd = vec!["-sandbox".to_string()];
45
46        let mut args = vec![];
47        match &self.mode {
48            OnOff::On => {
49                args.push("on".to_string());
50            }
51            OnOff::Off => {
52                args.push("off".to_string());
53            }
54        }
55
56        if let Some(obsolete) = &self.obsolete {
57            args.push(obsolete.to_arg().to_string());
58        }
59        if let Some(elevateprivileges) = &self.elevateprivileges {
60            args.push(format!("elevateprivileges={}", elevateprivileges.to_arg()))
61        }
62        if let Some(spawn) = &self.spawn {
63            args.push(format!("spawn={}", spawn.to_arg()));
64        }
65        if let Some(resourcecontrol) = &self.resourcecontrol {
66            args.push(format!("resourcecontrol={}", resourcecontrol.to_arg()));
67        }
68
69        cmd.push(args.join(","));
70        cmd
71    }
72}