httpd: Add `/nodes/:nid` and `/nodes/:nid/inventory` endpoints to get info on other nodes
This commit is contained in:
parent
db6cb55d6c
commit
29cb5c085d
|
|
@ -46,6 +46,10 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Repository(#[from] radicle::storage::RepositoryError),
|
Repository(#[from] radicle::storage::RepositoryError),
|
||||||
|
|
||||||
|
/// Routing error.
|
||||||
|
#[error(transparent)]
|
||||||
|
Routing(#[from] radicle::node::routing::Error),
|
||||||
|
|
||||||
/// Project doc error.
|
/// Project doc error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ProjectDoc(#[from] radicle::identity::doc::PayloadError),
|
ProjectDoc(#[from] radicle::identity::doc::PayloadError),
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ use hyper::StatusCode;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use radicle::identity::RepoId;
|
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 radicle::Node;
|
||||||
|
|
||||||
use crate::api::error::Error;
|
use crate::api::error::Error;
|
||||||
|
|
@ -22,6 +23,8 @@ pub fn router(ctx: Context) -> Router {
|
||||||
"/node/policies/repos/:rid",
|
"/node/policies/repos/:rid",
|
||||||
put(node_policies_seed_handler).delete(node_policies_unseed_handler),
|
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)
|
.with_state(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,6 +55,29 @@ async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||||
Ok::<_, Error>(Json(response))
|
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.
|
/// Return local repo policies information.
|
||||||
/// `GET /node/policies/repos`
|
/// `GET /node/policies/repos`
|
||||||
async fn node_policies_repos_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
async fn node_policies_repos_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue