summaryrefslogtreecommitdiff
path: root/angelsharkd/src/routes/extensions/simple_deprov.rs
blob: eb6f04b02f7fd5ddedc25178fd61a7f41f363d4e (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
35
36
37
38
39
40
41
42
43
44
45
use std::{convert::Infallible, fmt::Display};

use libangelshark::{AcmRunner, Message};
use serde::Deserialize;
use warp::{
    body::{content_length_limit, json},
    post, Filter, Rejection, Reply,
};

pub fn filter(runner: AcmRunner) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    warp::path("deprov")
        .and(post())
        .and(content_length_limit(1024 * 16))
        .and(json())
        .and_then(move |entries: Entries| remove_entries(entries, runner.to_owned()))
}

async fn remove_entries(entries: Entries, mut runner: AcmRunner) -> Result<impl Reply, Infallible> {
    for entry in entries {
        match entry {
            Entry::StationUser { acm, ext } => {
                runner.queue_input(&acm, &Message::new(&format!("clear amw all {}", ext)));
                runner.queue_input(&acm, &Message::new(&format!("remove station {}", ext)));
            }
            Entry::AgentLoginId { acm, ext } => {
                runner.queue_input(
                    &acm,
                    &Message::new(&format!("remove agent-loginID {}", ext)),
                );
            }
        }
    }
    dbg!(&runner);
    Ok("")
}

type Entries = Vec<Entry>;

#[derive(Debug, Deserialize)]
enum Entry {
    #[serde(rename(deserialize = "station-user"))]
    StationUser { acm: String, ext: String },
    #[serde(rename(deserialize = "agent-loginid"))]
    AgentLoginId { acm: String, ext: String },
}