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-28 12:15:18 +01:00 committed by cloudhead
parent 0af233cceb
commit 9ae7fd702e
No known key found for this signature in database
1 changed files with 19 additions and 1 deletions

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))
}