cx_sdk/client/
archive_retentions.rsuse cx_api::proto::com::coralogix::archive::v1::{
ActivateRetentionsRequest,
ActivateRetentionsResponse,
GetRetentionsEnabledRequest,
GetRetentionsEnabledResponse,
GetRetentionsRequest,
GetRetentionsResponse,
UpdateRetentionsRequest,
UpdateRetentionsResponse,
retentions_service_client::RetentionsServiceClient,
};
use std::str::FromStr;
use tokio::sync::Mutex;
use tonic::{
metadata::MetadataMap,
transport::{
Channel,
ClientTlsConfig,
Endpoint,
},
};
use crate::{
CoralogixRegion,
auth::AuthContext,
error::{
Result,
SdkApiError,
SdkError,
},
metadata::CallProperties,
util::make_request_with_metadata,
};
pub use cx_api::proto::com::coralogix::archive::v1::RetentionUpdateElement;
const ARCHIVE_FEATURE_GROUP_ID: &str = "archive";
pub struct ArchiveRetentionClient {
metadata_map: MetadataMap,
service_client: Mutex<RetentionsServiceClient<Channel>>,
}
impl ArchiveRetentionClient {
pub fn new(auth_context: AuthContext, region: CoralogixRegion) -> Result<Self> {
let channel: Channel = Endpoint::from_str(region.grpc_endpoint().as_str())?
.tls_config(ClientTlsConfig::new().with_native_roots())?
.connect_lazy();
let request_metadata: CallProperties = (&auth_context.team_level_api_key).into();
Ok(Self {
metadata_map: request_metadata.to_metadata_map(),
service_client: Mutex::new(RetentionsServiceClient::new(channel)),
})
}
pub async fn get(&self) -> Result<GetRetentionsResponse> {
Ok(self
.service_client
.lock()
.await
.get_retentions(make_request_with_metadata(
GetRetentionsRequest {},
&self.metadata_map,
))
.await
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogix.archive.v1.RetentionsService/GetRetentions"
.to_string(),
feature_group: ARCHIVE_FEATURE_GROUP_ID.to_string(),
})
})?
.into_inner())
}
pub async fn get_enabled(&self) -> Result<GetRetentionsEnabledResponse> {
Ok(self
.service_client
.lock()
.await
.get_retentions_enabled(make_request_with_metadata(
GetRetentionsEnabledRequest {},
&self.metadata_map,
))
.await
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogix.archive.v1.RetentionsService/GetEnabled".to_string(),
feature_group: ARCHIVE_FEATURE_GROUP_ID.to_string(),
})
})?
.into_inner())
}
pub async fn update(
&self,
retention_update_elements: Vec<RetentionUpdateElement>,
) -> Result<UpdateRetentionsResponse> {
Ok(self
.service_client
.lock()
.await
.update_retentions(make_request_with_metadata(
UpdateRetentionsRequest {
retention_update_elements,
},
&self.metadata_map,
))
.await
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogix.archive.v1.RetentionsService/UpdateRetentions"
.to_string(),
feature_group: ARCHIVE_FEATURE_GROUP_ID.to_string(),
})
})?
.into_inner())
}
pub async fn activate(&self) -> Result<ActivateRetentionsResponse> {
Ok(self
.service_client
.lock()
.await
.activate_retentions(make_request_with_metadata(
ActivateRetentionsRequest {},
&self.metadata_map,
))
.await
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogix.archive.v1.RetentionsService/ActivateRetentions"
.to_string(),
feature_group: ARCHIVE_FEATURE_GROUP_ID.to_string(),
})
})?
.into_inner())
}
}