From 57e1816e690821be282d7c38a5d865e48f8ddf3f Mon Sep 17 00:00:00 2001 From: Rickard Lundin Date: Tue, 4 Nov 2025 23:26:25 +0100 Subject: [PATCH] fixed new package handler --- Cargo.toml | 4 +- holger-ron/Cargo.toml | 2 +- holger-rust-file-repository/Cargo.toml | 26 +++++ .../examples/get_path.rs | 15 +++ .../src/lib.rs | 22 ++-- .../Cargo.toml | 2 +- .../examples/get_path.rs | 0 holger-rust-znippy-repository/src/lib.rs | 103 ++++++++++++++++++ 8 files changed, 159 insertions(+), 15 deletions(-) create mode 100644 holger-rust-file-repository/Cargo.toml create mode 100644 holger-rust-file-repository/examples/get_path.rs rename {holger-rust-repository => holger-rust-file-repository}/src/lib.rs (91%) rename {holger-rust-repository => holger-rust-znippy-repository}/Cargo.toml (93%) rename {holger-rust-repository => holger-rust-znippy-repository}/examples/get_path.rs (100%) create mode 100644 holger-rust-znippy-repository/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 03bcb27..7a6b6d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] -#members = ["holger-traits","holger-rust-repository","holger-ron","holger-cli","holger"] -members = ["holger-traits","holger-rust-repository","holger-ron","holger-cli","holger"] +#members = ["holger-traits","holger-rust-file-repository","holger-ron","holger-cli","holger"] +members = ["holger-traits", "holger-rust-znippy-repository","holger-rust-file-repository","holger-ron","holger-cli","holger"] resolver = "2" diff --git a/holger-ron/Cargo.toml b/holger-ron/Cargo.toml index 0edaba1..b1f208c 100644 --- a/holger-ron/Cargo.toml +++ b/holger-ron/Cargo.toml @@ -26,7 +26,7 @@ anyhow = "1.0.98" derivative = "2.2.0" #holger-traits = {path="../holger-traits"} holger-traits = {version = "0.2.0"} -#holger-rust-repository = {path ="../holger-rust-repository"} +#holger-rust-file-repository = {path ="../holger-rust-file-repository"} holger-rust-repository = {version = "0.2.0"} hyper-util = { version = "0.1.16", features = ["tokio"] } diff --git a/holger-rust-file-repository/Cargo.toml b/holger-rust-file-repository/Cargo.toml new file mode 100644 index 0000000..75876ec --- /dev/null +++ b/holger-rust-file-repository/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "holger-rust-file-repository" +version = "0.2.0" +edition = "2021" +authors = ["Rickard Lundin ","Wilhelm Ågren"] + +description = "Holger guards your artifacts at rest. May Allfather Odin watch over every bit." +license = "MIT" +repository = "https://github.com/Ignalina/holger" +readme = "../README.md" +categories = ["command-line-utilities","development-tools"] +keywords = ["file", "artifacts", "blake3", "cli","airgap"] + + +[dependencies] + +anyhow = "1.0.98" + +#holger-traits = {path="../holger-traits"} +holger-traits = {version = "0.2.0"} + +sha2 = "0.11.0-rc.0" +hex = "0.4.3" + +[[example]] +name = "get_path" diff --git a/holger-rust-file-repository/examples/get_path.rs b/holger-rust-file-repository/examples/get_path.rs new file mode 100644 index 0000000..5aad34a --- /dev/null +++ b/holger-rust-file-repository/examples/get_path.rs @@ -0,0 +1,15 @@ +use holger_rust_file_repository::RustRepo; + +type RPath<'a> = (&'a str, &'a str, &'a str); + +fn main() { + //let repo = RustRepo::new("kalle".to_string()); + println!("path: {:?}", RustRepo::sparse_path("a")); + println!("path: {:?}", RustRepo::sparse_path("ab")); + println!("path: {:?}", RustRepo::sparse_path("abc")); + println!("path: {:?}", RustRepo::sparse_path("tokio")); + + let tuple_path: RPath = RustRepo::sparse_path("tokio").into(); + + println!("Tuple: {:?}", tuple_path); +} diff --git a/holger-rust-repository/src/lib.rs b/holger-rust-file-repository/src/lib.rs similarity index 91% rename from holger-rust-repository/src/lib.rs rename to holger-rust-file-repository/src/lib.rs index c2f5d59..62ebebd 100644 --- a/holger-rust-repository/src/lib.rs +++ b/holger-rust-file-repository/src/lib.rs @@ -4,7 +4,7 @@ use sha2::{Digest, Sha256}; use std::any::Any; /// Minimal RustRepo example -pub struct RustRepo { +pub struct RustRepoFile { pub name: String, // pub format: ArtifactFormat, pub artifacts: Vec, // cached list of artifacts @@ -23,9 +23,9 @@ impl<'a> From> for (&'a str, &'a str, &'a str) { } } -impl RustRepo { +impl RustRepoFile { pub fn new(name: String) -> Self { - RustRepo { + RustRepoFile { // initialize fields if any; if none, leave empty struct // Example: name // name, @@ -81,7 +81,7 @@ impl RustRepo { } } -impl RepositoryBackendTrait for RustRepo { +impl RepositoryBackendTrait for RustRepoFile { fn name(&self) -> &str { &self.name } @@ -116,7 +116,7 @@ impl RepositoryBackendTrait for RustRepo { // Sparse crate metadata → /rust-prod/index/se/rd/serde [repo, "index", p1, p2, crate_name] if *repo == self.name() => { - if let Some(actual_name) = RustRepo::sparse_crate_from_parts(&[p1, p2, crate_name]) + if let Some(actual_name) = RustRepoFile::sparse_crate_from_parts(&[p1, p2, crate_name]) { println!( "Sparse crate metadata request: {}/{}/{}", @@ -124,7 +124,7 @@ impl RepositoryBackendTrait for RustRepo { ); let fake_crate_data = b"FAKE_CRATE_CONTENT"; - let checksum_hex = RustRepo::crate_sha256_hex(fake_crate_data); + let checksum_hex = RustRepoFile::crate_sha256_hex(fake_crate_data); let json = format!( r#"[{{"vers":"1.0.0","deps":[],"cksum":"{}"}}]"#, @@ -180,7 +180,7 @@ mod tests { #[test] fn sparse_path_test_1() { - let path = RustRepo::sparse_path("a"); + let path = RustRepoFile::sparse_path("a"); assert_eq!( path, RepoPath { @@ -193,7 +193,7 @@ mod tests { #[test] fn sparse_path_test_2() { - let path = RustRepo::sparse_path("ab"); + let path = RustRepoFile::sparse_path("ab"); assert_eq!( path, RepoPath { @@ -206,7 +206,7 @@ mod tests { #[test] fn sparse_path_test_3() { - let path = RustRepo::sparse_path("abc"); + let path = RustRepoFile::sparse_path("abc"); assert_eq!( path, RepoPath { @@ -219,7 +219,7 @@ mod tests { #[test] fn sparse_path_test_n() { - let path = RustRepo::sparse_path("abcd"); + let path = RustRepoFile::sparse_path("abcd"); assert_eq!( path, RepoPath { @@ -232,7 +232,7 @@ mod tests { #[test] fn sparse_path_into_tuple() { - let path: (&str, &str, &str) = RustRepo::sparse_path("abcd").into(); + let path: (&str, &str, &str) = RustRepoFile::sparse_path("abcd").into(); assert_eq!(path, ("ab", "cd", "abcd")); } } diff --git a/holger-rust-repository/Cargo.toml b/holger-rust-znippy-repository/Cargo.toml similarity index 93% rename from holger-rust-repository/Cargo.toml rename to holger-rust-znippy-repository/Cargo.toml index ebab71a..8bec253 100644 --- a/holger-rust-repository/Cargo.toml +++ b/holger-rust-znippy-repository/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "holger-rust-repository" +name = "holger-rust-znippy-repository" version = "0.2.0" edition = "2021" authors = ["Rickard Lundin ","Wilhelm Ågren"] diff --git a/holger-rust-repository/examples/get_path.rs b/holger-rust-znippy-repository/examples/get_path.rs similarity index 100% rename from holger-rust-repository/examples/get_path.rs rename to holger-rust-znippy-repository/examples/get_path.rs diff --git a/holger-rust-znippy-repository/src/lib.rs b/holger-rust-znippy-repository/src/lib.rs new file mode 100644 index 0000000..e2116d4 --- /dev/null +++ b/holger-rust-znippy-repository/src/lib.rs @@ -0,0 +1,103 @@ +use anyhow::anyhow; +use holger_traits::{ArtifactFormat, ArtifactId, RepositoryBackendTrait}; +use sha2::{Digest, Sha256}; +use std::any::Any; + +/// Minimal RustRepo example +pub struct RustRepoZnippy { + pub name: String, + // pub format: ArtifactFormat, + pub artifacts: Vec, // cached list of artifacts +} + + +impl RustRepoZnippy { + pub fn new(name: String) -> Self { + RustRepoZnippy { + // initialize fields if any; if none, leave empty struct + // Example: name + // name, + name, + artifacts: vec![], + } + } +} + +impl RepositoryBackendTrait for RustRepoZnippy { + fn name(&self) -> &str { + &self.name + } + + fn handle_http2_request( + &self, + suburl: &str, + body: &[u8], + ) -> anyhow::Result<(u16, Vec<(String, String)>, Vec)> { + let _ = body; + println!("Rust repo znippy handle_http2_request.suburl={}", suburl); + + let parts: Vec<&str> = suburl.trim_start_matches('/').split('/').collect(); + + match parts.as_slice() { + // Sparse root config.json → /rust-prod/index/config.json + [repo, "index", "config.json"] if *repo == self.name() => { + println!("Sparse config.json requested"); + let json = format!( + r#"{{ + "dl": "https://127.0.0.1:8443/{}/crates", + "api": null + }}"#, + self.name() + ); + return Ok(( + 200, + vec![("Content-Type".into(), "application/json".into())], + json.as_bytes().to_vec(), + )); + } + + // Sparse crate metadata → /rust-prod/index/se/rd/serde + [repo, "index", p1, p2, crate_name] if *repo == self.name() => { + return Ok((404, Vec::new(), b"Not found".to_vec())); + + } + + // Crate download → /crates///download + ["crates", crate_name, version, "download"] => { + println!("Download request: crate={} version={}", crate_name, version); + return Ok(( + 200, + vec![("Content-Type".into(), "application/octet-stream".into())], + b"FAKE_CRATE_CONTENT".to_vec(), + )); + } + + _ => { + println!("Unhandled path: {}", suburl); + Ok((404, Vec::new(), b"Not found".to_vec())) + } + } + } + fn format(&self) -> ArtifactFormat { + ArtifactFormat::Rust + } + + fn is_writable(&self) -> bool { + todo!() + } + + fn fetch(&self, id: &ArtifactId) -> anyhow::Result>> { + todo!() + } + + fn put(&self, id: &ArtifactId, data: &[u8]) -> anyhow::Result<()> { + todo!() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + +}