myc_adapters_shared_lib/models/
redis_config.rs1use myc_config::{load_config_from_file, secret_resolver::SecretResolver};
2use mycelium_base::utils::errors::{creation_err, MappedErrors};
3use serde::Deserialize;
4use std::path::PathBuf;
5
6#[derive(Clone, Debug, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub(super) struct TmpConfig {
9 pub(super) redis: RedisConfig,
10}
11
12#[derive(Clone, Debug, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct RedisConfig {
15 pub protocol: SecretResolver<String>,
16 pub hostname: SecretResolver<String>,
17 pub port: Option<SecretResolver<u16>>,
18 pub password: SecretResolver<String>,
19}
20
21impl RedisConfig {
22 pub fn from_default_config_file(
23 file: PathBuf,
24 ) -> Result<Self, MappedErrors> {
25 if !file.exists() {
26 return creation_err(format!(
27 "Could not find config file: {}",
28 file.to_str().unwrap()
29 ))
30 .as_error();
31 }
32
33 match load_config_from_file::<TmpConfig>(file) {
34 Ok(config) => Ok(config.redis),
35 Err(err) => Err(err),
36 }
37 }
38}