From a990f31a453b253f9fa072a4e78eef33f38dd614 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 18 Jun 2023 18:32:52 +0100 Subject: [PATCH] fix: little bit of a tidy up --- src/bin/update_groups.rs | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index ffe3674..21c1878 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -1,25 +1,8 @@ -use std::collections::HashSet; -use sqlx::{Pool, Sqlite}; use std::env; use dotenv::dotenv; use ldap3::{LdapConn, Mod}; -use tide::prelude::*; use skynet_ldap_server::{Config, get_config}; -/* -https://ticketbooking.dublincoach.ie/MobileAPI/MobileBooking/GetTrackToStageName?FromStage=University%20of%20Limerick -https://ticketbooking.dublincoach.ie/MobileAPI/MobileBooking/GetJourneyList?FromStageName=University%20of%20Limerick&ToStageName=Red%20Cow%20LUAS&JourneyType=0&RouteID=0&JrEndStageID=0&IsStageSelection=1 - - -From - University of Limerick -To - Dublin City - Ennis - Killarney - Tralee - */ - #[async_std::main] async fn main() -> tide::Result<()> { let config = get_config(); @@ -58,29 +41,30 @@ async fn update_group(config: &Config, group: &str, users: &Vec<&str>, replace: // use the admin account ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?; - let dn_skynet_admins = format!("cn={},ou=groups,dc=skynet,dc=ie", group); - let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect(); + let dn = format!("cn={},ou=groups,dc=skynet,dc=ie", group); + let members = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect(); let mods = if replace { - vec![Mod::Replace("member".to_string(), skynet_admins)] + vec![Mod::Replace("member".to_string(), members)] } else { - vec![Mod::Add("member".to_string(), skynet_admins)] + vec![Mod::Add("member".to_string(), members)] }; - if let Err(x) = ldap.modify(&dn_skynet_admins, mods) { + if let Err(x) = ldap.modify(&dn, mods) { println!("{:?}", x); } - let dn_skynet_admins_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group); - let skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect(); + let dn_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group); + let members_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect(); let mods = if replace { - vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)] + vec![Mod::Replace("memberUid".to_string(), members_linux)] } else { - vec![Mod::Add("memberUid".to_string(), skynet_admins_linux)] + vec![Mod::Add("memberUid".to_string(), members_linux)] }; - if let Err(x) = ldap.modify(&dn_skynet_admins_linux, mods){ + if let Err(x) = ldap.modify(&dn_linux, mods){ println!("{:?}", x); }; + // tidy up ldap.unbind()?; Ok(())