#![allow(unused_imports, clippy::too_many_arguments)]
use reqwest::Method;
use serde::{Deserialize, Serialize};
use futures_core::Stream;
use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::pagination::CursorGuard;
use crate::util::encode_path;
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DeleteDataExplorerValueParams {
pub namespace: String,
pub key: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDataExplorerValueParams {
pub namespace: String,
pub key: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ListDataExplorerKeysParams {
pub namespace: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub prefix: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub search: Option<String>,
}
#[derive(Debug, Clone)]
pub struct DataExplorerApi {
pub(crate) client: Client,
}
impl Client {
pub fn data_explorer(&self) -> DataExplorerApi {
DataExplorerApi { client: self.clone() }
}
}
impl DataExplorerApi {
pub async fn delete_data_explorer_value(&self, params: &DeleteDataExplorerValueParams) -> Result<models::DeleteDataExplorerValueResponse> {
self.client
.request_json(Request {
method: Method::DELETE,
path: "/api/v1/admin/data-explorer/value".to_string(),
query: Some(params),
body: NO_BODY,
headers: Vec::new(),
idempotent: true,
})
.await
}
pub async fn get_data_explorer_value(&self, params: &GetDataExplorerValueParams) -> Result<models::GetDataExplorerValueResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/admin/data-explorer/value".to_string(),
query: Some(params),
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn list_data_explorer_keys(&self, params: &ListDataExplorerKeysParams) -> Result<models::ListDataExplorerKeysResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/admin/data-explorer/keys".to_string(),
query: Some(params),
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub fn list_data_explorer_keys_all<'a>(&'a self, params: &'a ListDataExplorerKeysParams) -> impl Stream<Item = Result<serde_json::Map<String, serde_json::Value>>> + 'a {
async_stream::try_stream! {
let mut guard = CursorGuard::new();
let mut cursor = params.cursor.clone();
loop {
let mut page_params = params.clone();
page_params.cursor = cursor.clone();
let page = self.list_data_explorer_keys(&page_params).await?;
let items = page.keys.unwrap_or_default();
let was_empty = items.is_empty();
for item in items {
yield item;
}
match guard.advance(page.cursor, page.has_more, was_empty) {
Some(next) => cursor = Some(next),
None => break,
}
}
}
}
pub async fn list_data_explorer_namespaces(&self) -> Result<models::ListDataExplorerNamespacesResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/admin/data-explorer/namespaces".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
pub async fn set_data_explorer_value(&self, body: &models::SetDataExplorerValueRequest) -> Result<models::SetDataExplorerValueResponse> {
self.client
.request_json(Request {
method: Method::PUT,
path: "/api/v1/admin/data-explorer/value".to_string(),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
}