Skip to content

Commit 2b041fc

Browse files
bors[bot]irevoire
andauthored
Merge #458
458: make the api key optional r=bidoubiwa a=irevoire # Pull Request Since we introduced the `Authentication: Bearer {api_key}` header, sending an empty `api_key` doesn't work anymore, which means it's impossible to use this SDK without an API key. A lot of noise is due to the doctest update; it's probably easier to review this PR by reading the first commit alone ## Related issue Fixes #240 ## What does this PR do? - Makes the API key optional when creating a client ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Tamo <tamo@meilisearch.com>
2 parents 316816e + 0eb59ed commit 2b041fc

File tree

18 files changed

+317
-294
lines changed

18 files changed

+317
-294
lines changed

.code-samples.meilisearch.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ add_movies_json_1: |-
779779
use futures::executor::block_on;
780780
781781
fn main() { block_on(async move {
782-
let client = Client::new("http://localhost:7700", "masterKey");
782+
let client = Client::new("http://localhost:7700", Some("masterKey"));
783783
784784
// reading and parsing the file
785785
let mut file = File::open("movies.json")
@@ -903,7 +903,7 @@ getting_started_add_documents_md: |-
903903
use futures::executor::block_on;
904904
905905
fn main() { block_on(async move {
906-
let client = Client::new("http://localhost:7700", "masterKey");
906+
let client = Client::new("http://localhost:7700", Some("masterKey"));
907907
908908
// reading and parsing the file
909909
let mut file = File::open("movies.json")
@@ -1022,7 +1022,7 @@ getting_started_update_displayed_attributes: |-
10221022
.await
10231023
.unwrap();
10241024
getting_started_communicating_with_a_protected_instance: |-
1025-
let client = Client::new("http://localhost:7700", "apiKey");
1025+
let client = Client::new("http://localhost:7700", Some("apiKey"));
10261026
client
10271027
.index("movies")
10281028
.search()
@@ -1385,20 +1385,20 @@ delete_a_key_1: |-
13851385
.delete_key(&key)
13861386
.await?;
13871387
authorization_header_1:
1388-
let client = Client::new("http://localhost:7700", "masterKey");
1388+
let client = Client::new("http://localhost:7700", Some("masterKey"));
13891389
let keys = client
13901390
.get_keys()
13911391
.await
13921392
.unwrap();
13931393
security_guide_search_key_1: |-
1394-
let client = Client::new("http://localhost:7700", "apiKey");
1394+
let client = Client::new("http://localhost:7700", Some("apiKey"));
13951395
let result = client.index("patient_medical_records")
13961396
.search()
13971397
.execute()
13981398
.await
13991399
.unwrap();
14001400
security_guide_update_key_1: |-
1401-
let client = Client::new("http://localhost:7700", "masterKey");
1401+
let client = Client::new("http://localhost:7700", Some("masterKey"));
14021402
let mut key = client
14031403
.get_key("74c9c733-3368-4738-bbe5-1d18a5fecb37")
14041404
.await
@@ -1407,7 +1407,7 @@ security_guide_update_key_1: |-
14071407
.with_description("Default Search API key".to_string())
14081408
.update(&client);
14091409
security_guide_create_key_1: |-
1410-
let client = Client::new("http://localhost:7700", "masterKey");
1410+
let client = Client::new("http://localhost:7700", Some("masterKey"));
14111411
let mut key_options = KeyBuilder::new("Search patient records key");
14121412
key_options
14131413
.with_action(Action::Search)
@@ -1418,13 +1418,13 @@ security_guide_create_key_1: |-
14181418
.await
14191419
.unwrap();
14201420
security_guide_list_keys_1: |-
1421-
let client = Client::new("http://localhost:7700", "masterKey");
1421+
let client = Client::new("http://localhost:7700", Some("masterKey"));
14221422
let keys = client
14231423
.get_keys()
14241424
.await
14251425
.unwrap();
14261426
security_guide_delete_key_1: |-
1427-
let client = Client::new("http://localhost:7700", "masterKey");
1427+
let client = Client::new("http://localhost:7700", Some("masterKey"));
14281428
let key = client
14291429
.get_key("ac5cd97d-5a4b-4226-a868-2d0eb6d197ab")
14301430
.await
@@ -1433,7 +1433,7 @@ security_guide_delete_key_1: |-
14331433
.delete_key(&key)
14341434
.await?;
14351435
landing_getting_started_1: |-
1436-
let client = Client::new("http://localhost:7700", "masterKey");
1436+
let client = Client::new("http://localhost:7700", Some("masterKey"));
14371437
14381438
#[derive(Serialize, Deserialize)]
14391439
struct Movie {
@@ -1462,7 +1462,7 @@ tenant_token_guide_generate_sdk_1: |-
14621462
.generate_tenant_token(api_key_uid, search_rules, api_key, expires_at)
14631463
.unwrap();
14641464
tenant_token_guide_search_sdk_1: |-
1465-
let front_end_client = Client::new("http://localhost:7700", token);
1465+
let front_end_client = Client::new("http://localhost:7700", Some(token));
14661466
let results: SearchResults<Patient> = front_end_client
14671467
.index("patient_medical_records")
14681468
.search()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct Movie {
104104

105105
fn main() { block_on(async move {
106106
// Create a client (without sending any request so that can't fail)
107-
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
107+
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
108108

109109
// An index is where the documents are stored.
110110
let movies = client.index("movies");

examples/cli-app/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::stdin;
77

88
// instantiate the client. load it once
99
lazy_static! {
10-
static ref CLIENT: Client = Client::new("http://localhost:7700", "masterKey");
10+
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey"));
1111
}
1212

1313
fn main() {

examples/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use meilisearch_sdk::settings::Settings;
55
// we need an async runtime
66
#[tokio::main(flavor = "current_thread")]
77
async fn main() {
8-
let client: Client = Client::new("http://localhost:7700", "masterKey");
8+
let client: Client = Client::new("http://localhost:7700", Some("masterKey"));
99

1010
// We try to create an index called `movies` with a primary_key of `movie_id`.
1111
let my_index: Index = client

examples/web_app/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod document;
1616
use crate::document::{display, Crate};
1717

1818
lazy_static! {
19-
static ref CLIENT: Client = Client::new("http://localhost:7700", "masterKey",);
19+
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey"));
2020
}
2121

2222
struct Model {

meilisearch-test-macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
8989
let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
9090
));
9191
outer_block.push(parse_quote!(
92-
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
92+
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
9393
));
9494
}
9595

0 commit comments

Comments
 (0)