redis_enterprise/
modules.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Module {
16 pub uid: String,
17 pub module_name: Option<String>,
18 pub version: Option<u32>,
19 pub semantic_version: Option<String>,
20 pub author: Option<String>,
21 pub description: Option<String>,
22 pub homepage: Option<String>,
23 pub license: Option<String>,
24 pub command_line_args: Option<String>,
25 pub capabilities: Option<Vec<String>>,
26 pub min_redis_version: Option<String>,
27 pub compatible_redis_version: Option<String>,
28 pub display_name: Option<String>,
29 pub is_bundled: Option<bool>,
30
31 pub bigstore_version_2_support: Option<bool>,
34
35 pub capability_name: Option<String>,
37
38 pub config_command: Option<String>,
40
41 pub crdb: Option<bool>,
43
44 pub dependencies: Option<Vec<Value>>,
46
47 pub email: Option<String>,
49
50 pub min_redis_pack_version: Option<String>,
52
53 pub platforms: Option<Vec<String>>,
55
56 pub sha256: Option<String>,
58
59 #[serde(flatten)]
60 pub extra: Value,
61}
62
63pub struct ModuleHandler {
65 client: RestClient,
66}
67
68pub type ModulesHandler = ModuleHandler;
70
71impl ModuleHandler {
72 pub fn new(client: RestClient) -> Self {
73 ModuleHandler { client }
74 }
75
76 pub async fn list(&self) -> Result<Vec<Module>> {
78 self.client.get("/v1/modules").await
79 }
80
81 pub async fn get(&self, uid: &str) -> Result<Module> {
83 self.client.get(&format!("/v1/modules/{}", uid)).await
84 }
85
86 pub async fn upload(&self, module_data: Vec<u8>, file_name: &str) -> Result<Value> {
88 match self
90 .client
91 .post_multipart("/v2/modules", module_data.clone(), "module", file_name)
92 .await
93 {
94 Ok(response) => Ok(response),
95 Err(crate::error::RestError::NotFound) => {
96 self.client
98 .post_multipart("/v1/modules", module_data, "module", file_name)
99 .await
100 }
101 Err(e) => Err(e),
102 }
103 }
104
105 pub async fn delete(&self, uid: &str) -> Result<()> {
107 self.client.delete(&format!("/v1/modules/{}", uid)).await
108 }
109
110 pub async fn update(&self, uid: &str, updates: Value) -> Result<Module> {
112 self.client
113 .put(&format!("/v1/modules/{}", uid), &updates)
114 .await
115 }
116
117 pub async fn config_bdb(&self, bdb_uid: u32, config: Value) -> Result<Module> {
119 self.client
120 .post(&format!("/v1/modules/config/bdb/{}", bdb_uid), &config)
121 .await
122 }
123}