Skip to content
This repository was archived by the owner on May 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion holger-ron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
26 changes: 26 additions & 0 deletions holger-rust-file-repository/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "holger-rust-file-repository"
version = "0.2.0"
edition = "2021"
authors = ["Rickard Lundin <rickard@x14.se>","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"
15 changes: 15 additions & 0 deletions holger-rust-file-repository/examples/get_path.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArtifactId>, // cached list of artifacts
Expand All @@ -23,9 +23,9 @@ impl<'a> From<RepoPath<'a>> 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,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl RustRepo {
}
}

impl RepositoryBackendTrait for RustRepo {
impl RepositoryBackendTrait for RustRepoFile {
fn name(&self) -> &str {
&self.name
}
Expand Down Expand Up @@ -116,15 +116,15 @@ 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: {}/{}/{}",
p1, p2, actual_name
);

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":"{}"}}]"#,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "holger-rust-repository"
name = "holger-rust-znippy-repository"
version = "0.2.0"
edition = "2021"
authors = ["Rickard Lundin <rickard@x14.se>","Wilhelm Ågren"]
Expand Down
103 changes: 103 additions & 0 deletions holger-rust-znippy-repository/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<ArtifactId>, // 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<u8>)> {
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/<crate>/<version>/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<Option<Vec<u8>>> {
todo!()
}

fn put(&self, id: &ArtifactId, data: &[u8]) -> anyhow::Result<()> {
todo!()
}
}

#[cfg(test)]
mod tests {
use super::*;


}
Loading