2026-01-24 22:59:20 +00:00
|
|
|
use crate::api::rpc::RpcHandler;
|
|
|
|
|
use crate::config::Config;
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use hyper::{Method, Request, Response, StatusCode};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tracing::debug;
|
|
|
|
|
|
|
|
|
|
pub struct ApiHandler {
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
_config: Config,
|
2026-01-24 22:59:20 +00:00
|
|
|
rpc_handler: Arc<RpcHandler>,
|
|
|
|
|
// Add other handlers here (websocket, static files, etc.)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ApiHandler {
|
|
|
|
|
pub async fn new(config: Config) -> Result<Self> {
|
|
|
|
|
let rpc_handler = Arc::new(RpcHandler::new(config.clone()).await?);
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
_config: config,
|
2026-01-24 22:59:20 +00:00
|
|
|
rpc_handler,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 23:20:54 +00:00
|
|
|
pub async fn handle_request(
|
|
|
|
|
&self,
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
req: Request<hyper::Body>,
|
|
|
|
|
) -> Result<Response<hyper::Body>> {
|
2026-01-24 23:20:54 +00:00
|
|
|
// Extract path and method before consuming req
|
|
|
|
|
let path = req.uri().path().to_string();
|
|
|
|
|
let method = req.method().clone();
|
2026-01-24 22:59:20 +00:00
|
|
|
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
// Convert body to bytes
|
2026-01-24 22:59:20 +00:00
|
|
|
let (parts, body) = req.into_parts();
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
let body_bytes = hyper::body::to_bytes(body).await
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("Failed to read body: {}", e))?;
|
2026-01-24 22:59:20 +00:00
|
|
|
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
// Reconstruct request with body as Bytes for RPC handler
|
|
|
|
|
let req_with_bytes = Request::from_parts(parts, hyper::Body::from(body_bytes));
|
2026-01-24 22:59:20 +00:00
|
|
|
|
|
|
|
|
debug!("{} {}", method, path);
|
|
|
|
|
|
|
|
|
|
// Route requests
|
2026-01-24 23:09:46 +00:00
|
|
|
match (method, path.as_str()) {
|
2026-01-24 23:20:54 +00:00
|
|
|
(Method::POST, "/rpc/v1") => {
|
2026-01-24 22:59:20 +00:00
|
|
|
self.rpc_handler.handle(req_with_bytes).await
|
|
|
|
|
}
|
2026-01-24 23:20:54 +00:00
|
|
|
(Method::GET, "/health") => {
|
2026-01-24 22:59:20 +00:00
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::OK)
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
.body(hyper::Body::from("OK"))
|
2026-01-24 22:59:20 +00:00
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::NOT_FOUND)
|
Update archipelago: API, auth, container, parmanode, performance, security
- API handler, RPC, and server updates
- Auth and coding rules
- Container data manager, dev orchestrator, health monitor, podman client
- Parmanode script runner
- Performance resource manager
- Security container policies and secrets manager
- Add build scripts and documentation
2026-01-27 22:27:17 +00:00
|
|
|
.body(hyper::Body::from("Not Found"))
|
2026-01-24 22:59:20 +00:00
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|