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