feat: turned group add into a nice function

This commit is contained in:
silver 2023-06-18 17:33:39 +01:00
parent 4e6c810e7b
commit dc7139a86f

View file

@ -38,20 +38,24 @@ fn uid_to_dn(uid: &str) -> String{
}
async fn update_admin(config: &Config) -> tide::Result<()>{
let users = vec!["silver", "evanc", "eoghanconlon73"];
update_group(config,"skynet-admins", &users).await?;
Ok(())
}
async fn update_group(config: &Config, group: &str, users: &Vec<&str>) -> tide::Result<()>{
let mut ldap = LdapConn::new(&config.ldap_host)?;
// use the admin account
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
// read from config file
let users = vec!["silver", "evanc", "eoghanconlon73", "pio"];
let dn_skynet_admins = "cn=skynet-admins,ou=groups,dc=skynet,dc=ie";
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 mods = vec![Mod::Replace("member".to_string(), skynet_admins)];
ldap.modify(&dn_skynet_admins, mods)?.success()?;
let dn_skynet_admins_linux = "cn=skynet-admins-linux,ou=groups,dc=skynet,dc=ie";
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 mods = vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)];
ldap.modify(&dn_skynet_admins_linux, mods)?.success()?;