feat: add proper env vars for home and the csv

This commit is contained in:
silver 2023-07-17 01:24:52 +01:00
parent 480860ca26
commit f73a7dfa29
4 changed files with 19 additions and 13 deletions

View file

@ -35,7 +35,6 @@ async fn update_users(config: &Config) -> tide::Result<()> {
for every valid user in wolves match to ldap
add to users
*/
println!("{:#?}", users_tmp);
// pull from wolves csv
for user in from_csv(config).await.unwrap_or_default() {
users_tmp.insert(user);
@ -48,8 +47,6 @@ async fn update_users(config: &Config) -> tide::Result<()> {
}
}
println!("{:#?}", users_tmp);
// easier to work with Strings above but easier to work with &str below
let users: Vec<&str> = users_tmp.iter().map(|s| &**s).collect();
@ -184,7 +181,7 @@ 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?;
let records = read_csv()?;
let records = read_csv(config)?;
let now = Utc::now();
let today = format!("{}-{:02}-{:02}", now.year(), now.month(), now.day());
@ -218,10 +215,10 @@ struct Record {
expiry: String,
}
fn read_csv() -> Result<Vec<Record>, Box<dyn Error>> {
fn read_csv(config: &Config) -> Result<Vec<Record>, Box<dyn Error>> {
let mut records: Vec<Record> = vec![];
if let Ok(mut rdr) = csv::Reader::from_path("tmp.csv") {
if let Ok(mut rdr) = csv::Reader::from_path(format!("{}/{}", &config.home, &config.csv)) {
for result in rdr.deserialize() {
// Notice that we need to provide a type hint for automatic
// deserialization.