From 94f26c59c6f295a4f9354e9e2b2f39a52af6b247 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 14 Feb 2019 19:00:21 -0800 Subject: [PATCH] Added some comments and add a few expects --- src/ldap.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ldap.rs b/src/ldap.rs index d0270e1..1105cda 100644 --- a/src/ldap.rs +++ b/src/ldap.rs @@ -17,6 +17,7 @@ use crate::db::models::{Invitation, User}; use crate::db::DbConn; use crate::CONFIG; +/// Generates invites for all users in LDAP who don't yet have an account or invite. fn invite_from_results(conn: DbConn, results: Vec) -> Result<(), Box> { let mail_field = CONFIG.ldap_mail_field(); for ldap_user in results { @@ -40,6 +41,7 @@ fn invite_from_results(conn: DbConn, results: Vec) -> Result<(), Bo Ok(()) } +/// Initializes an LdapConnAsync client using provided configuration fn new_ldap_client_async(handle: &Handle) -> Result> { let scheme = if CONFIG.ldap_ssl() { "ldaps" } else { "ldap" }; let host = CONFIG.ldap_host().unwrap(); @@ -52,6 +54,7 @@ fn new_ldap_client_async(handle: &Handle) -> Result> { Ok(ldap) } +/// Given syncs users from LDAP fn ldap_sync(handle: &Handle) -> Result<(), Box> { let handle = handle.clone(); @@ -84,7 +87,7 @@ fn ldap_sync(handle: &Handle) -> Result<(), Box> { } let conn = db::get_dbconn().expect("Can't reach database"); // Can't figure out how to use this result - invite_from_results(conn, entries); + invite_from_results(conn, entries).expect("Could not invite users"); Ok(()) }) .map_err(|e| panic!("Error searching: {:?}", e)); @@ -94,6 +97,7 @@ fn ldap_sync(handle: &Handle) -> Result<(), Box> { Ok(()) } +/// Starts a new thread with event loop to sync LDAP users pub fn start_ldap_sync() -> Result<(), Box> { thread::spawn(move || { let mut core = Core::new().expect("Could not create core"); @@ -105,10 +109,10 @@ pub fn start_ldap_sync() -> Result<(), Box> { let task = Interval::new(now, Duration::from_secs(sync_interval)) .for_each(|_| { // Can't figure out how to get this error handled - ldap_sync(&handle); + ldap_sync(&handle).expect("Failed to sync from LDAP"); Ok(()) }) - .map_err(|e| panic!("interval errored: {:?}", e)); + .map_err(|e| panic!("LDAP sync interval errored: {:?}", e)); core.run(task) });