mannequin/src/nexus/mod.rs
mod prod;
mod proxy;
mod upload;
pub use prod::ProdRepo;
pub use proxy::ProxyRepo;
pub use upload::UploadRepo;
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize)]
pub struct NexusRepository {
pub name: String,
pub format: String,
#[serde(rename = "type")]
pub repo_type: String,
pub url: Option<String>,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct NexusAsset {
pub path: String,
#[serde(rename = "downloadUrl")]
pub download_url: String,
#[serde(rename = "contentType")]
pub content_type: Option<String>,
#[serde(rename = "fileSize")]
pub size: Option<u64>,
}
#[derive(Serialize)]
pub struct AssetPage {
pub items: Vec<NexusAsset>,
#[serde(rename = "continuationToken")]
pub continuation_token: Option<String>,
}
/// Aggregates all three Nexus repo types.
pub struct MockNexusService {
pub proxy: ProxyRepo,
pub prod: ProdRepo,
pub upload: UploadRepo,
}
impl MockNexusService {
pub fn new(base_url: &str) -> Self {
let mut prod = ProdRepo::new(base_url);
prod.seed_defaults();
Self {
proxy: ProxyRepo::new(base_url),
prod,
upload: UploadRepo::new(base_url),
}
}
pub fn list_repositories(&self) -> Vec<NexusRepository> {
vec![
NexusRepository {
name: "proxy-only".into(),
format: "raw".into(),
repo_type: "proxy".into(),
url: None,
},
NexusRepository {
name: "prod".into(),
format: "raw".into(),
repo_type: "hosted".into(),
url: None,
},
NexusRepository {
name: "upload".into(),
format: "raw".into(),
repo_type: "hosted".into(),
url: None,
},
]
}
pub fn list_assets(&self, repo: &str) -> Vec<NexusAsset> {
match repo {
"proxy-only" => self.proxy.list_assets(),
"prod" => self.prod.list_assets(),
"upload" => self.upload.list_assets(),
_ => vec![],
}
}
pub async fn download(&self, repo: &str, path: &str) -> Option<Vec<u8>> {
match repo {
"proxy-only" => self.proxy.download(path).await,
"prod" => self.prod.download(path).await,
"upload" => self.upload.download(path),
_ => None,
}
}
pub fn upload(&self, repo: &str, path: &str, data: Vec<u8>) -> bool {
match repo {
"upload" => {
self.upload.upload(path, data);
true
}
_ => false,
}
}
}