mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-06-06 12:15:45 +00:00
redact the chat settings API key
This commit is contained in:
parent
1eb8249a51
commit
7bfb7b7d58
@ -24,10 +24,11 @@ async fn get_settings(
|
|||||||
Data<IndexScheduler>,
|
Data<IndexScheduler>,
|
||||||
>,
|
>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let settings = match index_scheduler.chat_settings()? {
|
let mut settings = match index_scheduler.chat_settings()? {
|
||||||
Some(value) => serde_json::from_value(value).unwrap(),
|
Some(value) => serde_json::from_value(value).unwrap(),
|
||||||
None => GlobalChatSettings::default(),
|
None => GlobalChatSettings::default(),
|
||||||
};
|
};
|
||||||
|
settings.hide_secrets();
|
||||||
Ok(HttpResponse::Ok().json(settings))
|
Ok(HttpResponse::Ok().json(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +81,33 @@ pub struct GlobalChatSettings {
|
|||||||
pub prompts: Setting<ChatPrompts>,
|
pub prompts: Setting<ChatPrompts>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GlobalChatSettings {
|
||||||
|
pub fn hide_secrets(&mut self) {
|
||||||
|
match &mut self.api_key {
|
||||||
|
Setting::Set(key) => Self::hide_secret(key),
|
||||||
|
Setting::Reset => (),
|
||||||
|
Setting::NotSet => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hide_secret(secret: &mut String) {
|
||||||
|
match secret.len() {
|
||||||
|
x if x < 10 => {
|
||||||
|
secret.replace_range(.., "XXX...");
|
||||||
|
}
|
||||||
|
x if x < 20 => {
|
||||||
|
secret.replace_range(2.., "XXXX...");
|
||||||
|
}
|
||||||
|
x if x < 30 => {
|
||||||
|
secret.replace_range(3.., "XXXXX...");
|
||||||
|
}
|
||||||
|
_x => {
|
||||||
|
secret.replace_range(5.., "XXXXXX...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
pub struct ChatPrompts {
|
pub struct ChatPrompts {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user