Put back code samples we should not have deleted#767
Conversation
📝 WalkthroughWalkthroughAdded two Rust code-sample blocks demonstrating tenant token authorization workflows: one showing token generation using API keys with expiration and search rules, and another showing how to use the generated token to initialize a client and perform searches. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.code-samples.meilisearch.yaml:
- Around line 1400-1407: The snippet uses token without defining it, so make the
example standalone by declaring a local placeholder token before creating
front_end_client: add a local variable (e.g., token) assigned to a placeholder
string and use that when calling Client::new("http://localhost:7700",
Some(token)); keep all other symbols (front_end_client, Client::new,
SearchResults<Patient>, index("patient_medical_records"), .search()) unchanged
so the example compiles and can be copy‑pasted.
- Around line 1391-1399: Replace the concrete-looking secret values and past
expiration with clear placeholders and a future date: update the variables
api_key and api_key_uid to non-sensitive placeholder strings (e.g.,
"MEILISEARCH_API_KEY" and "API_KEY_UID_PLACEHOLDER") and set expires_at to a
date well in the future (e.g., 2030-01-01T00:00:00Z) before calling
client.generate_tenant_token(api_key_uid, search_rules, api_key, expires_at).
Ensure the token generation call and variable names (api_key, api_key_uid,
expires_at, client.generate_tenant_token) remain unchanged so samples continue
to demonstrate usage without exposing secrets.
| let api_key = "B5KdX2MY2jV6EXfUs6scSfmC..."; | ||
| let api_key_uid = "6062abda-a5aa-4414-ac91-ecd7944c0f8d"; | ||
| let expires_at = time::macros::datetime!(2025 - 12 - 20 00:00:00 UTC); | ||
| let search_rules = json!({ "patient_medical_records": { "filter": "user_id = 1" } }); | ||
|
|
||
| let token = client | ||
| .generate_tenant_token(api_key_uid, search_rules, api_key, expires_at) | ||
| .unwrap(); | ||
| tenant_token_guide_search_sdk_1: |- |
There was a problem hiding this comment.
Replace concrete-looking keys and use a future expiration.
Line 1391–Line 1392 look like real secrets and are already flagged by secret scanning. Also, Line 1393 is in the past (December 20, 2025), so the sample token is immediately expired as of February 11, 2026. Please use obvious placeholders and a future date.
🔧 Suggested fix
- let api_key = "B5KdX2MY2jV6EXfUs6scSfmC...";
- let api_key_uid = "6062abda-a5aa-4414-ac91-ecd7944c0f8d";
- let expires_at = time::macros::datetime!(2025 - 12 - 20 00:00:00 UTC);
+ let api_key = "MEILISEARCH_API_KEY";
+ let api_key_uid = "API_KEY_UID";
+ let expires_at = time::macros::datetime!(2026 - 12 - 20 00:00:00 UTC);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let api_key = "B5KdX2MY2jV6EXfUs6scSfmC..."; | |
| let api_key_uid = "6062abda-a5aa-4414-ac91-ecd7944c0f8d"; | |
| let expires_at = time::macros::datetime!(2025 - 12 - 20 00:00:00 UTC); | |
| let search_rules = json!({ "patient_medical_records": { "filter": "user_id = 1" } }); | |
| let token = client | |
| .generate_tenant_token(api_key_uid, search_rules, api_key, expires_at) | |
| .unwrap(); | |
| tenant_token_guide_search_sdk_1: |- | |
| let api_key = "MEILISEARCH_API_KEY"; | |
| let api_key_uid = "API_KEY_UID"; | |
| let expires_at = time::macros::datetime!(2026 - 12 - 20 00:00:00 UTC); | |
| let search_rules = json!({ "patient_medical_records": { "filter": "user_id = 1" } }); | |
| let token = client | |
| .generate_tenant_token(api_key_uid, search_rules, api_key, expires_at) | |
| .unwrap(); | |
| tenant_token_guide_search_sdk_1: |- |
🧰 Tools
🪛 Gitleaks (8.30.0)
[high] 1391-1391: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
[high] 1392-1392: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🤖 Prompt for AI Agents
In @.code-samples.meilisearch.yaml around lines 1391 - 1399, Replace the
concrete-looking secret values and past expiration with clear placeholders and a
future date: update the variables api_key and api_key_uid to non-sensitive
placeholder strings (e.g., "MEILISEARCH_API_KEY" and "API_KEY_UID_PLACEHOLDER")
and set expires_at to a date well in the future (e.g., 2030-01-01T00:00:00Z)
before calling client.generate_tenant_token(api_key_uid, search_rules, api_key,
expires_at). Ensure the token generation call and variable names (api_key,
api_key_uid, expires_at, client.generate_tenant_token) remain unchanged so
samples continue to demonstrate usage without exposing secrets.
| let front_end_client = Client::new("http://localhost:7700", Some(token)); | ||
| let results: SearchResults<Patient> = front_end_client | ||
| .index("patient_medical_records") | ||
| .search() | ||
| .with_query("blood test") | ||
| .execute() | ||
| .await | ||
| .unwrap(); |
There was a problem hiding this comment.
Define token locally to keep the snippet standalone.
token is used without a local definition. If this snippet is rendered independently, it won’t compile or be copy‑pasteable. Consider adding a placeholder token in this block.
🧩 Suggested fix
+ let token = "TENANT_TOKEN";
let front_end_client = Client::new("http://localhost:7700", Some(token));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let front_end_client = Client::new("http://localhost:7700", Some(token)); | |
| let results: SearchResults<Patient> = front_end_client | |
| .index("patient_medical_records") | |
| .search() | |
| .with_query("blood test") | |
| .execute() | |
| .await | |
| .unwrap(); | |
| let token = "TENANT_TOKEN"; | |
| let front_end_client = Client::new("http://localhost:7700", Some(token)); | |
| let results: SearchResults<Patient> = front_end_client | |
| .index("patient_medical_records") | |
| .search() | |
| .with_query("blood test") | |
| .execute() | |
| .await | |
| .unwrap(); |
🤖 Prompt for AI Agents
In @.code-samples.meilisearch.yaml around lines 1400 - 1407, The snippet uses
token without defining it, so make the example standalone by declaring a local
placeholder token before creating front_end_client: add a local variable (e.g.,
token) assigned to a placeholder string and use that when calling
Client::new("http://localhost:7700", Some(token)); keep all other symbols
(front_end_client, Client::new, SearchResults<Patient>,
index("patient_medical_records"), .search()) unchanged so the example compiles
and can be copy‑pasted.
Summary by CodeRabbit