fmt: fmt and clippy

This commit is contained in:
silver 2023-07-17 00:14:48 +01:00
parent b9bcd5352e
commit 6374b44e08
3 changed files with 32 additions and 45 deletions

View file

@ -1,10 +1,9 @@
use dotenv::dotenv; use dotenv::dotenv;
use ldap3::{LdapConn, Mod, Scope, SearchEntry}; use ldap3::{LdapConn, Mod, Scope, SearchEntry};
use skynet_ldap_backend::{get_config, Config}; use skynet_ldap_backend::{get_config, Config};
use std::{env, io};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env;
use std::error::Error; use std::error::Error;
use csv;
#[async_std::main] #[async_std::main]
async fn main() -> tide::Result<()> { async fn main() -> tide::Result<()> {
@ -18,21 +17,16 @@ async fn main() -> tide::Result<()> {
} }
async fn update_users(config: &Config) -> tide::Result<()> { async fn update_users(config: &Config) -> tide::Result<()> {
let mut users_tmp = vec![ let mut users_tmp = HashSet::new();
// default user to ensure group is never empty // default user to ensure group is never empty
String::from("compsoc"), users_tmp.insert(String::from("compsoc"));
];
// add lifetime folks
if let Ok(x) = env::var("USERS_LIFETIME") { if let Ok(x) = env::var("USERS_LIFETIME") {
for user in x.split(',').collect::<Vec<&str>>() { 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 in data from wolves (csv or api (hopefully api)
pull entire ldap data 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 for every valid user in wolves match to ldap
add to users 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 // sorting makes it easier/faster
users_tmp.sort();
if let Ok(x) = env::var("USERS_BANNED") { if let Ok(x) = env::var("USERS_BANNED") {
for user in x.split(',').collect::<Vec<&str>>() { for user in x.split(',').collect::<Vec<&str>>() {
// find its position users_tmp.remove(user);
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);
}
} }
} }
@ -133,7 +126,6 @@ async fn update_group(config: &Config, group: &str, users: &[&str], replace: boo
} }
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 // connect to ldap
let mut ldap = LdapConn::new(&config.ldap_host)?; let mut ldap = LdapConn::new(&config.ldap_host)?;
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?; ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
@ -141,12 +133,8 @@ async fn ldap_get_accounts(config: &Config) -> Result<(HashMap<String, String>,
let mut uid_idstudent: HashMap<String, String> = HashMap::new(); let mut uid_idstudent: HashMap<String, String> = HashMap::new();
let mut uid_email: HashMap<String, String> = HashMap::new(); let mut uid_email: HashMap<String, String> = HashMap::new();
let (rs, _res) = ldap.search( let (rs, _res) = ldap
"ou=users,dc=skynet,dc=ie", .search("ou=users,dc=skynet,dc=ie", Scope::OneLevel, "(objectClass=*)", vec!["uid", "mail", "skID", "skSecure"])
Scope::OneLevel,
"(objectClass=*)",
vec!["uid", "mail", "skID", "skSecure"]
)
.unwrap() .unwrap()
.success() .success()
.unwrap(); .unwrap();
@ -206,11 +194,10 @@ async fn from_csv(config: &Config) -> Result<HashSet<String>, Box<dyn Error>>{
Ok(uids) Ok(uids)
} }
#[derive(Debug, serde::Deserialize)] #[derive(Debug, serde::Deserialize)]
struct Record { struct Record {
#[serde(rename = "MemID")] // #[serde(rename = "MemID")]
id_wolves: String, // id_wolves: String,
#[serde(rename = "Student Num")] #[serde(rename = "Student Num")]
id_student: String, id_student: String,
#[serde(rename = "Contact Email")] #[serde(rename = "Contact Email")]