httpd: Add configuration to `/node` endpoint
Adds the "config" key containing node configuration. Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
parent
78e6833672
commit
9a1a216f70
|
|
@ -1,7 +1,6 @@
|
|||
pub mod auth;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -40,7 +39,6 @@ pub struct Context {
|
|||
profile: Arc<Profile>,
|
||||
sessions: Arc<RwLock<HashMap<SessionId, auth::Session>>>,
|
||||
cache: Option<Cache>,
|
||||
address: SocketAddr,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
|
|
@ -49,7 +47,6 @@ impl Context {
|
|||
profile,
|
||||
sessions: Default::default(),
|
||||
cache: options.cache.map(Cache::new),
|
||||
address: options.listen,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ pub enum Error {
|
|||
#[error(transparent)]
|
||||
RoutingStore(#[from] radicle::node::routing::Error),
|
||||
|
||||
/// Node error.
|
||||
#[error(transparent)]
|
||||
Node(#[from] radicle::node::Error),
|
||||
|
||||
/// Invalid update to issue or patch.
|
||||
#[error("{0}")]
|
||||
BadRequest(String),
|
||||
|
|
|
|||
|
|
@ -1,31 +1,37 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use axum::extract::State;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::get;
|
||||
use axum::{Json, Router};
|
||||
use serde_json::json;
|
||||
|
||||
use radicle::node::NodeId;
|
||||
use radicle::node::Handle;
|
||||
use radicle::Node;
|
||||
|
||||
use crate::api::error::Error;
|
||||
use crate::api::Context;
|
||||
|
||||
pub fn router(ctx: Context) -> Router {
|
||||
let node_id = ctx.profile.public_key;
|
||||
let address = ctx.address;
|
||||
|
||||
Router::new()
|
||||
.route("/node", get(node_handler))
|
||||
.with_state((node_id, address))
|
||||
.with_state(ctx)
|
||||
}
|
||||
|
||||
/// Return the node id for the node identity.
|
||||
/// Return local node information.
|
||||
/// `GET /node`
|
||||
async fn node_handler(State((node_id, address)): State<(NodeId, SocketAddr)>) -> impl IntoResponse {
|
||||
async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||
let node = Node::new(ctx.profile.socket());
|
||||
let node_id = ctx.profile.public_key;
|
||||
let node_state = if node.is_running() {
|
||||
"running"
|
||||
} else {
|
||||
"stopped"
|
||||
};
|
||||
let config = node.config()?;
|
||||
let response = json!({
|
||||
"id": node_id.to_string(),
|
||||
"address": address.to_string(),
|
||||
"config": config,
|
||||
"state": node_state,
|
||||
});
|
||||
|
||||
Json(response)
|
||||
Ok::<_, Error>(Json(response))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue