From 435cda893bd74bd8e597876f4b5f515c8347f9de Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 15:59:29 +0300 Subject: Read preapproved users CSV file from config --- src/db.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index e7fb137..2187010 100644 --- a/src/db.rs +++ b/src/db.rs @@ -15,8 +15,6 @@ use log::debug; use parking_lot::RwLock; use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; -const PREAPPROVED_STU_FILENAME: &str = "students.csv"; - #[derive(Debug, Clone, Default)] pub struct Db { pub blockchain: Arc>, @@ -35,7 +33,7 @@ impl Db { let users: HashMap = get_friendly_users(); // Read the list of users who can register - let preapproved_users = read_approved_users(); + let preapproved_users = read_approved_users(&config.preapproved_users); let mut db = Db { blockchain: Arc::new(RwLock::new(Block::default())), @@ -184,14 +182,14 @@ fn get_friendly_users() -> HashMap { users } -fn read_approved_users() -> Vec { +fn read_approved_users(filename: &str) -> Vec { let mut approved_students: Vec = Vec::new(); - let contents = fs::read_to_string(PREAPPROVED_STU_FILENAME).unwrap_or_else(|_| { + let contents = fs::read_to_string(filename).unwrap_or_else(|_| { panic!( "{}", format!( "Expected {} in place to load preapproved students", - PREAPPROVED_STU_FILENAME + filename ) ) }); -- cgit v1.2.3-70-g09d2