diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index b356964..a1711b1 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -7,16 +7,54 @@ use std::env; async fn main() -> tide::Result<()> { let config = get_config(); - //update_users(&config).await; + update_users(&config).await?; update_admin(&config).await?; update_committee(&config).await?; Ok(()) } -//async fn update_users(config: &Config) { +async fn update_users(config: &Config) -> tide::Result<()> { + let mut users_tmp = vec![ + // default user to ensure group is never empty + String::from("compsoc"), + ]; + + // add lifetime folks + if let Ok(x) = env::var("USERS_LIFETIME") { + for user in x.split(',').collect::>() { + users_tmp.push(user.to_string()); + } + } + + /* + pull in data from wolves (csv or api (hopefully api) + pull entire ldap data + + for every valid user in wolves match to ldap + add to users + */ + + // sorting makes it easier/faster + users_tmp.sort(); + if let Ok(x) = env::var("USERS_BANNED") { + for user in x.split(',').collect::>() { + // find its position + while let Ok(index) = users_tmp.binary_search(&user.to_string()) { + // in case it just so happens to be there multiple times + users_tmp.remove(index); + } + } + } + + // easier to work with Strings above but easier to work with &str below + let users: Vec<&str> = users_tmp.iter().map(|s| &**s).collect(); + + update_group(config, "skynet-users", &users, true).await?; + + Ok(()) +} -//} fn uid_to_dn(uid: &str) -> String { format!("uid={},ou=users,dc=skynet,dc=ie", uid) }