From af8ba238c62a4d70d84e7c3e65fa8cb53bf142b9 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 13 Nov 2024 14:40:52 -0800 Subject: [PATCH] Add version endpoint to registry backend --- wally-registry-backend/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wally-registry-backend/src/main.rs b/wally-registry-backend/src/main.rs index 07ca2c6b..02ce83b4 100644 --- a/wally-registry-backend/src/main.rs +++ b/wally-registry-backend/src/main.rs @@ -59,6 +59,11 @@ fn root() -> content::RawJson { })) } +#[get("/version")] +fn version() -> content::RawText<&'static str> { + content::RawText(option_env!("GIT_HASH").unwrap_or(env!("CARGO_PKG_VERSION"))) +} + #[get("/v1/package-contents///")] async fn package_contents( storage: &State>, @@ -155,7 +160,7 @@ async fn publish( let manifest = get_manifest(&mut archive).status(Status::BadRequest)?; let package_id = manifest.package_id(); - if !authorization.can_write_package(&package_id, &index)? { + if !authorization.can_write_package(&package_id, index)? { return Err(format_err!( "you do not have permission to write in scope {}", package_id.name().scope() @@ -195,7 +200,7 @@ async fn publish( if let Ok(mut search_backend) = search_backend.try_write() { // TODO: Recrawling the whole index for each publish is very wasteful! // Eventually this will get too expensive and we should only add the new package. - search_backend.crawl_packages(&index)?; + search_backend.crawl_packages(index)?; } Ok(Json(json!({ @@ -251,6 +256,7 @@ pub fn server(figment: Figment) -> rocket::Rocket { "/", routes![ root, + version, package_contents, publish, package_info,