httpd: Add endpoint with tracking information

This allows us to check which projects are really tracked by the node
and which aren't and with which scopes and policies.
This commit is contained in:
Sebastian Martinez
2023-11-30 12:30:07 +01:00
committed by cloudhead
parent c197bc8763
commit 80c1bb5b22
+19 -1
View File
@@ -4,7 +4,7 @@ use axum::routing::get;
use axum::{Json, Router};
use serde_json::json;
use radicle::node::Handle;
use radicle::node::{tracking, Handle};
use radicle::Node;
use crate::api::error::Error;
@@ -13,6 +13,7 @@ use crate::api::Context;
pub fn router(ctx: Context) -> Router {
Router::new()
.route("/node", get(node_handler))
.route("/node/tracking/repos", get(node_tracking_repos_handler))
.with_state(ctx)
}
@@ -41,3 +42,20 @@ async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {
Ok::<_, Error>(Json(response))
}
/// Return local tracking repos information.
/// `GET /node/tracking/repos`
async fn node_tracking_repos_handler(State(ctx): State<Context>) -> impl IntoResponse {
let tracking = ctx.profile.tracking()?;
let mut repos = Vec::new();
for tracking::Repo { id, scope, policy } in tracking.repo_policies()? {
repos.push(json!({
"id": id,
"scope": scope,
"policy": policy,
}));
}
Ok::<_, Error>(Json(repos))
}