summaryrefslogtreecommitdiff
path: root/angelsharkd/src/routes/extensions/mod.rs
blob: b1c5aa3f86eb5242f9ce67163459bd4c4b306dfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::sync::{Arc, Mutex};

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<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());

    #[cfg(feature = "simple_search")]
    let runner = config.runner.clone();
    #[cfg(feature = "simple_search")]
    let haystack = simple_search::Haystack::new();
    #[cfg(feature = "simple_search")]
    let filters = filters
        .or(simple_search::search(haystack.clone()))
        .or(simple_search::refresh(runner, haystack));

    #[cfg(feature = "simple_deprov")]
    let filters = filters.or(simple_deprov::filter());

    path("extensions").and(filters)
}

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>`.")
}