mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
Merge #2054
2054: Bug(auth): Wrap key list in results r=irevoire a=ManyTheFish fix #2052 Co-authored-by: ManyTheFish <many@meilisearch.com>
This commit is contained in:
commit
d53c61a6d0
@ -2,7 +2,7 @@ use std::str;
|
||||
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use chrono::SecondsFormat;
|
||||
use log::debug;
|
||||
|
||||
use meilisearch_auth::{generate_key, Action, AuthController, Key};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
@ -32,7 +32,6 @@ pub async fn create_api_key(
|
||||
let key = auth_controller.create_key(body.into_inner()).await?;
|
||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Created().json(res))
|
||||
}
|
||||
|
||||
@ -46,8 +45,7 @@ pub async fn list_api_keys(
|
||||
.map(|k| KeyView::from_key(k, auth_controller.get_master_key()))
|
||||
.collect();
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
Ok(HttpResponse::Ok().json(KeyListView::from(res)))
|
||||
}
|
||||
|
||||
pub async fn get_api_key(
|
||||
@ -58,7 +56,6 @@ pub async fn get_api_key(
|
||||
let key = auth_controller.get_key(&path.api_key).await?;
|
||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}
|
||||
|
||||
@ -73,7 +70,6 @@ pub async fn patch_api_key(
|
||||
.await?;
|
||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}
|
||||
|
||||
@ -125,3 +121,14 @@ impl KeyView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct KeyListView {
|
||||
results: Vec<KeyView>,
|
||||
}
|
||||
|
||||
impl From<Vec<KeyView>> for KeyListView {
|
||||
fn from(results: Vec<KeyView>) -> Self {
|
||||
Self { results }
|
||||
}
|
||||
}
|
||||
|
@ -571,7 +571,8 @@ async fn list_api_keys() {
|
||||
|
||||
let (response, code) = server.list_api_keys().await;
|
||||
|
||||
let expected_response = json!([
|
||||
let expected_response = json!({ "results":
|
||||
[
|
||||
{
|
||||
"description": "Indexing API key",
|
||||
"indexes": ["products"],
|
||||
@ -604,7 +605,8 @@ async fn list_api_keys() {
|
||||
"indexes": ["*"],
|
||||
"actions": ["*"],
|
||||
"expiresAt": serde_json::Value::Null,
|
||||
}]);
|
||||
}
|
||||
]});
|
||||
|
||||
assert_json_include!(actual: response, expected: expected_response);
|
||||
assert_eq!(code, 200);
|
||||
|
Loading…
Reference in New Issue
Block a user