use crate::client::RestClient;
use crate::error::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::BTreeMap;
use typed_builder::TypedBuilder;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct License {
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub license: Option<String>,
#[serde(rename = "type")]
pub type_: Option<String>,
pub expired: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub activation_date: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration_date: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shards_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ram_shards_in_use: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ram_shards_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub flash_shards_in_use: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub flash_shards_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub features: Option<Vec<String>>,
#[serde(default, flatten, skip_serializing_if = "BTreeMap::is_empty")]
pub additional_fields: BTreeMap<String, Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
pub struct LicenseUpdateRequest {
#[builder(setter(into))]
pub license: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LicenseUsage {
pub shards_used: u32,
pub shards_limit: u32,
pub nodes_used: u32,
pub nodes_limit: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub ram_used: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ram_limit: Option<u64>,
}
pub struct LicenseHandler {
client: RestClient,
}
impl LicenseHandler {
pub fn new(client: RestClient) -> Self {
LicenseHandler { client }
}
pub async fn get(&self) -> Result<License> {
self.client.get("/v1/license").await
}
pub async fn update(&self, request: LicenseUpdateRequest) -> Result<License> {
self.client.put_action("/v1/license", &request).await?;
self.get().await
}
#[deprecated(note = "Redis Software does not register /v1/license/usage")]
pub async fn usage(&self) -> Result<LicenseUsage> {
crate::error::unsupported_operation("get license usage")
}
#[deprecated(note = "install with update and inspect the canonical license resource")]
pub async fn validate(&self, _license_key: &str) -> Result<License> {
crate::error::unsupported_operation("validate license without installing it")
}
pub async fn cluster_license(&self) -> Result<License> {
self.get().await
}
}