Skip to content

Commit

Permalink
feat: fixed config loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-cne committed Apr 21, 2024
1 parent 4ea5677 commit 90983ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 6 additions & 29 deletions crates/infrastructure/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use figment::providers::{Format, Serialized, Yaml};
use figment::value::{Dict, Map};
use figment::{Figment, Metadata, Profile, Provider};
use figment::Figment;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Default)]
Expand All @@ -12,11 +11,10 @@ pub struct Config {

impl Config {
pub fn try_new() -> shared::error::Result<Self> {
let config = Figment::from(Config::default())
.merge(
Yaml::file(std::env::var("PURPLE_SECTOR_CONFIG").unwrap_or("config.yml".into()))
.nested(),
)
let config = Figment::from(Serialized::defaults(Config::default()))
.merge(Yaml::file(
std::env::var("PURPLE_SECTOR_CONFIG").unwrap_or("config.yml".into()),
))
.extract()?;
Ok(config)
}
Expand All @@ -41,6 +39,7 @@ pub struct CacheConfig {
#[serde(rename_all = "snake_case")]
pub enum MiddlewareConfig {
RateLimiter {
#[serde(default)]
enabled: bool,
#[serde(rename = "type")]
ty: Option<RateLimiterType>,
Expand Down Expand Up @@ -75,25 +74,3 @@ impl Default for CacheConfig {
}
}
}

impl Provider for Config {
fn metadata(&self) -> figment::Metadata {
Metadata::named("purple_sector::config")
}

fn data(
&self,
) -> std::result::Result<
figment::value::Map<figment::Profile, figment::value::Dict>,
figment::Error,
> {
let map: Map<Profile, Dict> = Serialized::defaults(self).data()?;

Ok(map)
}

fn profile(&self) -> Option<figment::Profile> {
// We don't indent to use profiles here
None
}
}

0 comments on commit 90983ab

Please sign in to comment.