Skip to content

Commit 328b0c7

Browse files
committed
feat: Obscure api key in debug display
1 parent 111d6d7 commit 328b0c7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/settings.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'de> serde::Deserialize<'de> for ModelProvider {
7070
}
7171
}
7272

73-
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
73+
#[derive(Default, Serialize, Deserialize, Clone)]
7474
pub(crate) struct OpenAISettings {
7575
pub api_base: Option<String>,
7676
pub api_key: Option<String>,
@@ -79,6 +79,22 @@ pub(crate) struct OpenAISettings {
7979
pub proxy: Option<String>,
8080
}
8181

82+
impl std::fmt::Debug for OpenAISettings {
83+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84+
f.debug_struct("OpenAISettings")
85+
.field("api_base", &self.api_base)
86+
.field(
87+
"api_key",
88+
// obfuscate the api key
89+
&self.api_key.as_ref().map(|_| "********"),
90+
)
91+
.field("model", &self.model)
92+
.field("retries", &self.retries)
93+
.field("proxy", &self.proxy)
94+
.finish()
95+
}
96+
}
97+
8298
// implement the trait `From<OpenAISettings>` for `ValueKind`
8399
impl From<OpenAISettings> for config::ValueKind {
84100
fn from(settings: OpenAISettings) -> Self {

0 commit comments

Comments
 (0)