summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/read_config.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/read_config.rs b/src/read_config.rs
new file mode 100644
index 0000000..6a99dcb
--- /dev/null
+++ b/src/read_config.rs
@@ -0,0 +1,27 @@
+use std::{fs::File, io::Read};
+use serde::Deserialize;
+#[derive(Debug, Deserialize)]
+#[serde()]
+pub struct Owner {
+ pub name: String,
+ pub email: String,
+ pub gpg_pubkey_id: String,
+}
+#[derive(Debug, Deserialize)]
+#[serde()]
+pub struct Config {
+ pub authorized_owners: Vec<Owner>,
+ pub cgitrepos_file_path: String,
+ pub git_host_dir_path: String,
+}
+
+pub fn get_config(config_path: String) -> Config {
+ let mut config_file = match File::open(config_path) {
+ Ok(config_file) => config_file,
+ Err(e) => panic!("File reading error, invalid path?"),
+ };
+ let mut config_buf = String::new();
+ config_file.read_to_string(&mut config_buf).expect("Expected file to read correctly");
+ let config: Config = serde_json::from_str(&config_buf).expect("JSON may not be well-formatted!");
+ config
+}