diff --git a/src/controller/list.rs b/src/controller/list.rs index dcbed40..9a2f9f9 100644 --- a/src/controller/list.rs +++ b/src/controller/list.rs @@ -4,19 +4,31 @@ use anyhow::{anyhow, bail, Ok, Result}; use ory_kratos_client::models::Identity; use serde_json::Value; -use tracing::{error, info, debug}; +use tracing::{debug, error, info}; use crate::config::SiriusConfig; fn populate_set(projects: &mut HashSet, mut data: Value, request_id: &str) -> Result<()> { let data = data.take(); - let data = data - .as_object() - .ok_or_else(|| anyhow!("{request_id}: This should be a map!"))?; - if !data.is_empty() { - for (key, _) in data.iter() { - projects.insert(key.to_owned()); + match data { + Value::Object(map) => { + if !map.is_empty() { + for (key, _) in map.iter() { + projects.insert(key.to_owned()); + } + } + } + Value::Array(array) => { + if !array.is_empty() { + for project in array.iter() { + let project = project + .as_str() + .ok_or_else(|| anyhow!(" this shoud be a string"))?; + projects.insert(project.to_owned()); + } + } } + _ => bail!("{request_id}: This should be a map or an array!"), } Ok(()) } diff --git a/src/controller/update.rs b/src/controller/update.rs index 6f53812..f7a0b48 100644 --- a/src/controller/update.rs +++ b/src/controller/update.rs @@ -229,7 +229,7 @@ pub mod test_controler { .create_async() .await; */ let identity = serde_json::from_str(IDENTITY_USER).unwrap(); - update_controller(Arc::new(config), vec![data], uuid, identity) + update_controller(Arc::new(config), vec![data], uuid, identity, "project") .await .unwrap(); kratos_mock.assert_async().await; @@ -269,9 +269,15 @@ pub mod test_controler { .await; */ let identity = serde_json::from_str(IDENTITY_USER).unwrap(); - update_controller(Arc::new(config), vec![data.clone(), data], uuid, identity) - .await - .unwrap(); + update_controller( + Arc::new(config), + vec![data.clone(), data], + uuid, + identity, + "project", + ) + .await + .unwrap(); kratos_mock.assert_async().await; // opa_mock.assert_async().await; }