use labadoor_acl::{ACLEntry, AuthMethod, ResourceShortcuts, ACL}; use serde::Deserialize; pub struct CSV { pub path: String, } impl CSV { fn find Deserialize<'a> + PartialEq>(&self, needle: T, path: &str) -> Option { let p = format!("{}/{}", self.path, path); println!("{}", p); let file = std::fs::File::open(p).unwrap(); let mut reader = csv::Reader::from_reader(file); reader .deserialize() .map(|x: Result| x.unwrap()) .collect::>() .into_iter() .find(|x: &T| x == &needle) } } impl ACL for CSV { /// ACLEntry fn allow_access(&self, user: String, resource: String) { todo!(); } fn deny_access(&self, user: Option, resource: Option) { todo!(); } /// AuthMethod fn add_auth_method(&self, user: String, method: String, identifier: String) { todo!(); } fn del_auth_method( &self, user: Option, method: Option, identifier: Option, ) { todo!(); } /// ResourceShortcuts fn add_shortcut(&self, user: String, resource: String, shortcut: i8) { todo!(); } fn del_shortcut(&self, user: Option, resource: Option, shortcut: Option) { todo!(); } /// Queries fn get_username(&self, method: String, identifier: String) -> Option { let needle = AuthMethod { method: method, identifier: identifier, username: "".to_string(), }; let res = self.find::(needle, "auth_methods.csv").unwrap(); Some(res.username) } fn get_resource(&self, username: String, id: i8) -> Option { let needle = ResourceShortcuts { username: username, id: id, resource: "".to_string(), }; let res = self .find::(needle, "resource_shortcuts.csv") .unwrap(); Some(res.resource) } fn is_allowed(&self, username: String, resource: String) -> Option<()> { let needle = ACLEntry { username, resource }; self.find::(needle, "acl_entries.csv").unwrap(); Some(()) } }