Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Add `/nodes/:nid` and `/nodes/:nid/inventory` endpoints to get info on other nodes
Sebastian Martinez committed 2 years ago
commit f576028bfb11a4a380638fcb5b3cc6ffe13df30d
parent 9abad78582b1ad3e3fef56ce1c7de1b5826afcb3
2 files changed +31 -1
modified radicle-httpd/src/api/error.rs
@@ -46,6 +46,10 @@ pub enum Error {
    #[error(transparent)]
    Repository(#[from] radicle::storage::RepositoryError),

+
    /// Routing error.
+
    #[error(transparent)]
+
    Routing(#[from] radicle::node::routing::Error),
+

    /// Project doc error.
    #[error(transparent)]
    ProjectDoc(#[from] radicle::identity::doc::PayloadError),
modified radicle-httpd/src/api/v1/node.rs
@@ -7,7 +7,8 @@ use hyper::StatusCode;
use serde_json::json;

use radicle::identity::RepoId;
-
use radicle::node::{policy, Handle, DEFAULT_TIMEOUT};
+
use radicle::node::routing::Store;
+
use radicle::node::{policy, AliasStore, Handle, NodeId, DEFAULT_TIMEOUT};
use radicle::Node;

use crate::api::error::Error;
@@ -22,6 +23,8 @@ pub fn router(ctx: Context) -> Router {
            "/node/policies/repos/:rid",
            put(node_policies_seed_handler).delete(node_policies_unseed_handler),
        )
+
        .route("/nodes/:nid", get(nodes_handler))
+
        .route("/nodes/:nid/inventory", get(nodes_inventory_handler))
        .with_state(ctx)
}

@@ -52,6 +55,29 @@ async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {
    Ok::<_, Error>(Json(response))
}

+
/// Return stored information about other nodes.
+
/// `GET /nodes/:nid`
+
async fn nodes_handler(State(ctx): State<Context>, Path(nid): Path<NodeId>) -> impl IntoResponse {
+
    let aliases = ctx.profile.aliases();
+
    let response = json!({
+
        "alias": aliases.alias(&nid),
+
    });
+

+
    Ok::<_, Error>(Json(response))
+
}
+

+
/// Return stored information about other nodes.
+
/// `GET /nodes/:nid/inventory`
+
async fn nodes_inventory_handler(
+
    State(ctx): State<Context>,
+
    Path(nid): Path<NodeId>,
+
) -> impl IntoResponse {
+
    let db = &ctx.profile.database()?;
+
    let resources = db.get_resources(&nid)?;
+

+
    Ok::<_, Error>(Json(resources))
+
}
+

/// Return local repo policies information.
/// `GET /node/policies/repos`
async fn node_policies_repos_handler(State(ctx): State<Context>) -> impl IntoResponse {