feat: Added http server that serve the same files

This commit is contained in:
2026-10-20 02:56:39 +02:00
parent a5594c768d
commit 620f36d0bb
7 changed files with 210 additions and 38 deletions
+37
View File
@@ -0,0 +1,37 @@
use crete::cluster::Cluster;
use ipxe::IPXE_DIR;
use regex::Regex;
// TODO: Make this a proper async function
pub fn get_file(filename: impl ToString) -> impl Future<Output = Option<(Vec<u8>, &'static str)>> {
// TODO: Make this a static that is initialized once
let re =
Regex::new(r"^talos/(?<cluster>.+)/(?<node>.+)\.ya?ml$").expect("regex should be valid");
let filename: String = filename.to_string();
let re = re.clone();
async move {
const IPXE_PATTERN: &str = "ipxe/";
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
}
}
}