Skip to main content

ignition_core/deploy/
mod.rs

1//! Offline render of declared gateway trees (Phase 21).
2//!
3//! Invariants every `deploy` module keeps:
4//! - **Pure and offline.** No network, no profile, no [`crate::session::Session`].
5//!   Functions take bytes (or an injected file set) and return models.
6//! - **Deterministic.** Ordered collections only, no clock reads, no
7//!   randomness, no dependence on directory iteration order. The same
8//!   input yields the same output or the same error.
9//! - **Core never prints.** Findings ride [`crate::error::CoreError`]; the
10//!   binary renders them.
11
12pub mod apply;
13pub mod exclude;
14pub mod layout;
15pub mod ledger;
16pub mod lint;
17pub mod manifest;
18pub mod node;
19#[cfg(any(windows, test))]
20pub(crate) mod owner_acl;
21pub mod pair;
22pub mod plan;
23pub mod project_artifact;
24pub mod project_tags;
25pub mod projects;
26pub mod pull;
27pub mod render;
28pub mod rules;
29pub mod target;
30pub mod transport;
31pub mod tree;
32pub mod uuid;
33pub mod verify;
34pub mod yamlio;
35
36/// Why `name` is not a safe single path component, or `None` when it is.
37///
38/// Used before any path is built from a declared name (`target.gateway`,
39/// `target.mode`, tag providers, type halves), so a hostile value cannot
40/// walk out of its directory (T-21-12). Refuses: empty, `.`, `..`, any `/`,
41/// `\` or NUL, and any dot-leading name.
42pub fn component_problem(name: &str) -> Option<&'static str> {
43    if name.is_empty() {
44        Some("must not be empty")
45    } else if name == "." || name == ".." {
46        Some("must not be `.` or `..`")
47    } else if name.contains('/') || name.contains('\\') {
48        Some("must not contain a path separator")
49    } else if name.contains('\0') {
50        Some("must not contain a NUL byte")
51    } else if name.starts_with('.') {
52        Some("must not start with `.`")
53    } else {
54        None
55    }
56}
57
58#[cfg(test)]
59mod tests {
60    use super::component_problem;
61
62    #[test]
63    fn safe_names_pass() {
64        for ok in ["prod", "gw-1", "my_gateway", "a.b", "Ignition 8"] {
65            assert_eq!(component_problem(ok), None, "{ok}");
66        }
67    }
68
69    #[test]
70    fn unsafe_names_are_refused() {
71        for bad in [
72            "", ".", "..", "a/b", "a\\b", "a\0b", ".hidden", "../x", "/abs",
73        ] {
74            assert!(component_problem(bad).is_some(), "{bad:?}");
75        }
76    }
77}