diff options
author | Adam Carpenter <adam.carpenter@adp.com> | 2021-12-01 09:35:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-01 09:35:06 -0500 |
commit | 37c5cdff434e86778977a7d7fd00d80b71fcf363 (patch) | |
tree | a582caae4e8c0706041497fb16a2525a14002c2e /angelsharkd/src/routes/extensions/mod.rs | |
parent | 9a940e64d55c4144fb65c702241eeac99a426bd1 (diff) | |
parent | e18d0c1a4189d5278639a9b323ae3794118566bc (diff) | |
download | altruistic-angelshark-37c5cdff434e86778977a7d7fd00d80b71fcf363.tar.xz altruistic-angelshark-37c5cdff434e86778977a7d7fd00d80b71fcf363.zip |
Merge pull request #5 from adpllc/extensions
Extensions and simple extension search
Diffstat (limited to 'angelsharkd/src/routes/extensions/mod.rs')
-rw-r--r-- | angelsharkd/src/routes/extensions/mod.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/angelsharkd/src/routes/extensions/mod.rs b/angelsharkd/src/routes/extensions/mod.rs new file mode 100644 index 0000000..7f217d6 --- /dev/null +++ b/angelsharkd/src/routes/extensions/mod.rs @@ -0,0 +1,35 @@ +use crate::config::Config; +use warp::{path, Filter, Rejection, Reply}; + +#[cfg(feature = "simple_deprov")] +mod simple_deprov; +#[cfg(feature = "simple_search")] +mod simple_search; + +/// The extension filter; consists of all compiled optional Angelshark extension +/// filters combined under `/extensions`. +pub fn filter(config: &Config) -> impl Filter<Extract = impl Reply, Error = Rejection> + 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()); + + // Block to enable simple_search extension feature. Instantiates a + // searchable haystack and configures filters to handle search requests. + #[cfg(feature = "simple_search")] + let haystack = simple_search::Haystack::new(config.runner.clone()); + #[cfg(feature = "simple_search")] + let filters = filters + .or(simple_search::search_filter(haystack.clone())) + .or(simple_search::refresh_filter(haystack)); + + #[cfg(feature = "simple_deprov")] + let filters = filters.or(simple_deprov::filter()); + + path("extensions").and(filters) +} + +/// The default, informational extension route. +fn default() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { + warp::path::end().map(|| "Angelshark extension route index. Enable extensions with feature switches and access them at `/extensions/<feature>`.") +} |