Skip to main content

podbox/config/
defaults.rs

1use std::collections::HashMap;
2
3use crate::config::enums::{GpuMode, OnStop, PackageManager};
4use crate::config::types::{
5    HostExecConfig, LifecycleConfig, NetworkConfig, PackageConfig, RunConfig, SecurityConfig,
6    SystemdConfig,
7};
8
9pub const EMBEDDED_DEFAULT: &str = r#"
10[image]
11base = "fedora:44"
12name = "podbox"
13
14[container]
15    name = "podbox"
16home = "~/containers/podbox"
17"#;
18
19pub fn default_true() -> bool {
20    true
21}
22
23pub fn is_true(v: &bool) -> bool {
24    *v
25}
26
27pub fn is_false(v: &bool) -> bool {
28    !*v
29}
30
31pub fn default_shell() -> String {
32    "fish".into()
33}
34
35pub fn is_default_shell(v: &str) -> bool {
36    v == "fish"
37}
38
39pub fn default_package_manager() -> PackageManager {
40    PackageManager::Dnf
41}
42
43pub fn is_default_pkg_mgr(v: &PackageManager) -> bool {
44    *v == PackageManager::Dnf
45}
46
47pub fn default_pull_retry() -> u32 {
48    3
49}
50
51pub fn is_default_pull_retry(v: &u32) -> bool {
52    *v == 3
53}
54
55pub fn default_pull_retry_delay() -> String {
56    "5s".into()
57}
58
59pub fn is_default_pull_retry_delay(v: &str) -> bool {
60    v == "5s"
61}
62
63pub fn is_empty_hashmap(v: &HashMap<String, String>) -> bool {
64    v.is_empty()
65}
66
67pub fn is_default_mounts(v: &super::types::MountConfig) -> bool {
68    v.extra.is_empty()
69}
70
71pub fn is_default_gpu(v: &GpuMode) -> bool {
72    *v == GpuMode::Auto
73}
74
75pub fn is_default_packages(v: &PackageConfig) -> bool {
76    v.install.is_empty() && v.remove.is_empty() && v.manager == PackageManager::Dnf
77}
78
79pub fn is_default_run(v: &RunConfig) -> bool {
80    v.commands.is_empty()
81}
82
83pub fn is_default_host_exec(v: &HostExecConfig) -> bool {
84    !v.enabled && v.allowlist.is_none()
85}
86
87pub fn default_idle_timeout() -> String {
88    "off".to_string()
89}
90
91pub fn is_default_idle_timeout(v: &str) -> bool {
92    v == "off"
93}
94
95pub fn is_default_lifecycle(v: &LifecycleConfig) -> bool {
96    !v.quadlet
97        && !v.autostart
98        && v.on_stop == OnStop::Keep
99        && !v.auto_update
100        && v.idle_timeout == "off"
101}
102
103pub fn is_default_systemd(v: &SystemdConfig) -> bool {
104    v.requires.is_empty() && v.after.is_empty()
105}
106
107pub fn is_default_dbus(v: &super::types::DbusConfig) -> bool {
108    v.preset.is_empty() && v.talk.is_empty() && v.own.is_empty()
109}
110
111pub fn is_default_security(v: &SecurityConfig) -> bool {
112    v.apparmor.is_none()
113        && v.seccomp.is_none()
114        && v.security_label_disable
115        && v.no_new_privileges
116        && !v.read_only_rootfs
117        && v.userns.is_none()
118}
119
120pub fn default_network_mode() -> String {
121    "private".into()
122}
123
124pub fn is_default_network(v: &NetworkConfig) -> bool {
125    v.mode == "private" && v.ports.is_empty()
126}