Builder pattern for modifying the Key
Closed this issue · 7 comments
We should provide a kind of builder design for the Key
as we have for the BuilderKey
.
If we can do that to create a key:
let mut key_options = KeyBuilder::new("Add documents: Products API key");
key_options.with_action(Action::DocumentsAdd)
.with_expires_at("2042-04-02T00:42:42Z")
.with_index("products");
let new_key = client.create_key(key_options).await.unwrap();
We shouldn’t have to do that to update a key:
let key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
key.indexes = vec!["products".to_string(), "reviews".to_string()];
key.expires_at = Some("2042-04-02T00:42:42Z".to_string());
let updated_key = client.update_key(&key);
We should instead do something like that:
let mut key = client.get_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4").await.unwrap();
key
.with_indexes(&["products", "reviews"])
.with_expires_at("2042-04-02T00:42:42Z");
let updated_key = client.update_key(&key);
So, do we just implement these methods for Key
such that they return &mut self
and can be used in the builder pattern?
Yep, this one is not that hard I just don't have the time to tackle it 👍
Question, so I was about to send a PR but realized some tests don't seem to pass?
meilisearch-sdk search::tests::test_query_crop_length
meilisearch-sdk search::tests::test_query_customized_highlight_pre_tag
meilisearch-sdk search::tests::test_query_customized_crop_marker
meilisearch-sdk search::tests::test_query_attributes_to_crop
Should I create a new issue?
With the v0.27.x on main?
Yes.
Oh wait no, I was running an older version of the meilisearch binary.
Nevermind, sorry about that!
I looked at the Cargo.toml
version, and read 0.17 as 0.27 lol
I got an email for this and I still have 12 tests failing even after doing a clean fork, how would i go about updating sdk? I fetched the latest from upstream.
These are failing for me and I can't understand why
client::tests::test_create_key
client::tests::test_delete_key
client::tests::test_error_create_key
client::tests::test_error_delete_key
client::tests::test_error_update_key
client::tests::test_get_keys
client::tests::test_update_key
search::tests::test_generate_tenant_token_from_client
search::tests::test_query_attributes_to_crop
search::tests::test_query_crop_length
search::tests::test_query_customized_crop_marker
search::tests::test_query_customized_highlight_pre_tag