holger-server-lib 0.4.0

Holger server library: config, wiring, gRPC service, Rust API
use std::sync::Arc;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use holger_rust_file_repository::RustRepoFile as RustRepo;
use holger_rust_znippy_repository::{RustRepoZnippy, MavenRepoZnippy};
use holger_traits::RepositoryBackendTrait;
use crate::{ExposedEndpoint, StorageEndpoint};

#[derive(Serialize, Deserialize)]
pub struct Repository {
    // Parsed from RON
    pub ron_name: String,
    pub ron_repo_type: String,        // rust/java/python/raw
    pub ron_upstreams: Vec<String>,   // empty means no upstreams
    pub ron_in: Option<RepositoryIO>,
    pub ron_out: Option<RepositoryIO>,

    /// Optional path to a znippy archive (.znippy file)
    #[serde(default)]
    pub ron_archive_path: Option<String>,

    // Wired in second pass
    #[serde(skip_serializing, skip_deserializing, default)]
    pub backend_repository: Option<Arc<dyn RepositoryBackendTrait>>,
    


    #[serde(skip_serializing, skip_deserializing, default)]
    pub wired_upstreams: Vec<*const Repository>, // or &Repository pinned after build
}
impl Repository {
    pub fn backend_from_config(&mut self) -> anyhow::Result<()> {
        match self.ron_repo_type.as_str() {
            "rust" => {
                if let Some(archive_path) = &self.ron_archive_path {
                    let repo = RustRepoZnippy::with_archive(
                        self.ron_name.clone(),
                        PathBuf::from(archive_path),
                    )?;
                    self.backend_repository = Some(Arc::new(repo));
                } else {
                    self.backend_repository = Some(Arc::new(RustRepo {
                        name: self.ron_name.clone(),
                        artifacts: vec![],
                    }));
                }
                Ok(())
            }
            "maven3" => {
                if let Some(archive_path) = &self.ron_archive_path {
                    let repo = MavenRepoZnippy::with_archive(
                        self.ron_name.clone(),
                        PathBuf::from(archive_path),
                    )?;
                    self.backend_repository = Some(Arc::new(repo));
                } else {
                    anyhow::bail!("Maven3 repository requires ron_archive_path to a znippy archive");
                }
                Ok(())
            }
            other => anyhow::bail!("Unsupported repository type: {}", other),
        }
    }

}




#[derive(Serialize, Deserialize)]
pub struct RepositoryIO {
    pub ron_storage_endpoint: String,
    pub ron_exposed_endpoint: String,


    #[serde(skip_serializing, skip_deserializing, default = "std::ptr::null")]
    pub wired_storage: *const StorageEndpoint,
    #[serde(skip_serializing, skip_deserializing, default = "std::ptr::null")]
    pub wired_exposed: *const ExposedEndpoint,
}