fmt: fmt and clippy
This commit is contained in:
parent
a990f31a45
commit
9cba5ce94a
1 changed files with 16 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::env;
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use ldap3::{LdapConn, Mod};
|
use ldap3::{LdapConn, Mod};
|
||||||
use skynet_ldap_server::{Config, get_config};
|
use skynet_ldap_server::{get_config, Config};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[async_std::main]
|
#[async_std::main]
|
||||||
async fn main() -> tide::Result<()> {
|
async fn main() -> tide::Result<()> {
|
||||||
|
@ -13,36 +13,35 @@ async fn main() -> tide::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//async fn update_users(config: &Config) {
|
//async fn update_users(config: &Config) {
|
||||||
|
|
||||||
//}
|
//}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_admin(config: &Config) -> tide::Result<()>{
|
async fn update_admin(config: &Config) -> tide::Result<()> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
// read from teh env
|
// read from teh env
|
||||||
if let Ok(x) = env::var("USERS_ADMIN") {
|
if let Ok(x) = env::var("USERS_ADMIN") {
|
||||||
let users = x.split(',').collect::<Vec<&str>>();
|
let users = x.split(',').collect::<Vec<&str>>();
|
||||||
|
|
||||||
update_group(config,"skynet-admins", &users, true).await?;
|
update_group(config, "skynet-admins", &users, true).await?;
|
||||||
// admins automatically get added as users
|
// admins automatically get added as users
|
||||||
update_group(config,"skynet-users", &users, false).await?;
|
update_group(config, "skynet-users", &users, false).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_group(config: &Config, group: &str, users: &Vec<&str>, replace: bool) -> tide::Result<()>{
|
async fn update_group(config: &Config, group: &str, users: &[&str], replace: bool) -> 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()?;
|
||||||
|
|
||||||
let dn = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
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 members = users.iter().map(|uid| uid_to_dn(uid)).collect();
|
||||||
let mods = if replace {
|
let mods = if replace {
|
||||||
vec![Mod::Replace("member".to_string(), members)]
|
vec![Mod::Replace("member".to_string(), members)]
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,13 +53,13 @@ async fn update_group(config: &Config, group: &str, users: &Vec<&str>, replace:
|
||||||
}
|
}
|
||||||
|
|
||||||
let dn_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group);
|
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 members_linux = users.iter().map(|uid| uid.to_string()).collect();
|
||||||
let mods = if replace {
|
let mods = if replace {
|
||||||
vec![Mod::Replace("memberUid".to_string(), members_linux)]
|
vec![Mod::Replace("memberUid".to_string(), members_linux)]
|
||||||
} else {
|
} else {
|
||||||
vec![Mod::Add("memberUid".to_string(), members_linux)]
|
vec![Mod::Add("memberUid".to_string(), members_linux)]
|
||||||
};
|
};
|
||||||
if let Err(x) = ldap.modify(&dn_linux, mods){
|
if let Err(x) = ldap.modify(&dn_linux, mods) {
|
||||||
println!("{:?}", x);
|
println!("{:?}", x);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue