diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index a768ab8..85b5404 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -1,36 +1,48 @@ use std::sync::Arc; use tower_http::trace::TraceLayer; use axum::{ routing::get, extract::{State, Request, Json, Path, Extension, Query}, routing::post, }; pub use axum::serve; struct AppState { collar: libcollar::State, } pub fn app(collar: libcollar::State) -> axum::Router { let state = Arc::new(AppState { collar }); // build our application with a single route let app = axum::Router::new() .route("/", get(|| async { "collared." })) .route("/ng/eiface/{name}", post(post_ng_eiface)) + .route("/store/namespace/{name}/{key}/{value}", post(post_ns_key)) + .route("/store/namespace/{name}/{key}", get(get_ns_key)) .with_state(state) .layer(tower_http::trace::TraceLayer::new_for_http()); app } +async fn post_ns_key(State(state): State>, Path((name, key, value)): Path<(String, String, String)>) -> Result { + let ns = state.collar.store.namespaces(); + Ok("todo".to_string()) +} + +async fn get_ns_key(State(state): State>, Path((name, key)): Path<(String, String)>) -> Result { + let ns = state.collar.store.namespaces(); + Ok("todo".to_string()) +} + async fn post_ng_eiface(State(state): State>, Path(name): Path) -> Result { let fname = name.clone(); let result = state.collar.leash().gated(move || { Ok(libcollar::ng::new_eiface(&name)) }).await; Ok(format!("sup {} => {:?}", &fname, result)) } diff --git a/crates/libcollar/src/error.rs b/crates/libcollar/src/error.rs index dfd55e9..42269e8 100644 --- a/crates/libcollar/src/error.rs +++ b/crates/libcollar/src/error.rs @@ -1,62 +1,65 @@ #[derive(thiserror::Error, Debug)] pub enum Error { //#[error("sys err")] //SystemError(errno::Errno), #[error("not a bridge")] PathIsNotABridge, #[error("invalid node type")] InvalidNodeType(String, String), #[error("bridge already exists")] BridgeLinkExists(String, String), #[error("utf8")] InvalidUtf8(std::str::Utf8Error), #[error("nul")] NulError(String), #[error("exists")] Exists, #[error("invalid file descriptor")] InvalidDescriptor, #[error("name too long")] NameTooLong, #[error("description too long")] DescriptionTooLong, #[error("interface not found")] InterfaceNotFound, #[error("out of memory")] OutOfMemory, #[error("operation not supported")] NotSupported, + #[error(transparent)] + Store(#[from] store::Error), + #[error(transparent)] Ifconfig(#[from] ifconfig::Error), #[error(transparent)] Netgraph(#[from] ng::Error), #[error(transparent)] TaskJoin(#[from] tokio::task::JoinError), #[error(transparent)] Io(#[from] std::io::Error), #[error(transparent)] Nul(#[from] std::ffi::NulError), #[error(transparent)] ParseNum(#[from] std::num::ParseIntError), } pub type Result = ::std::result::Result; diff --git a/crates/libcollar/src/libcollar.rs b/crates/libcollar/src/libcollar.rs index ed39c62..4bd9f92 100644 --- a/crates/libcollar/src/libcollar.rs +++ b/crates/libcollar/src/libcollar.rs @@ -1,19 +1,21 @@ use crate::Result; use crate::net; pub struct State { leash: net::Leash, + pub store: store::Store, } pub fn new() -> Result { Ok(State { leash: net::Leash::new(), + store: store::open()?, }) } impl State { pub fn leash(&self) -> &net::Leash { &self.leash } }