mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
Forward the keys update to zookeeper
This commit is contained in:
parent
b0ff595f60
commit
0cd81573b4
@ -116,7 +116,7 @@ impl AuthController {
|
|||||||
Ok(key)
|
Ok(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_key(&self, uid: Uuid, patch: PatchApiKey) -> Result<Key> {
|
pub async fn update_key(&self, uid: Uuid, patch: PatchApiKey) -> Result<Key> {
|
||||||
let mut key = self.get_key(uid)?;
|
let mut key = self.get_key(uid)?;
|
||||||
match patch.description {
|
match patch.description {
|
||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
@ -127,7 +127,14 @@ impl AuthController {
|
|||||||
name => key.name = name.set(),
|
name => key.name = name.set(),
|
||||||
};
|
};
|
||||||
key.updated_at = OffsetDateTime::now_utc();
|
key.updated_at = OffsetDateTime::now_utc();
|
||||||
self.store.put_api_key(key)
|
let store = self.store.clone();
|
||||||
|
// TODO: we may commit only after zk persisted the keys
|
||||||
|
let key = tokio::task::spawn_blocking(move || store.put_api_key(key)).await??;
|
||||||
|
if let Some(ref zk) = self.zk {
|
||||||
|
zk.set_data(&format!("/auth/{}", key.uid), &serde_json::to_vec_pretty(&key)?, None)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Ok(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_key(&self, uid: Uuid) -> Result<Key> {
|
pub fn get_key(&self, uid: Uuid) -> Result<Key> {
|
||||||
|
@ -106,17 +106,11 @@ pub async fn patch_api_key(
|
|||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let key = path.into_inner().key;
|
let key = path.into_inner().key;
|
||||||
let patch_api_key = body.into_inner();
|
let patch_api_key = body.into_inner();
|
||||||
let res = tokio::task::spawn_blocking(move || -> Result<_, AuthControllerError> {
|
let uid = Uuid::parse_str(&key).or_else(|_| auth_controller.get_uid_from_encoded_key(&key))?;
|
||||||
let uid =
|
let key = auth_controller.update_key(uid, patch_api_key).await?;
|
||||||
Uuid::parse_str(&key).or_else(|_| auth_controller.get_uid_from_encoded_key(&key))?;
|
let key = KeyView::from_key(key, &auth_controller);
|
||||||
let key = auth_controller.update_key(uid, patch_api_key)?;
|
|
||||||
|
|
||||||
Ok(KeyView::from_key(key, &auth_controller))
|
Ok(HttpResponse::Ok().json(key))
|
||||||
})
|
|
||||||
.await
|
|
||||||
.map_err(|e| ResponseError::from_msg(e.to_string(), Code::Internal))??;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(res))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_api_key(
|
pub async fn delete_api_key(
|
||||||
|
Loading…
Reference in New Issue
Block a user