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
* Packages of architecture "any" are part of every architecture's
database
* Bearer authentication for private routes

View File

@ -26,18 +26,18 @@ pub fn router() -> Router<crate::Global> {
"/:repo",
post(post_package_archive)
.delete(delete_repo)
.layer(ValidateRequestHeaderLayer::bearer("test")),
.route_layer(ValidateRequestHeaderLayer::bearer("test")),
)
.route(
"/: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
// be authorized
.route(
"/:repo/:arch/:filename",
delete(delete_package)
.layer(ValidateRequestHeaderLayer::bearer("test"))
.route_layer(ValidateRequestHeaderLayer::bearer("test"))
.get(get_file),
)
}
@ -165,10 +165,13 @@ async fn delete_repo(
) -> crate::Result<StatusCode> {
let clone = Arc::clone(&global.repo_manager);
let repo_clone = repo.clone();
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 {
tracing::info!("Removed repo '{}'", repo);
Ok(StatusCode::OK)
} else {
Ok(StatusCode::NOT_FOUND)
@ -181,11 +184,14 @@ async fn delete_arch_repo(
) -> crate::Result<StatusCode> {
let clone = Arc::clone(&global.repo_manager);
let log = format!("Removed architecture '{}' from repo '{}'", arch, repo);
let repo_removed =
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo_arch(&repo, &arch))
.await??;
if repo_removed {
tracing::info!(log);
Ok(StatusCode::OK)
} else {
Ok(StatusCode::NOT_FOUND)
@ -205,6 +211,7 @@ async fn delete_package(
}
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);
@ -214,6 +221,8 @@ async fn delete_package(
.await??;
if pkg_removed {
tracing::info!(log);
Ok(StatusCode::OK)
} else {
Ok(StatusCode::NOT_FOUND)