reduct_base/msg/
bucket_api.rs1use crate::msg::entry_api::EntryInfo;
6use crate::msg::status::ResourceStatus;
7use serde::{Deserialize, Serialize};
8use std::fmt::Display;
9use std::str::FromStr;
10
11#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
17pub enum QuotaType {
18 #[default]
19 NONE = 0,
20 FIFO = 1,
21 HARD = 2,
22}
23
24impl From<i32> for QuotaType {
25 fn from(value: i32) -> Self {
26 match value {
27 0 => QuotaType::NONE,
28 1 => QuotaType::FIFO,
29 2 => QuotaType::HARD,
30 _ => QuotaType::NONE,
31 }
32 }
33}
34
35impl FromStr for QuotaType {
36 type Err = ();
37
38 fn from_str(s: &str) -> Result<Self, Self::Err> {
39 match s {
40 "NONE" => Ok(QuotaType::NONE),
41 "FIFO" => Ok(QuotaType::FIFO),
42 "HARD" => Ok(QuotaType::HARD),
43 _ => Err(()),
44 }
45 }
46}
47
48impl Display for QuotaType {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 match self {
51 QuotaType::NONE => write!(f, "NONE"),
52 QuotaType::FIFO => write!(f, "FIFO"),
53 QuotaType::HARD => write!(f, "HARD"),
54 }
55 }
56}
57
58#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
60pub struct BucketSettings {
61 pub quota_type: Option<QuotaType>,
63 pub quota_size: Option<u64>,
65 pub max_block_size: Option<u64>,
67 pub max_block_records: Option<u64>,
69}
70
71#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
73pub struct BucketInfo {
74 pub name: String,
76 pub entry_count: u64,
78 pub size: u64,
80 pub oldest_record: u64,
82 pub latest_record: u64,
84 pub is_provisioned: bool,
86 #[serde(default)]
88 pub status: ResourceStatus,
89}
90
91#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
93pub struct FullBucketInfo {
94 pub info: BucketInfo,
96 pub settings: BucketSettings,
98 pub entries: Vec<EntryInfo>,
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105 use rstest::rstest;
106
107 #[rstest]
108 #[case(QuotaType::NONE, "NONE")]
109 #[case(QuotaType::FIFO, "FIFO")]
110 #[case(QuotaType::HARD, "HARD")]
111 fn test_enum_as_string(#[case] quota_type: QuotaType, #[case] expected: &str) {
112 let settings = BucketSettings {
113 quota_type: Some(quota_type),
114 quota_size: Some(100),
115 max_block_size: Some(100),
116 max_block_records: Some(100),
117 };
118 let serialized = serde_json::to_string(&settings).unwrap();
119
120 assert_eq!(
121 serialized,
122 format!("{{\"quota_type\":\"{}\",\"quota_size\":100,\"max_block_size\":100,\"max_block_records\":100}}", expected)
123 );
124 }
125
126 #[rstest]
127 #[case(QuotaType::NONE, "NONE")]
128 #[case(QuotaType::FIFO, "FIFO")]
129 #[case(QuotaType::HARD, "HARD")]
130 fn test_quota_from_string(#[case] expected: QuotaType, #[case] as_string: &str) {
131 assert_eq!(QuotaType::from_str(as_string).unwrap(), expected);
132 }
133}
134
135#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
136pub struct RenameBucket {
137 pub new_name: String,
139}