fix config loading

This commit is contained in:
mbecker20
2025-10-13 22:04:42 -07:00
parent 26fd5b2a6d
commit fe2d68a001
7 changed files with 19 additions and 31 deletions

View File

@@ -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()
}
})
}

View File

@@ -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()
}
})
}

View File

@@ -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()
}
})
}

View File

@@ -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<PathBuf> {
/// 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,

View File

@@ -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.
///

View File

@@ -1,17 +1,6 @@
use std::path::PathBuf;
use colored::Colorize as _;
use serde::{Serialize, de::DeserializeOwned};
pub fn interpolate_config_struct<T: Serialize + DeserializeOwned>(
s: &T,
) -> crate::Result<T> {
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)'

View File

@@ -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<T: DeserializeOwned>(
};
}
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 })
}