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 projects;
25pub mod pull;
26pub mod render;
27pub mod rules;
28pub mod target;
29pub mod transport;
30pub mod tree;
31pub mod uuid;
32pub mod verify;
33pub mod yamlio;
34
35/// Why `name` is not a safe single path component, or `None` when it is.
36///
37/// Used before any path is built from a declared name (`target.gateway`,
38/// `target.mode`, tag providers, type halves), so a hostile value cannot
39/// walk out of its directory (T-21-12). Refuses: empty, `.`, `..`, any `/`,
40/// `\` or NUL, and any dot-leading name.
41pub fn component_problem(name: &str) -> Option<&'static str> {
42    if name.is_empty() {
43        Some("must not be empty")
44    } else if name == "." || name == ".." {
45        Some("must not be `.` or `..`")
46    } else if name.contains('/') || name.contains('\\') {
47        Some("must not contain a path separator")
48    } else if name.contains('\0') {
49        Some("must not contain a NUL byte")
50    } else if name.starts_with('.') {
51        Some("must not start with `.`")
52    } else {
53        None
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::component_problem;
60
61    #[test]
62    fn safe_names_pass() {
63        for ok in ["prod", "gw-1", "my_gateway", "a.b", "Ignition 8"] {
64            assert_eq!(component_problem(ok), None, "{ok}");
65        }
66    }
67
68    #[test]
69    fn unsafe_names_are_refused() {
70        for bad in [
71            "", ".", "..", "a/b", "a\\b", "a\0b", ".hidden", "../x", "/abs",
72        ] {
73            assert!(component_problem(bad).is_some(), "{bad:?}");
74        }
75    }
76}