Skip to content

Put back code samples we should not have deleted#767

Merged
curquiza merged 1 commit intomainfrom
put-back-missing-cs
Feb 11, 2026
Merged

Put back code samples we should not have deleted#767
curquiza merged 1 commit intomainfrom
put-back-missing-cs

Conversation

@curquiza
Copy link
Member

@curquiza curquiza commented Feb 11, 2026

Summary by CodeRabbit

  • Documentation
    • Added Rust code samples for tenant token generation, including API key and authorization rule configuration with token expiration time controls
    • Added examples demonstrating front-end client initialization with generated tokens and search query functionality
    • Expanded multi-search workflow documentation with additional code examples and real-world configuration scenarios

@curquiza curquiza added skip-changelog The PR will not appear in the release changelogs maintenance Anything related to maintenance (CI, tests, refactoring...) labels Feb 11, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Added 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

Cohort / File(s) Summary
Tenant Token Authorization Documentation
.code-samples.meilisearch.yaml
Added two Rust code samples under authorization_header_1: one demonstrating tenant token generation with API key UID, search rules, and expiration, and another showing client initialization and searching with the generated token.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hop along the auth trail, dear friend,
With tokens that twist and defend,
In Rust we trust, both search and guard,
These samples make auth less hard! 🔐✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: restoring previously deleted code samples to the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch put-back-missing-cs

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1391 to +1399
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: |-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

Comment on lines +1400 to +1407
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@curquiza curquiza merged commit ae1b906 into main Feb 11, 2026
7 of 8 checks passed
@curquiza curquiza deleted the put-back-missing-cs branch February 11, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Anything related to maintenance (CI, tests, refactoring...) skip-changelog The PR will not appear in the release changelogs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant