fmt: fmt and clippy
This commit is contained in:
parent
b9bcd5352e
commit
6374b44e08
3 changed files with 32 additions and 45 deletions
|
@ -1,10 +1,9 @@
|
|||
use dotenv::dotenv;
|
||||
use ldap3::{LdapConn, Mod, Scope, SearchEntry};
|
||||
use skynet_ldap_backend::{get_config, Config};
|
||||
use std::{env, io};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use csv;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> tide::Result<()> {
|
||||
|
@ -18,21 +17,16 @@ async fn main() -> tide::Result<()> {
|
|||
}
|
||||
|
||||
async fn update_users(config: &Config) -> tide::Result<()> {
|
||||
let mut users_tmp = vec![
|
||||
// default user to ensure group is never empty
|
||||
String::from("compsoc"),
|
||||
];
|
||||
let mut users_tmp = HashSet::new();
|
||||
// default user to ensure group is never empty
|
||||
users_tmp.insert(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());
|
||||
users_tmp.insert(user.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
for user in from_csv(config).await.unwrap_or_default() {
|
||||
users_tmp.push(user);
|
||||
}
|
||||
/*
|
||||
pull in data from wolves (csv or api (hopefully api)
|
||||
pull entire ldap data
|
||||
|
@ -40,16 +34,15 @@ async fn update_users(config: &Config) -> tide::Result<()> {
|
|||
for every valid user in wolves match to ldap
|
||||
add to users
|
||||
*/
|
||||
// pull from wolves csv
|
||||
for user in from_csv(config).await.unwrap_or_default() {
|
||||
users_tmp.insert(user);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
users_tmp.remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,8 +125,7 @@ async fn update_group(config: &Config, group: &str, users: &[&str], replace: boo
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>, HashMap<String, String>), Box<dyn Error>>{
|
||||
|
||||
async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>, HashMap<String, String>), Box<dyn Error>> {
|
||||
// connect to ldap
|
||||
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
||||
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
|
||||
|
@ -141,21 +133,17 @@ async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>,
|
|||
let mut uid_idstudent: HashMap<String, String> = HashMap::new();
|
||||
let mut uid_email: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let (rs, _res) = ldap.search(
|
||||
"ou=users,dc=skynet,dc=ie",
|
||||
Scope::OneLevel,
|
||||
"(objectClass=*)",
|
||||
vec!["uid", "mail", "skID", "skSecure"]
|
||||
)
|
||||
.unwrap()
|
||||
.success()
|
||||
.unwrap();
|
||||
let (rs, _res) = ldap
|
||||
.search("ou=users,dc=skynet,dc=ie", Scope::OneLevel, "(objectClass=*)", vec!["uid", "mail", "skID", "skSecure"])
|
||||
.unwrap()
|
||||
.success()
|
||||
.unwrap();
|
||||
|
||||
for entry in rs {
|
||||
let tmp = SearchEntry::construct(entry);
|
||||
let tmp = SearchEntry::construct(entry);
|
||||
|
||||
// skSecure is a standin for teh password, only 1 if the password is SSHA512
|
||||
if !tmp.attrs.contains_key("skSecure"){
|
||||
if !tmp.attrs.contains_key("skSecure") {
|
||||
continue;
|
||||
}
|
||||
if tmp.attrs["skSecure"].is_empty() {
|
||||
|
@ -165,7 +153,7 @@ async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>,
|
|||
// make sure there is an id;
|
||||
let uid = if !tmp.attrs["uid"].is_empty() {
|
||||
tmp.attrs["uid"][0].clone()
|
||||
}else {
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -188,7 +176,7 @@ async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>,
|
|||
Ok((uid_idstudent, uid_email))
|
||||
}
|
||||
|
||||
async fn from_csv(config: &Config) -> Result<HashSet<String>, Box<dyn Error>>{
|
||||
async fn from_csv(config: &Config) -> Result<HashSet<String>, Box<dyn Error>> {
|
||||
let mut uids = HashSet::new();
|
||||
|
||||
let (uid_idstudent, uid_email) = ldap_get_accounts(config).await?;
|
||||
|
@ -206,11 +194,10 @@ async fn from_csv(config: &Config) -> Result<HashSet<String>, Box<dyn Error>>{
|
|||
Ok(uids)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Record {
|
||||
#[serde(rename = "MemID")]
|
||||
id_wolves: String,
|
||||
// #[serde(rename = "MemID")]
|
||||
// id_wolves: String,
|
||||
#[serde(rename = "Student Num")]
|
||||
id_student: String,
|
||||
#[serde(rename = "Contact Email")]
|
||||
|
|
Loading…
Reference in a new issue