diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.lock" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.lock" new file mode 100644 index 0000000000000000000000000000000000000000..79a5048fb0b1573d4b942e94aa178b431fa88de3 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.lock" @@ -0,0 +1,296 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "clap" +version = "4.5.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + +[[package]] +name = "parse-yaml" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "regex", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.toml" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.toml" new file mode 100644 index 0000000000000000000000000000000000000000..698527f1591740eed4616558630c1c992f2d4ecc --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/Cargo.toml" @@ -0,0 +1,9 @@ +[package] +name = "parse-yaml" +version = "0.1.0" +edition = "2021" + +[dependencies] +regex = "1" +anyhow = "1" +clap = { version = "4", features = ["derive"] } \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/README.md" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..2af1161825dac3d50e024bd0b8ae2492207dd98f --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/README.md" @@ -0,0 +1,30 @@ +# parse-yaml + +根据原始文件中的的conf_source,找到多行文本文件并插入原始文件 + + + +## 构建项目 + +``` +cd parse-yaml +cargo build --release +``` + + + +## 使用 + +`/path/to/parse-yaml -i /path/input.yaml -o /path/output.yaml` + +- -i, --input : 输入文件 +- -o, --output : 输出文件 + + + +## 示例 + +`./target/debug/parse-yaml -i ./test/input.yaml -o ./etc/output.yaml` + +`./target/release/parse-yaml -i ./test/test-ori.yaml -o ./etc/test-res.yaml` + diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/src/main.rs" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/src/main.rs" new file mode 100644 index 0000000000000000000000000000000000000000..af84954e9615e91635551c08e4835214a9d6f3e4 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/src/main.rs" @@ -0,0 +1,82 @@ +use std::fs; +use std::path::{Path, PathBuf}; +use anyhow::{Context, Result}; +use clap::Parser; +use regex::Regex; + +/// 命令行参数定义 +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// 输入 YAML 文件路径 + #[arg(short, long)] + input: PathBuf, + + /// 输出 YAML 文件路径 + #[arg(short, long)] + output: PathBuf, +} + +fn main() -> Result<()> { + let args = Args::parse(); + + // 读取 YAML 原始内容 + let content = fs::read_to_string(&args.input) + .with_context(|| format!("读取输入文件失败: {}", args.input.display()))?; + + // conf_source 的正则,捕获缩进和路径 + let conf_source_re = Regex::new(r"(?m)^(\s*)conf_source:\s*([^\s#]+)(?:\s*#.*)?$") + .expect("正则无效"); + + // 预先获取 base_dir,供闭包中使用 + let base_dir = args.input.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + + // 替换所有 conf_source + let result = conf_source_re + .replace_all(&content, move |caps: ®ex::Captures| { + let indent = &caps[1]; + let relative_path = caps[2].trim(); + // let full_path = base_dir.join(relative_path); + let full_path = { + let path = Path::new(relative_path); + if path.is_absolute() || relative_path.starts_with("./") { + PathBuf::from(relative_path) + } else if path.starts_with(&base_dir) { + path.to_path_buf() + } else { + base_dir.join(relative_path) + } + }; + + println!("{}", full_path.display()); + + let file_content = match fs::read_to_string(&full_path) { + Ok(text) => text, + Err(_) => { + eprintln!("无法读取文件: {}", full_path.display()); + return caps.get(0).unwrap().as_str().to_string(); + } + }; + // 构建 conf_para 块 + let formatted = format!( + "{}conf_para: |\n{}", + indent, + file_content + .lines() + .map(|line| format!("{} {}", indent, line)) + .collect::>() + .join("\n") + ); + // 原始 conf_source 行 + 新插入段 + let original_line = caps.get(0).unwrap().as_str(); + format!("{original_line}\n{formatted}") + }) + .into_owned(); + + // 写入结果文件 + fs::write(&args.output, result) + .with_context(|| format!("写入输出文件失败: {}", args.output.display()))?; + + println!("插入完成,输出写入:{}", args.output.display()); + Ok(()) +} \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/fire.service" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/fire.service" new file mode 100644 index 0000000000000000000000000000000000000000..462486714ddf18bb09ed5643d4cf8bbb9f6e1e56 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/fire.service" @@ -0,0 +1,11 @@ +[Unit] +Description=Firewall Daemon +After=network.target + +[Service] +ExecStart=/usr/sbin/firewalld --nofork --nopid +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/input.yaml" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/input.yaml" new file mode 100644 index 0000000000000000000000000000000000000000..4da0566dacf54f06f3a9ed2cdbc99fab026abf97 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/input.yaml" @@ -0,0 +1,28 @@ +filename: test-yaml +metadata: + name: test-metadata + namespace: default + +spec: + type: config + version: "1.0" + flag: true + osconfigs: | + files: + dbus: + conf_path: /etc/systemd/system/dbus.service + conf_source: ./test/my-dbus.service # test1 + conf_cmd: + - systemctl restart dbus + + ssh: + conf_path: /etc/ssh/sshd_config + conf_source: ./test/ssh.service # test2 + conf_cmd: + - systemctl restart sshd + + fire: + conf_path: /etc/firewalld/firewalld.conf + conf_source: ./test/fire.service ## test3 + conf_cmd: + - systemctl restart firewalld \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/my-dbus.service" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/my-dbus.service" new file mode 100644 index 0000000000000000000000000000000000000000..195b90d0b00e76ce827aae36d1d1c7620b79eff6 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/my-dbus.service" @@ -0,0 +1,22 @@ +[Unit] +Description=D-Bus System Message Bus +Documentation=man:dbus-broker-launch(1) +DefaultDependencies=false +After=dbus.socket +Before=basic.target shutdown.target +Requires=dbus.socket +Conflicts=shutdown.target + +[Service] +Type=notify +Sockets=dbus.socket +OOMScoreAdjust=-900 +LimitNOFILE=16384 +ProtectSystem=full +PrivateTmp=true +PrivateDevices=true +ExecStart=/usr/bin/dbus-broker-launch --scope system --audit +ExecReload=/usr/bin/busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig + +[Install] +Alias=dbus.service \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/output.yaml" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/output.yaml" new file mode 100644 index 0000000000000000000000000000000000000000..8a37d2e6a166d040218ff0c0400b848b4a510938 --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/output.yaml" @@ -0,0 +1,75 @@ +filename: test-yaml +metadata: + name: test-metadata + namespace: default + +spec: + type: config + version: "1.0" + flag: true + osconfigs: | + files: + dbus: + conf_path: /etc/systemd/system/dbus.service + conf_source: ./test/my-dbus.service # test1 + conf_para: | + [Unit] + Description=D-Bus System Message Bus + Documentation=man:dbus-broker-launch(1) + DefaultDependencies=false + After=dbus.socket + Before=basic.target shutdown.target + Requires=dbus.socket + Conflicts=shutdown.target + + [Service] + Type=notify + Sockets=dbus.socket + OOMScoreAdjust=-900 + LimitNOFILE=16384 + ProtectSystem=full + PrivateTmp=true + PrivateDevices=true + ExecStart=/usr/bin/dbus-broker-launch --scope system --audit + ExecReload=/usr/bin/busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig + + [Install] + Alias=dbus.service + conf_cmd: + - systemctl restart dbus + + ssh: + conf_path: /etc/ssh/sshd_config + conf_source: ./test/ssh.service # test2 + conf_para: | + [Unit] + Description=SSH Daemon + After=network.target + + [Service] + ExecStart=/usr/sbin/sshd --nofork --nopid + ExecReload=/bin/kill -HUP $MAINPID + Restart=on-failure + + [Install] + WantedBy=multi-user.target + conf_cmd: + - systemctl restart sshd + + fire: + conf_path: /etc/firewalld/firewalld.conf + conf_source: ./test/fire.service ## test3 + conf_para: | + [Unit] + Description=Firewall Daemon + After=network.target + + [Service] + ExecStart=/usr/sbin/firewalld --nofork --nopid + ExecReload=/bin/kill -HUP $MAINPID + Restart=on-failure + + [Install] + WantedBy=multi-user.target + conf_cmd: + - systemctl restart firewalld \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/ssh.service" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/ssh.service" new file mode 100644 index 0000000000000000000000000000000000000000..d412167195b45c9beb2277d7e601aea3b643699c --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/ssh.service" @@ -0,0 +1,11 @@ +[Unit] +Description=SSH Daemon +After=network.target + +[Service] +ExecStart=/usr/sbin/sshd --nofork --nopid +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-ori.yaml" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-ori.yaml" new file mode 100644 index 0000000000000000000000000000000000000000..e6046dae3f4503985ab5df112fbf19e6e9f9b59d --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-ori.yaml" @@ -0,0 +1,46 @@ +filename: mytest +metadata: + name: my-sample + namespace: default_runtime +spec: + type: config + version: "1.0" + flag: true + osconfigs: | + kernel: + sysctl: + conf_path: /etc/sysctl.conf + conf_para: + vm.swappiness: 73 + user.max_user_namespaces: 64006 + + container: + cri_file1: + conf_path: /etc/containerd/config.toml + conf_para: + root: "/var/lib/containerd" + version: 2 + plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.privileged_without_host_devices_all_devices_allowed_test: [1, "b", [2, "b", [3, "b", true]]] + plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.privileged_without_host_devices_test: [1, "b", [2, "b", [3, "b", true]]] + plugins."io.containerd.grpc.v1.cri".containerd.runtime.privileged_test: [a,b,c] # add in new table + conf_cmd: + - systemctl daemon-reload + - systemctl restart containerd + + files: + dns: + conf_path: /etc/resolv.conf + conf_para: | + # Generated by NetworkManager + nameserver xx.xx.xx.xx + conf_cmd: + - systemctl status NetworkManager + + dbus: + conf_path: /etc/systemd/system/dbus.service + conf_source: ./test/my-dbus.service + + conf_cmd: + - systemctl daemon-reload + - systemctl restart dbus + - systemctl status dbus \ No newline at end of file diff --git "a/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-res.yaml" "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-res.yaml" new file mode 100644 index 0000000000000000000000000000000000000000..fcd4e2ece39e11e2f0a9daaa43deacd565dfee0a --- /dev/null +++ "b/\344\270\212\346\211\213issue_\344\275\234\345\223\201\346\226\207\344\273\266\345\244\271/\345\255\231\345\256\207\350\210\252-\350\247\243\346\236\220yaml\345\271\266\345\234\250\346\214\207\345\256\232\344\275\215\347\275\256\346\217\222\345\205\245\346\226\260key-value/test/test-res.yaml" @@ -0,0 +1,69 @@ +filename: mytest +metadata: + name: my-sample + namespace: default_runtime +spec: + type: config + version: "1.0" + flag: true + osconfigs: | + kernel: + sysctl: + conf_path: /etc/sysctl.conf + conf_para: + vm.swappiness: 73 + user.max_user_namespaces: 64006 + + container: + cri_file1: + conf_path: /etc/containerd/config.toml + conf_para: + root: "/var/lib/containerd" + version: 2 + plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.privileged_without_host_devices_all_devices_allowed_test: [1, "b", [2, "b", [3, "b", true]]] + plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.privileged_without_host_devices_test: [1, "b", [2, "b", [3, "b", true]]] + plugins."io.containerd.grpc.v1.cri".containerd.runtime.privileged_test: [a,b,c] # add in new table + conf_cmd: + - systemctl daemon-reload + - systemctl restart containerd + + files: + dns: + conf_path: /etc/resolv.conf + conf_para: | + # Generated by NetworkManager + nameserver xx.xx.xx.xx + conf_cmd: + - systemctl status NetworkManager + + dbus: + conf_path: /etc/systemd/system/dbus.service + conf_source: ./test/my-dbus.service + conf_para: | + [Unit] + Description=D-Bus System Message Bus + Documentation=man:dbus-broker-launch(1) + DefaultDependencies=false + After=dbus.socket + Before=basic.target shutdown.target + Requires=dbus.socket + Conflicts=shutdown.target + + [Service] + Type=notify + Sockets=dbus.socket + OOMScoreAdjust=-900 + LimitNOFILE=16384 + ProtectSystem=full + PrivateTmp=true + PrivateDevices=true + ExecStart=/usr/bin/dbus-broker-launch --scope system --audit + ExecReload=/usr/bin/busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig + + [Install] + Alias=dbus.service + + conf_cmd: + - systemctl daemon-reload + - systemctl restart dbus + - systemctl status dbus \ No newline at end of file