refactor: redact secrets in Debug output

This commit is contained in:
KimiSwitch Dev
2026-07-06 17:40:17 +08:00
parent 26adba78ba
commit 9875e503a4
4 changed files with 31 additions and 2 deletions
+2
View File
@@ -0,0 +1,2 @@
//! Configuration file I/O for KimiSwitch.
//! Reads and writes the global config file and profile files.
+26 -2
View File
@@ -28,7 +28,7 @@ impl ProviderType {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Provider {
pub name: String,
pub provider_type: ProviderType,
@@ -39,6 +39,19 @@ pub struct Provider {
pub raw_other: Table,
}
impl std::fmt::Debug for Provider {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Provider")
.field("name", &self.name)
.field("provider_type", &self.provider_type)
.field("base_url", &self.base_url)
.field("api_key", &"<redacted>")
.field("env", &"<redacted>")
.field("raw_other", &"<table>")
.finish()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Model {
pub alias: String,
@@ -50,7 +63,7 @@ pub struct Model {
pub raw_other: Table,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Config {
pub default_model: Option<String>,
pub providers: IndexMap<String, Provider>,
@@ -59,6 +72,17 @@ pub struct Config {
pub raw_other: Table,
}
impl std::fmt::Debug for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Config")
.field("default_model", &self.default_model)
.field("providers", &format!("{} providers", self.providers.len()))
.field("models", &self.models)
.field("raw_other", &"<table>")
.finish()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfileSummary {
pub name: String,
+2
View File
@@ -0,0 +1,2 @@
//! Profile management for KimiSwitch.
//! Loads, saves, and switches between configuration profiles.
+1
View File
@@ -0,0 +1 @@
//! Validation helpers for KimiSwitch configuration and command inputs.