From 85037352b95d947151692307c1f00371fed134a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 30 Jun 2025 18:31:32 +0200 Subject: [PATCH] Fix most of the easy issues --- crates/index-scheduler/src/processing.rs | 4 ++-- .../src/scheduler/create_batch.rs | 6 ++--- .../src/scheduler/process_export.rs | 5 ++-- crates/index-scheduler/src/utils.rs | 2 +- crates/meilisearch-types/src/task_view.rs | 23 ++++++++++++++++++- crates/meilisearch/src/routes/export.rs | 15 ++++++------ 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/crates/index-scheduler/src/processing.rs b/crates/index-scheduler/src/processing.rs index 5d4ac11c3..631719f73 100644 --- a/crates/index-scheduler/src/processing.rs +++ b/crates/index-scheduler/src/processing.rs @@ -178,8 +178,8 @@ make_enum_progress! { make_enum_progress! { pub enum Export { EnsuringCorrectnessOfTheTarget, - ExportTheSettings, - ExportTheDocuments, + ExporingTheSettings, + ExporingTheDocuments, } } diff --git a/crates/index-scheduler/src/scheduler/create_batch.rs b/crates/index-scheduler/src/scheduler/create_batch.rs index 7a6fa4a9b..b08d27d48 100644 --- a/crates/index-scheduler/src/scheduler/create_batch.rs +++ b/crates/index-scheduler/src/scheduler/create_batch.rs @@ -510,9 +510,9 @@ impl IndexScheduler { // 3. we batch the export. let to_export = self.queue.tasks.get_kind(rtxn, Kind::Export)? & enqueued; if !to_export.is_empty() { - let mut tasks = self.queue.tasks.get_existing_tasks(rtxn, to_export)?; - current_batch.processing(&mut tasks); - let task = tasks.pop().expect("There must be only one export task"); + let task_id = to_export.iter().next().expect("There must be only one export task"); + let mut task = self.queue.tasks.get_task(rtxn, task_id)?.unwrap(); + current_batch.processing([&mut task]); current_batch.reason(BatchStopReason::TaskKindCannotBeBatched { kind: Kind::Export }); return Ok(Some((Batch::Export { task }, current_batch))); } diff --git a/crates/index-scheduler/src/scheduler/process_export.rs b/crates/index-scheduler/src/scheduler/process_export.rs index 57f79c83f..b81ff0b96 100644 --- a/crates/index-scheduler/src/scheduler/process_export.rs +++ b/crates/index-scheduler/src/scheduler/process_export.rs @@ -86,10 +86,11 @@ impl IndexScheduler { } // Retry logic for sending settings let url = format!("{base_url}/indexes/{uid}/settings"); + let bearer = api_key.map(|api_key| format!("Bearer {api_key}")); retry(&must_stop_processing, || { let mut request = agent.patch(&url); - if let Some(api_key) = api_key { - request = request.set("Authorization", &format!("Bearer {api_key}")); + if let Some(bearer) = bearer.as_ref() { + request = request.set("Authorization", bearer); } request.send_json(settings.clone()).map_err(into_backoff_error) })?; diff --git a/crates/index-scheduler/src/utils.rs b/crates/index-scheduler/src/utils.rs index 594023145..2cfe63bff 100644 --- a/crates/index-scheduler/src/utils.rs +++ b/crates/index-scheduler/src/utils.rs @@ -273,7 +273,7 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) { K::TaskCancelation { .. } | K::TaskDeletion { .. } | K::DumpCreation { .. } - | K::Export { .. } // TODO I have patterns, not index uids + | K::Export { .. } | K::UpgradeDatabase { .. } | K::SnapshotCreation => (), }; diff --git a/crates/meilisearch-types/src/task_view.rs b/crates/meilisearch-types/src/task_view.rs index 1dbd5637b..7521137c0 100644 --- a/crates/meilisearch-types/src/task_view.rs +++ b/crates/meilisearch-types/src/task_view.rs @@ -371,7 +371,10 @@ impl From
for DetailsView { } Details::Export { url, api_key, payload_size, indexes } => DetailsView { url: Some(url), - api_key, + api_key: api_key.map(|mut api_key| { + hide_secret(&mut api_key); + api_key + }), payload_size: payload_size .map(|ps| ps.get_appropriate_unit(UnitType::Both).to_string()), indexes: Some( @@ -390,3 +393,21 @@ impl From
for DetailsView { } } } + +// We definitely need to factorize the code to hide the secret key +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..."); + } + } +} diff --git a/crates/meilisearch/src/routes/export.rs b/crates/meilisearch/src/routes/export.rs index 21a77ae32..1df2d271e 100644 --- a/crates/meilisearch/src/routes/export.rs +++ b/crates/meilisearch/src/routes/export.rs @@ -42,17 +42,18 @@ pub fn configure(cfg: &mut web::ServiceConfig) { } #[utoipa::path( - get, + post, path = "", tag = "Export", security(("Bearer" = ["export", "*"])), responses( (status = OK, description = "Known nodes are returned", body = Export, content_type = "application/json", example = json!( - { - "indexes": ["movie", "steam-*"], - "skip_embeddings": true, - "apiKey": "meilisearch-api-key" - })), + { + "taskUid": 1, + "status": "enqueued", + "type": "export", + "enqueuedAt": "2021-08-11T09:25:53.000000Z" + })), (status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!( { "message": "The Authorization header is missing. It must use the bearer authorization method.", @@ -126,7 +127,7 @@ pub struct Export { #[serde(default)] #[deserr(default, error = DeserrJsonError)] pub payload_size: Option, - #[schema(value_type = Option>, example = json!(["movies", "steam-*"]))] + #[schema(value_type = Option>, example = json!({ "*": { "filter": null } }))] #[deserr(default)] #[serde(default)] pub indexes: BTreeMap,