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(
16 &mut File::open(&configuration_path)?,
17 configuration_path.to_string_lossy().into_owned().into(),
18 )?
19 } else {
20 tracing::info!("configuration file not found: {}", configuration_path.display());
21 Default::default()
22 };
23
24 configuration.files.set_assets_path(assets_path);
25 configuration.validate(&configuration_base_path)?;
26
27 Ok(configuration)
28}