diff --git a/bin/cli/src/config.rs b/bin/cli/src/config.rs index f8393d391..12eb0e3aa 100644 --- a/bin/cli/src/config.rs +++ b/bin/cli/src/config.rs @@ -187,7 +187,7 @@ pub fn cli_config() -> &'static CliConfig { config.config_profile }; - let config = CliConfig { + CliConfig { config_profile, config_aliases: config.config_aliases, default_profile: config.default_profile, @@ -269,8 +269,6 @@ pub fn cli_config() -> &'static CliConfig { .unwrap_or(config.cli_logging.opentelemetry_service_name), }, profile: config.profile, - }; - - config::interpolate_config_struct(&config).unwrap() + } }) } diff --git a/bin/core/src/config.rs b/bin/core/src/config.rs index afa4c3a0a..70ff0888b 100644 --- a/bin/core/src/config.rs +++ b/bin/core/src/config.rs @@ -134,7 +134,7 @@ pub fn core_config() -> &'static CoreConfig { }; // recreating CoreConfig here makes sure apply all env overrides applied. - let config = CoreConfig { + CoreConfig { // Secret things overridden with file private_key: maybe_read_item_from_file( env.komodo_private_key_file, @@ -379,8 +379,6 @@ pub fn core_config() -> &'static CoreConfig { secrets: config.secrets, git_providers: config.git_providers, docker_registries: config.docker_registries, - }; - - config::interpolate_config_struct(&config).unwrap() + } }) } diff --git a/bin/periphery/src/config.rs b/bin/periphery/src/config.rs index 76bb74c61..c90de0c0e 100644 --- a/bin/periphery/src/config.rs +++ b/bin/periphery/src/config.rs @@ -69,7 +69,7 @@ pub fn periphery_config() -> &'static PeripheryConfig { .expect("failed at parsing config from paths") }; - let config = PeripheryConfig { + PeripheryConfig { private_key: maybe_read_item_from_file( env.periphery_private_key_file, env.periphery_private_key, @@ -169,8 +169,6 @@ pub fn periphery_config() -> &'static PeripheryConfig { secrets: config.secrets, git_providers: config.git_providers, docker_registries: config.docker_registries, - }; - - config::interpolate_config_struct(&config).unwrap() + } }) } diff --git a/client/core/rs/src/entities/config/core.rs b/client/core/rs/src/entities/config/core.rs index 20c964d3a..b7c3dc75b 100644 --- a/client/core/rs/src/entities/config/core.rs +++ b/client/core/rs/src/entities/config/core.rs @@ -11,7 +11,7 @@ use std::{collections::HashMap, path::PathBuf}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use crate::{ deserializers::option_string_list_deserializer, @@ -279,7 +279,7 @@ fn default_core_config_paths() -> Vec { /// or simply override whichever fields you need using the environment. /// /// Refer to the [example file](https://github.com/moghtech/komodo/blob/main/config/core.config.toml) for a full example. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct CoreConfig { // =========== // = General = @@ -892,7 +892,7 @@ impl CoreConfig { } /// Generic Oauth credentials -#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Deserialize)] pub struct OauthCredentials { /// Whether this oauth method is available for usage. #[serde(default)] @@ -906,7 +906,7 @@ pub struct OauthCredentials { } /// Provide AWS credentials for Komodo to use. -#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Deserialize)] pub struct AwsCredentials { /// The aws ACCESS_KEY_ID pub access_key_id: String, diff --git a/client/core/rs/src/entities/config/periphery.rs b/client/core/rs/src/entities/config/periphery.rs index 4d5da5072..7df7d8e28 100644 --- a/client/core/rs/src/entities/config/periphery.rs +++ b/client/core/rs/src/entities/config/periphery.rs @@ -14,7 +14,7 @@ use clap::Parser; use ipnetwork::IpNetwork; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use std::{collections::HashMap, path::PathBuf}; use crate::{ @@ -219,7 +219,7 @@ pub struct Env { /// # Periphery Configuration File /// /// Refer to the [example file](https://github.com/moghtech/komodo/blob/main/config/periphery.config.toml) for a full example. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct PeripheryConfig { /// The private key used with noise handshake. /// diff --git a/lib/config/src/interpolate.rs b/lib/config/src/interpolate.rs index 11a732c83..1b8e83aaf 100644 --- a/lib/config/src/interpolate.rs +++ b/lib/config/src/interpolate.rs @@ -1,17 +1,6 @@ use std::path::PathBuf; use colored::Colorize as _; -use serde::{Serialize, de::DeserializeOwned}; - -pub fn interpolate_config_struct( - s: &T, -) -> crate::Result { - let res = serde_json::to_string(s) - .map_err(|e| crate::Error::SerializeJson { e })?; - let res = interpolate_env_and_shell(&res); - serde_json::from_str(&res) - .map_err(|e| crate::Error::ParseFinalJson { e }) -} /// - Supports '${VAR}' -> Env var extended /// - Supports '$(shell command)' -> 'echo $(shell command)' diff --git a/lib/config/src/load.rs b/lib/config/src/load.rs index 2f715d0ec..fec7ba25f 100644 --- a/lib/config/src/load.rs +++ b/lib/config/src/load.rs @@ -8,7 +8,8 @@ use colored::Colorize; use serde::de::DeserializeOwned; use crate::{ - Error, Result, includes::IncludesLoader, merge::merge_objects, + Error, Result, includes::IncludesLoader, interpolate_env_and_shell, + merge::merge_objects, }; pub fn load_config_files( @@ -128,7 +129,11 @@ pub fn load_parse_config_files( }; } - serde_json::from_value(serde_json::Value::Object(target)) + let json = serde_json::to_string(&target) + .map_err(|e| Error::SerializeJson { e })?; + let interpolated = interpolate_env_and_shell(&json); + + serde_json::from_str(&interpolated) .map_err(|e| Error::ParseFinalJson { e }) }