diff options
author | Carpenter, Adam (CORP) <adam.carpenter@adp.com> | 2021-12-10 11:11:33 -0500 |
---|---|---|
committer | Carpenter, Adam (CORP) <adam.carpenter@adp.com> | 2021-12-10 11:11:33 -0500 |
commit | 7b6b942b8d70f5bcf0c48ecf2c67c4af460d98ab (patch) | |
tree | d3fa2e539c38f795a6689d77546e99290e1311f9 /angelsharkd/src/routes | |
parent | a91ee6ff6467d131c76151fb18ca2c55345db188 (diff) | |
download | altruistic-angelshark-7b6b942b8d70f5bcf0c48ecf2c67c4af460d98ab.tar.xz altruistic-angelshark-7b6b942b8d70f5bcf0c48ecf2c67c4af460d98ab.zip |
feat: complete impl simple deprov
Diffstat (limited to 'angelsharkd/src/routes')
-rw-r--r-- | angelsharkd/src/routes/extensions/simple_deprov.rs | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/angelsharkd/src/routes/extensions/simple_deprov.rs b/angelsharkd/src/routes/extensions/simple_deprov.rs index eb6f04b..df818f0 100644 --- a/angelsharkd/src/routes/extensions/simple_deprov.rs +++ b/angelsharkd/src/routes/extensions/simple_deprov.rs @@ -1,21 +1,25 @@ -use std::{convert::Infallible, fmt::Display}; - -use libangelshark::{AcmRunner, Message}; +use libangelshark::{AcmRunner, Message, ParallelIterator}; use serde::Deserialize; +use std::convert::Infallible; use warp::{ body::{content_length_limit, json}, - post, Filter, Rejection, Reply, + post, reply, Filter, Rejection, Reply, }; +const SIXTEEN_K: u64 = 1024 * 16; + +/// Returns a warp filter to handle HTTP POSTs for deprovisioning stations, agents, etc. 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(content_length_limit(SIXTEEN_K)) .and(json()) - .and_then(move |entries: Entries| remove_entries(entries, runner.to_owned())) + .and_then(move |entries| remove_entries(entries, runner.to_owned())) } +/// Queues removal commands for [Entries] on an [AcmRunner]. Gathers any errors encountered and returns those. async fn remove_entries(entries: Entries, mut runner: AcmRunner) -> Result<impl Reply, Infallible> { + // Construct OSSI messages to carry out removals. for entry in entries { match entry { Entry::StationUser { acm, ext } => { @@ -30,12 +34,27 @@ async fn remove_entries(entries: Entries, mut runner: AcmRunner) -> Result<impl } } } - dbg!(&runner); - Ok("") + + // Gather any errors encountered and format them for the client response. + let errors: Vec<String> = runner + .run_cached() + .map(|(acm, output)| match output { + Ok(messages) => messages + .into_iter() + .filter_map(|message| Some(format!("ACM {}: {}", acm.clone(), message.error?))) + .collect(), + Err(error) => vec![format!("ACM {}: {}", acm, error)], + }) + .flatten() + .collect(); + + Ok(reply::json(&errors)) } +/// Collection of [Entry]. type Entries = Vec<Entry>; +/// Very basic [Deserialize] target for deprov inputs. Going from stringly typed to strongly typed. #[derive(Debug, Deserialize)] enum Entry { #[serde(rename(deserialize = "station-user"))] |