diff options
author | necrashter | 2022-04-23 15:59:29 +0300 |
---|---|---|
committer | Yigit Sever | 2022-04-23 18:10:12 +0300 |
commit | 435cda893bd74bd8e597876f4b5f515c8347f9de (patch) | |
tree | c3939c359d934e78548ad49bbb3290ab8a53530e /src/db.rs | |
parent | bcf7a379620ca433215ad9617ad9417b4f39e87d (diff) | |
download | gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.gz gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.bz2 gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.zip |
Read preapproved users CSV file from config
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -15,8 +15,6 @@ use log::debug; | |||
15 | use parking_lot::RwLock; | 15 | use parking_lot::RwLock; |
16 | use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; | 16 | use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; |
17 | 17 | ||
18 | const PREAPPROVED_STU_FILENAME: &str = "students.csv"; | ||
19 | |||
20 | #[derive(Debug, Clone, Default)] | 18 | #[derive(Debug, Clone, Default)] |
21 | pub struct Db { | 19 | pub struct Db { |
22 | pub blockchain: Arc<RwLock<Block>>, | 20 | pub blockchain: Arc<RwLock<Block>>, |
@@ -35,7 +33,7 @@ impl Db { | |||
35 | let users: HashMap<Fingerprint, User> = get_friendly_users(); | 33 | let users: HashMap<Fingerprint, User> = get_friendly_users(); |
36 | 34 | ||
37 | // Read the list of users who can register | 35 | // Read the list of users who can register |
38 | let preapproved_users = read_approved_users(); | 36 | let preapproved_users = read_approved_users(&config.preapproved_users); |
39 | 37 | ||
40 | let mut db = Db { | 38 | let mut db = Db { |
41 | blockchain: Arc::new(RwLock::new(Block::default())), | 39 | blockchain: Arc::new(RwLock::new(Block::default())), |
@@ -184,14 +182,14 @@ fn get_friendly_users() -> HashMap<Fingerprint, User> { | |||
184 | users | 182 | users |
185 | } | 183 | } |
186 | 184 | ||
187 | fn read_approved_users() -> Vec<MetuId> { | 185 | fn read_approved_users(filename: &str) -> Vec<MetuId> { |
188 | let mut approved_students: Vec<MetuId> = Vec::new(); | 186 | let mut approved_students: Vec<MetuId> = Vec::new(); |
189 | let contents = fs::read_to_string(PREAPPROVED_STU_FILENAME).unwrap_or_else(|_| { | 187 | let contents = fs::read_to_string(filename).unwrap_or_else(|_| { |
190 | panic!( | 188 | panic!( |
191 | "{}", | 189 | "{}", |
192 | format!( | 190 | format!( |
193 | "Expected {} in place to load preapproved students", | 191 | "Expected {} in place to load preapproved students", |
194 | PREAPPROVED_STU_FILENAME | 192 | filename |
195 | ) | 193 | ) |
196 | ) | 194 | ) |
197 | }); | 195 | }); |