feat: turned group add into a nice function
This commit is contained in:
parent
4e6c810e7b
commit
dc7139a86f
1 changed files with 12 additions and 8 deletions
|
@ -38,20 +38,24 @@ fn uid_to_dn(uid: &str) -> String{
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_admin(config: &Config) -> tide::Result<()>{
|
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)?;
|
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
||||||
|
|
||||||
// use the admin account
|
// use the admin account
|
||||||
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
|
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
|
||||||
|
|
||||||
// read from config file
|
let dn_skynet_admins = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
||||||
let users = vec!["silver", "evanc", "eoghanconlon73", "pio"];
|
|
||||||
|
|
||||||
let dn_skynet_admins = "cn=skynet-admins,ou=groups,dc=skynet,dc=ie";
|
|
||||||
let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect();
|
let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect();
|
||||||
let mods = vec![Mod::Replace("member".to_string(), skynet_admins)];
|
let mods = vec![Mod::Replace("member".to_string(), skynet_admins)];
|
||||||
ldap.modify(&dn_skynet_admins, mods)?.success()?;
|
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 skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect();
|
||||||
let mods = vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)];
|
let mods = vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)];
|
||||||
ldap.modify(&dn_skynet_admins_linux, mods)?.success()?;
|
ldap.modify(&dn_skynet_admins_linux, mods)?.success()?;
|
||||||
|
|
Loading…
Reference in a new issue