summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2024-12-24 12:46:35 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2024-12-24 12:46:35 +0200
commit5205e4287ef65797ecd9591484f07da19dc575d1 (patch)
treea52dfcee7ae4623b88d7683d87d59b6846e04b64
parentb2390f7cbab63915a24d23f04d2b5e3eb57ff1a1 (diff)
downloadgit_service-5205e4287ef65797ecd9591484f07da19dc575d1.tar.gz
git_service-5205e4287ef65797ecd9591484f07da19dc575d1.tar.bz2
git_service-5205e4287ef65797ecd9591484f07da19dc575d1.zip
feat: read config from a JSON source
used to determine git repos location and cgitrepos file location
-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
+}