credence_lib/server/
configuration.rs1use super::super::configuration::*;
2
3use std::{fs::*, path::*};
4
5pub fn load_configuration<PathT>(assets_path: PathT) -> Result<CredenceConfiguration, ConfigurationError>
7where
8 PathT: AsRef<Path>,
9{
10 let assets_path = assets_path.as_ref();
11 let configuration_base_path = assets_path.join(CREDENCE_DIRECTORY_NAME);
12 let configuration_path = configuration_base_path.join(CREDENCE_CONFIGURATION_FILE_NAME);
13
14 let mut configuration = if configuration_path.exists() {
15 CredenceConfiguration::read(&mut File::open(configuration_path)?)?
16 } else {
17 tracing::info!("configuration file not found: {}", configuration_path.display());
18 CredenceConfiguration::default()
19 };
20
21 configuration.files.set_assets_path(assets_path);
22 configuration.validate(&configuration_base_path)?;
23
24 Ok(configuration)
25}