feat(server): log repository updates

repo-db
Jef Roosens 2023-08-03 11:03:01 +02:00
parent a7e0c03b58
commit 33c8477b09
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 14 additions and 4 deletions

View File

@ -16,3 +16,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
requests requests
* Packages of architecture "any" are part of every architecture's * Packages of architecture "any" are part of every architecture's
database database
* Bearer authentication for private routes

View File

@ -26,18 +26,18 @@ pub fn router() -> Router<crate::Global> {
"/:repo", "/:repo",
post(post_package_archive) post(post_package_archive)
.delete(delete_repo) .delete(delete_repo)
.layer(ValidateRequestHeaderLayer::bearer("test")), .route_layer(ValidateRequestHeaderLayer::bearer("test")),
) )
.route( .route(
"/:repo/:arch", "/:repo/:arch",
delete(delete_arch_repo).layer(ValidateRequestHeaderLayer::bearer("test")), delete(delete_arch_repo).route_layer(ValidateRequestHeaderLayer::bearer("test")),
) )
// Routes added after the layer do not get that layer applied, so the GET requests will not // Routes added after the layer do not get that layer applied, so the GET requests will not
// be authorized // be authorized
.route( .route(
"/:repo/:arch/:filename", "/:repo/:arch/:filename",
delete(delete_package) delete(delete_package)
.layer(ValidateRequestHeaderLayer::bearer("test")) .route_layer(ValidateRequestHeaderLayer::bearer("test"))
.get(get_file), .get(get_file),
) )
} }
@ -165,10 +165,13 @@ async fn delete_repo(
) -> crate::Result<StatusCode> { ) -> crate::Result<StatusCode> {
let clone = Arc::clone(&global.repo_manager); let clone = Arc::clone(&global.repo_manager);
let repo_clone = repo.clone();
let repo_removed = let repo_removed =
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo(&repo)).await??; tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo(&repo_clone)).await??;
if repo_removed { if repo_removed {
tracing::info!("Removed repo '{}'", repo);
Ok(StatusCode::OK) Ok(StatusCode::OK)
} else { } else {
Ok(StatusCode::NOT_FOUND) Ok(StatusCode::NOT_FOUND)
@ -181,11 +184,14 @@ async fn delete_arch_repo(
) -> crate::Result<StatusCode> { ) -> crate::Result<StatusCode> {
let clone = Arc::clone(&global.repo_manager); let clone = Arc::clone(&global.repo_manager);
let log = format!("Removed architecture '{}' from repo '{}'", arch, repo);
let repo_removed = let repo_removed =
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo_arch(&repo, &arch)) tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo_arch(&repo, &arch))
.await??; .await??;
if repo_removed { if repo_removed {
tracing::info!(log);
Ok(StatusCode::OK) Ok(StatusCode::OK)
} else { } else {
Ok(StatusCode::NOT_FOUND) Ok(StatusCode::NOT_FOUND)
@ -205,6 +211,7 @@ async fn delete_package(
} }
let name = name_parts[..name_parts.len() - 3].join("-"); let name = name_parts[..name_parts.len() - 3].join("-");
let log = format!("Removed '{}' from repository '{}'", file_name, repo);
let clone = Arc::clone(&global.repo_manager); let clone = Arc::clone(&global.repo_manager);
@ -214,6 +221,8 @@ async fn delete_package(
.await??; .await??;
if pkg_removed { if pkg_removed {
tracing::info!(log);
Ok(StatusCode::OK) Ok(StatusCode::OK)
} else { } else {
Ok(StatusCode::NOT_FOUND) Ok(StatusCode::NOT_FOUND)