feat: basic structure for general suers, still need the wolves api

This commit is contained in:
silver 2023-06-18 19:10:46 +01:00
parent a3e95c5e10
commit 14b0531680

View file

@ -7,16 +7,54 @@ use std::env;
async fn main() -> tide::Result<()> { async fn main() -> tide::Result<()> {
let config = get_config(); let config = get_config();
//update_users(&config).await; update_users(&config).await?;
update_admin(&config).await?; update_admin(&config).await?;
update_committee(&config).await?; update_committee(&config).await?;
Ok(()) 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::<Vec<&str>>() {
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::<Vec<&str>>() {
// 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 { fn uid_to_dn(uid: &str) -> String {
format!("uid={},ou=users,dc=skynet,dc=ie", uid) format!("uid={},ou=users,dc=skynet,dc=ie", uid)
} }