use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::manager_api as api;
use crate::gen::manager::models;
use crate::http::collect_all;
use crate::retry::{with_retry, RetryPolicy};
pub struct LogsResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl LogsResource {
pub async fn audit_all(&self) -> Result<Vec<models::AuditLog>, ManagerError> {
collect_all(&self.retry, map_manager_err, |page| async move {
let r = api::list_audit_logs(
self.cfg.as_ref(),
None,
None,
None,
Some(page),
None,
None,
None,
None,
)
.await?;
Ok((r.items, r.pagination.pages, r.pagination.current))
})
.await
}
pub async fn live(&self) -> Result<Vec<models::LiveLog>, ManagerError> {
let resp = with_retry(&self.retry, true, || {
api::list_live_logs(self.cfg.as_ref(), None)
})
.await
.map_err(map_manager_err)?;
Ok(resp.items)
}
pub async fn enable_live(&self) -> Result<models::DefaultV2MessageResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::enable_live_logging(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn disable_live(&self) -> Result<models::DefaultV2MessageResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::disable_live_logging(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn write(
&self,
body: models::WriteLogRequest,
) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::write_log(self.cfg.as_ref(), body.clone())
})
.await
.map_err(map_manager_err)
}
}