From 75ef35829dc57d5b6f04a0c59160fe7584324793 Mon Sep 17 00:00:00 2001 From: "Carpenter, Adam (CORP)" Date: Fri, 26 Nov 2021 14:32:11 -0500 Subject: feat: basic extension loader module and two scaffolded, unimplemented extensions --- angelsharkd/src/routes/extensions/mod.rs | 26 ++++++++++++++++++++++ angelsharkd/src/routes/extensions/simple_deprov.rs | 5 +++++ angelsharkd/src/routes/extensions/simple_search.rs | 14 ++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 angelsharkd/src/routes/extensions/mod.rs create mode 100644 angelsharkd/src/routes/extensions/simple_deprov.rs create mode 100644 angelsharkd/src/routes/extensions/simple_search.rs (limited to 'angelsharkd/src/routes/extensions') diff --git a/angelsharkd/src/routes/extensions/mod.rs b/angelsharkd/src/routes/extensions/mod.rs new file mode 100644 index 0000000..5dac1cf --- /dev/null +++ b/angelsharkd/src/routes/extensions/mod.rs @@ -0,0 +1,26 @@ +use crate::config::Config; +use warp::{path, Filter, Rejection, Reply}; + +#[cfg(feature = "simple_deprov")] +mod simple_deprov; +#[cfg(feature = "simple_search")] +mod simple_search; + +pub fn filter(config: &Config) -> impl Filter + Clone { + // Note: this next line deals with the common edge case of having no + // extensions loaded with feature flags. It ensures that the the type + // checking is right when the return `.and()` is called below. + let filters = default().or(default()); + + #[cfg(feature = "simple_search")] + let filters = filters.or(simple_search::filter()); + + #[cfg(feature = "simple_deprov")] + let filters = filters.or(simple_deprov::filter()); + + path("extensions").and(filters) +} + +fn default() -> impl Filter + Clone { + warp::path::end().map(|| "Angelshark extension route index. Enable extensions with feature switches and access them at `/extensions/`.") +} diff --git a/angelsharkd/src/routes/extensions/simple_deprov.rs b/angelsharkd/src/routes/extensions/simple_deprov.rs new file mode 100644 index 0000000..2b5ad40 --- /dev/null +++ b/angelsharkd/src/routes/extensions/simple_deprov.rs @@ -0,0 +1,5 @@ +use warp::{Filter, Rejection, Reply}; + +pub fn filter() -> impl Filter + Clone { + warp::path("deprov").map(|| -> &str { todo!() }) // TODO: +} diff --git a/angelsharkd/src/routes/extensions/simple_search.rs b/angelsharkd/src/routes/extensions/simple_search.rs new file mode 100644 index 0000000..454dba3 --- /dev/null +++ b/angelsharkd/src/routes/extensions/simple_search.rs @@ -0,0 +1,14 @@ +use crate::config::Config; +use std::convert::Infallible; +use warp::{path, post, Filter, Rejection, Reply}; + +const CMD_LIST_EXT: &str = "list extension-type"; +const CMD_LIST_STAT: &str = "list station"; + +pub fn filter() -> impl Filter + Clone { + path("search").and(post()).and_then(handle_simple_search) +} + +async fn handle_simple_search() -> Result { + Ok("Search!") +} -- cgit v1.2.3