diff --git a/labadoor-csv/src/acl.rs b/labadoor-csv/src/acl.rs new file mode 100644 index 0000000..16eab04 --- /dev/null +++ b/labadoor-csv/src/acl.rs @@ -0,0 +1,66 @@ +use crate::CSV; +use labadoor_acl::{ACLEntry, AuthMethod, ResourceShortcuts, ACL}; + +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"); + return if let Some(r) = res { + Some(r.username) + } else { + None + }; + } + 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"); + return if let Some(r) = res { + Some(r.resource) + } else { + None + }; + } + fn is_allowed(&self, username: String, resource: String) -> Option<()> { + let needle = ACLEntry { username, resource }; + let res = self.find::(needle, "acl_entries.csv"); + return if let Some(r) = res { Some(()) } else { None }; + } +} diff --git a/labadoor-csv/src/lib.rs b/labadoor-csv/src/lib.rs index 6aa659f..ed4be3b 100644 --- a/labadoor-csv/src/lib.rs +++ b/labadoor-csv/src/lib.rs @@ -1,6 +1,7 @@ -use labadoor_acl::{ACLEntry, AuthMethod, ResourceShortcuts, ACL}; use serde::Deserialize; +pub mod acl; + pub struct CSVArgs { pub path: String, } @@ -20,7 +21,6 @@ pub struct CSV { 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 @@ -31,67 +31,3 @@ impl CSV { .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"); - return if let Some(r) = res { - Some(r.username) - } else { - None - }; - } - 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"); - return if let Some(r) = res { - Some(r.resource) - } else { - None - }; - } - fn is_allowed(&self, username: String, resource: String) -> Option<()> { - let needle = ACLEntry { username, resource }; - let res = self.find::(needle, "acl_entries.csv"); - return if let Some(r) = res { Some(()) } else { None }; - } -}