2021-11-08 18:31:27 +01:00
|
|
|
mod api_keys;
|
|
|
|
mod authorization;
|
2023-01-24 17:30:35 +01:00
|
|
|
mod errors;
|
2021-11-08 18:31:27 +01:00
|
|
|
mod payload;
|
2022-01-12 15:35:33 +01:00
|
|
|
mod tenant_token;
|
2021-11-08 18:31:27 +01:00
|
|
|
|
2023-02-16 10:52:32 +01:00
|
|
|
mod tenant_token_multi_search;
|
|
|
|
|
2021-11-08 18:31:27 +01:00
|
|
|
use actix_web::http::StatusCode;
|
|
|
|
|
2023-09-11 16:50:53 +02:00
|
|
|
use crate::common::{Server, Value};
|
|
|
|
use crate::json;
|
2022-10-20 18:00:07 +02:00
|
|
|
|
2021-11-08 18:31:27 +01:00
|
|
|
impl Server {
|
|
|
|
pub fn use_api_key(&mut self, api_key: impl AsRef<str>) {
|
|
|
|
self.service.api_key = Some(api_key.as_ref().to_string());
|
|
|
|
}
|
|
|
|
|
2022-05-23 17:03:28 +02:00
|
|
|
/// Fetch and use the default admin key for nexts http requests.
|
|
|
|
pub async fn use_admin_key(&mut self, master_key: impl AsRef<str>) {
|
|
|
|
self.use_api_key(master_key);
|
2023-01-24 17:30:35 +01:00
|
|
|
let (response, code) = self.list_api_keys("").await;
|
2022-05-23 17:03:28 +02:00
|
|
|
assert_eq!(200, code, "{:?}", response);
|
|
|
|
let admin_key = &response["results"][1]["key"];
|
|
|
|
self.use_api_key(admin_key.as_str().unwrap());
|
|
|
|
}
|
|
|
|
|
2021-11-08 18:31:27 +01:00
|
|
|
pub async fn add_api_key(&self, content: Value) -> (Value, StatusCode) {
|
|
|
|
let url = "/keys";
|
|
|
|
self.service.post(url, content).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_api_key(&self, key: impl AsRef<str>) -> (Value, StatusCode) {
|
|
|
|
let url = format!("/keys/{}", key.as_ref());
|
|
|
|
self.service.get(url).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn patch_api_key(&self, key: impl AsRef<str>, content: Value) -> (Value, StatusCode) {
|
|
|
|
let url = format!("/keys/{}", key.as_ref());
|
|
|
|
self.service.patch(url, content).await
|
|
|
|
}
|
|
|
|
|
2023-01-24 17:30:35 +01:00
|
|
|
pub async fn list_api_keys(&self, params: &str) -> (Value, StatusCode) {
|
|
|
|
let url = format!("/keys{params}");
|
2021-11-08 18:31:27 +01:00
|
|
|
self.service.get(url).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_api_key(&self, key: impl AsRef<str>) -> (Value, StatusCode) {
|
|
|
|
let url = format!("/keys/{}", key.as_ref());
|
|
|
|
self.service.delete(url).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn dummy_request(
|
|
|
|
&self,
|
|
|
|
method: impl AsRef<str>,
|
|
|
|
url: impl AsRef<str>,
|
|
|
|
) -> (Value, StatusCode) {
|
|
|
|
match method.as_ref() {
|
|
|
|
"POST" => self.service.post(url, json!({})).await,
|
|
|
|
"PUT" => self.service.put(url, json!({})).await,
|
|
|
|
"PATCH" => self.service.patch(url, json!({})).await,
|
|
|
|
"GET" => self.service.get(url).await,
|
|
|
|
"DELETE" => self.service.delete(url).await,
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|