All checks were successful
Check go code / build-and-release (push) Successful in 1m9s
Reviewed-on: #5 Co-authored-by: Julien Fastré <julien.fastre@champs-libres.coop> Co-committed-by: Julien Fastré <julien.fastre@champs-libres.coop>
60 lines
1.3 KiB
Rust
60 lines
1.3 KiB
Rust
use crate::error::GeneralError;
|
|
use serde::Deserialize;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Config {
|
|
pub gitlab: Vec<GitlabConfig>,
|
|
pub gitea: Vec<GiteaConfig>,
|
|
pub openproject: OpenProjectConfig,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct GitlabConfig {
|
|
pub token: String,
|
|
pub domain: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct GiteaConfig {
|
|
pub token: String,
|
|
pub domain: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct OpenProjectConfig {
|
|
pub token: String,
|
|
pub base_url: String,
|
|
}
|
|
|
|
pub struct BuildConfigError {
|
|
msg: String,
|
|
}
|
|
|
|
impl Into<GeneralError> for BuildConfigError {
|
|
fn into(self) -> GeneralError {
|
|
GeneralError {
|
|
description: format!("Could not build config: {}", self.msg),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn build_config(config_path: &Path) -> Result<Config, BuildConfigError> {
|
|
let config_path_content = match fs::read_to_string(config_path) {
|
|
Ok(content) => content,
|
|
Err(e) => {
|
|
return Err(BuildConfigError {
|
|
msg: format!(
|
|
"Could not read a config file at {:?}, error: {}",
|
|
config_path, e
|
|
),
|
|
});
|
|
}
|
|
};
|
|
|
|
let config: Config = toml::from_str(&*config_path_content).expect("Could not parse config");
|
|
|
|
Ok(config)
|
|
}
|