redis_enterprise/
ldap_mappings.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12use typed_builder::TypedBuilder;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct LdapMapping {
17 pub uid: u32,
19 pub name: String,
21 pub dn: String,
23 pub role: String,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub email: Option<String>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub role_uids: Option<Vec<u32>>,
31
32 #[serde(flatten)]
33 pub extra: Value,
34}
35
36#[derive(Debug, Serialize, Deserialize, TypedBuilder)]
38pub struct CreateLdapMappingRequest {
39 #[builder(setter(into))]
41 pub name: String,
42 #[builder(setter(into))]
44 pub dn: String,
45 #[builder(setter(into))]
47 pub role: String,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 #[builder(default, setter(into, strip_option))]
51 pub email: Option<String>,
52 #[serde(skip_serializing_if = "Option::is_none")]
54 #[builder(default, setter(strip_option))]
55 pub role_uids: Option<Vec<u32>>,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct LdapConfig {
61 pub enabled: bool,
63 #[serde(skip_serializing_if = "Option::is_none")]
65 pub servers: Option<Vec<LdapServer>>,
66 #[serde(skip_serializing_if = "Option::is_none")]
68 pub cache_refresh_interval: Option<u32>,
69 #[serde(skip_serializing_if = "Option::is_none")]
71 pub authentication_query_suffix: Option<String>,
72 #[serde(skip_serializing_if = "Option::is_none")]
74 pub authorization_query_suffix: Option<String>,
75 #[serde(skip_serializing_if = "Option::is_none")]
77 pub bind_dn: Option<String>,
78 #[serde(skip_serializing_if = "Option::is_none")]
80 pub bind_pass: Option<String>,
81
82 #[serde(flatten)]
83 pub extra: Value,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct LdapServer {
89 pub host: String,
91 pub port: u16,
93 #[serde(skip_serializing_if = "Option::is_none")]
95 pub use_tls: Option<bool>,
96 #[serde(skip_serializing_if = "Option::is_none")]
98 pub starttls: Option<bool>,
99}
100
101pub struct LdapMappingHandler {
103 client: RestClient,
104}
105
106impl LdapMappingHandler {
107 pub fn new(client: RestClient) -> Self {
108 LdapMappingHandler { client }
109 }
110
111 pub async fn list(&self) -> Result<Vec<LdapMapping>> {
113 self.client.get("/v1/ldap_mappings").await
114 }
115
116 pub async fn get(&self, uid: u32) -> Result<LdapMapping> {
118 self.client.get(&format!("/v1/ldap_mappings/{}", uid)).await
119 }
120
121 pub async fn create(&self, request: CreateLdapMappingRequest) -> Result<LdapMapping> {
123 self.client.post("/v1/ldap_mappings", &request).await
124 }
125
126 pub async fn update(&self, uid: u32, request: CreateLdapMappingRequest) -> Result<LdapMapping> {
128 self.client
129 .put(&format!("/v1/ldap_mappings/{}", uid), &request)
130 .await
131 }
132
133 pub async fn delete(&self, uid: u32) -> Result<()> {
135 self.client
136 .delete(&format!("/v1/ldap_mappings/{}", uid))
137 .await
138 }
139
140 pub async fn get_config(&self) -> Result<LdapConfig> {
142 self.client.get("/v1/cluster/ldap").await
143 }
144
145 pub async fn update_config(&self, config: LdapConfig) -> Result<LdapConfig> {
147 self.client.put("/v1/cluster/ldap", &config).await
148 }
149}