Files
crete/src/file.rs
T
Dreaded_X 8e9c461a45
Committed / committed (pull_request) Successful in 1m4s
CI / cargo shear (pull_request) Successful in 4m19s
CI / prek (pull_request) Successful in 19m18s
CI / cargo shear (push) Successful in 7m46s
Audit / cargo audit (push) Failing after 12m52s
Release-plz / Release-plz Release (push) Failing after 3m22s
Release-plz / Release-plz PR (push) Failing after 14m19s
CI / prek (push) Successful in 32m52s
chore(deps): Upgrade all deps
2026-10-21 07:30:51 +02:00

56 lines
1.7 KiB
Rust

use crete::cluster::Cluster;
use crete::environment::configure_environment;
use ipxe::IPXE_DIR;
use minijinja::{Environment, context, value};
use regex::regex;
pub async fn get_file(
filename: impl ToString,
http_url: impl ToString,
) -> Option<(Vec<u8>, &'static str)> {
let re = regex!(r"^talos/(?<cluster>.+)/(?<node>.+)\.ya?ml$");
let filename: String = filename.to_string();
let re = re.clone();
const IPXE_PATTERN: &str = "ipxe/";
if filename == format!("{IPXE_PATTERN}boot.ipxe") {
let mut env = Environment::new();
configure_environment(&mut env);
let template = env
.template_from_str(include_str!("./boot.ipxe"))
.expect("Template should be valid");
let clusters = Cluster::get_all().await;
let content = template
.render(context! {
clusters => value::Serde(clusters.values().collect::<Vec<_>>()),
httpUrl => http_url.to_string()
})
.unwrap();
Some((content.into(), "text/plain; charset=utf-8"))
} else if let Some(filename) = filename.strip_prefix(IPXE_PATTERN) {
Some((
IPXE_DIR.get_file(filename)?.contents().to_owned(),
"application/octet-stream",
))
} else if let Some(caps) = re.captures(&filename) {
let cluster = &caps["cluster"];
let node = &caps["node"];
let clusters = Cluster::get_all().await;
let cluster = clusters.get(cluster)?;
let node = cluster.node(node)?;
let config = node.config(cluster).await;
Some((config.into(), "application/yaml; charset=utf-8"))
} else {
None
}
}