1pub mod pos;
2#[derive(Debug, Clone)]
3pub struct GroupClient<T> {
4 client: T,
5 path: String,
6}
7impl<T> GroupClient<T>
8where
9 T: crate::client::Client,
10{
11 pub fn new(client: T, parent_path: &str, group: &str) -> Self {
12 Self {
13 client,
14 path: format!("{}/{}", parent_path, group),
15 }
16 }
17}
18impl<T> GroupClient<T>
19where
20 T: crate::client::Client,
21{
22 #[doc = "Delete security group."]
23 #[doc = ""]
24 #[doc = "Permission check: perm(\"/\", [\"Sys.Modify\"])"]
25 pub async fn delete(&self) -> Result<(), T::Error> {
26 let path = self.path.to_string();
27 self.client.delete(&path, &()).await
28 }
29}
30impl<T> GroupClient<T>
31where
32 T: crate::client::Client,
33{
34 #[doc = "List rules."]
35 #[doc = ""]
36 #[doc = "Permission check: perm(\"/\", [\"Sys.Audit\"])"]
37 pub async fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
38 let path = self.path.to_string();
39 let optional_vec: Option<Vec<GetOutputItems>> = self.client.get(&path, &()).await?;
40 Ok(optional_vec.unwrap_or_default())
41 }
42}
43impl<T> GroupClient<T>
44where
45 T: crate::client::Client,
46{
47 #[doc = "Create new rule."]
48 #[doc = ""]
49 #[doc = "Permission check: perm(\"/\", [\"Sys.Modify\"])"]
50 pub async fn post(&self, params: PostParams) -> Result<(), T::Error> {
51 let path = self.path.to_string();
52 self.client.post(&path, ¶ms).await
53 }
54}
55impl GetOutputItems {
56 pub fn new(action: String, pos: i64, ty: String) -> Self {
57 Self {
58 action,
59 pos,
60 ty,
61 comment: ::std::default::Default::default(),
62 dest: ::std::default::Default::default(),
63 dport: ::std::default::Default::default(),
64 enable: ::std::default::Default::default(),
65 icmp_type: ::std::default::Default::default(),
66 iface: ::std::default::Default::default(),
67 ipversion: ::std::default::Default::default(),
68 log: ::std::default::Default::default(),
69 macro_def: ::std::default::Default::default(),
70 proto: ::std::default::Default::default(),
71 source: ::std::default::Default::default(),
72 sport: ::std::default::Default::default(),
73 additional_properties: ::std::default::Default::default(),
74 }
75 }
76}
77#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
78pub struct GetOutputItems {
79 #[doc = "Rule action ('ACCEPT', 'DROP', 'REJECT') or security group name"]
80 #[doc = ""]
81 pub action: String,
82 #[serde(skip_serializing_if = "Option::is_none", default)]
83 #[doc = "Descriptive comment"]
84 #[doc = ""]
85 pub comment: Option<String>,
86 #[serde(skip_serializing_if = "Option::is_none", default)]
87 #[doc = "Restrict packet destination address"]
88 #[doc = ""]
89 pub dest: Option<String>,
90 #[serde(skip_serializing_if = "Option::is_none", default)]
91 #[doc = "Restrict TCP/UDP destination port"]
92 #[doc = ""]
93 pub dport: Option<String>,
94 #[serde(
95 serialize_with = "crate::types::serialize_int_optional",
96 deserialize_with = "crate::types::deserialize_int_optional"
97 )]
98 #[serde(skip_serializing_if = "Option::is_none", default)]
99 #[doc = "Flag to enable/disable a rule"]
100 #[doc = ""]
101 pub enable: Option<i64>,
102 #[serde(rename = "icmp-type")]
103 #[serde(skip_serializing_if = "Option::is_none", default)]
104 #[doc = "Specify icmp-type. Only valid if proto equals 'icmp' or 'icmpv6'/'ipv6-icmp'"]
105 #[doc = ""]
106 pub icmp_type: Option<String>,
107 #[serde(skip_serializing_if = "Option::is_none", default)]
108 #[doc = "Network interface name. You have to use network configuration key names for VMs and containers"]
109 #[doc = ""]
110 pub iface: Option<String>,
111 #[serde(
112 serialize_with = "crate::types::serialize_int_optional",
113 deserialize_with = "crate::types::deserialize_int_optional"
114 )]
115 #[serde(skip_serializing_if = "Option::is_none", default)]
116 #[doc = "IP version (4 or 6) - automatically determined from source/dest addresses"]
117 #[doc = ""]
118 pub ipversion: Option<i64>,
119 #[serde(skip_serializing_if = "Option::is_none", default)]
120 #[doc = "Log level for firewall rule"]
121 #[doc = ""]
122 pub log: Option<Log>,
123 #[serde(rename = "macro")]
124 #[serde(skip_serializing_if = "Option::is_none", default)]
125 #[doc = "Use predefined standard macro"]
126 #[doc = ""]
127 pub macro_def: Option<String>,
128 #[serde(
129 serialize_with = "crate::types::serialize_int",
130 deserialize_with = "crate::types::deserialize_int"
131 )]
132 #[doc = "Rule position in the ruleset"]
133 #[doc = ""]
134 pub pos: i64,
135 #[serde(skip_serializing_if = "Option::is_none", default)]
136 #[doc = "IP protocol. You can use protocol names ('tcp'/'udp') or simple numbers, as defined in '/etc/protocols'"]
137 #[doc = ""]
138 pub proto: Option<String>,
139 #[serde(skip_serializing_if = "Option::is_none", default)]
140 #[doc = "Restrict packet source address"]
141 #[doc = ""]
142 pub source: Option<String>,
143 #[serde(skip_serializing_if = "Option::is_none", default)]
144 #[doc = "Restrict TCP/UDP source port"]
145 #[doc = ""]
146 pub sport: Option<String>,
147 #[serde(rename = "type")]
148 #[doc = "Rule type"]
149 #[doc = ""]
150 pub ty: String,
151 #[serde(
152 flatten,
153 default,
154 skip_serializing_if = "::std::collections::HashMap::is_empty"
155 )]
156 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
157}
158impl PostParams {
159 pub fn new(action: ActionStr, ty: Type) -> Self {
160 Self {
161 action,
162 ty,
163 comment: ::std::default::Default::default(),
164 dest: ::std::default::Default::default(),
165 digest: ::std::default::Default::default(),
166 dport: ::std::default::Default::default(),
167 enable: ::std::default::Default::default(),
168 icmp_type: ::std::default::Default::default(),
169 iface: ::std::default::Default::default(),
170 log: ::std::default::Default::default(),
171 macro_def: ::std::default::Default::default(),
172 pos: ::std::default::Default::default(),
173 proto: ::std::default::Default::default(),
174 source: ::std::default::Default::default(),
175 sport: ::std::default::Default::default(),
176 additional_properties: ::std::default::Default::default(),
177 }
178 }
179}
180#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
181pub struct PostParams {
182 #[doc = "Rule action ('ACCEPT', 'DROP', 'REJECT') or security group name."]
183 #[doc = ""]
184 pub action: ActionStr,
185 #[serde(skip_serializing_if = "Option::is_none", default)]
186 #[doc = "Descriptive comment."]
187 #[doc = ""]
188 pub comment: Option<String>,
189 #[serde(skip_serializing_if = "Option::is_none", default)]
190 #[doc = "Restrict packet destination address. This can refer to a single IP address, an IP set ('+ipsetname') or an IP alias definition. You can also specify an address range like '20.34.101.207-201.3.9.99', or a list of IP addresses and networks (entries are separated by comma). Please do not mix IPv4 and IPv6 addresses inside such lists."]
191 #[doc = ""]
192 pub dest: Option<DestStr>,
193 #[serde(skip_serializing_if = "Option::is_none", default)]
194 #[doc = "Prevent changes if current configuration file has a different digest. This can be used to prevent concurrent modifications."]
195 #[doc = ""]
196 pub digest: Option<DigestStr>,
197 #[serde(skip_serializing_if = "Option::is_none", default)]
198 #[doc = "Restrict TCP/UDP destination port. You can use service names or simple numbers (0-65535), as defined in '/etc/services'. Port ranges can be specified with '\\d+:\\d+', for example '80:85', and you can use comma separated list to match several ports or ranges."]
199 #[doc = ""]
200 pub dport: Option<String>,
201 #[serde(
202 serialize_with = "crate::types::serialize_unsigned_int_optional",
203 deserialize_with = "crate::types::deserialize_unsigned_int_optional"
204 )]
205 #[serde(skip_serializing_if = "Option::is_none", default)]
206 #[doc = "Flag to enable/disable a rule."]
207 #[doc = ""]
208 pub enable: Option<u64>,
209 #[serde(rename = "icmp-type")]
210 #[serde(skip_serializing_if = "Option::is_none", default)]
211 #[doc = "Specify icmp-type. Only valid if proto equals 'icmp' or 'icmpv6'/'ipv6-icmp'."]
212 #[doc = ""]
213 pub icmp_type: Option<String>,
214 #[serde(skip_serializing_if = "Option::is_none", default)]
215 #[doc = "Network interface name. You have to use network configuration key names for VMs and containers ('net\\d+'). Host related rules can use arbitrary strings."]
216 #[doc = ""]
217 pub iface: Option<IfaceStr>,
218 #[serde(skip_serializing_if = "Option::is_none", default)]
219 #[doc = "Log level for firewall rule."]
220 #[doc = ""]
221 pub log: Option<Log>,
222 #[serde(rename = "macro")]
223 #[serde(skip_serializing_if = "Option::is_none", default)]
224 #[doc = "Use predefined standard macro."]
225 #[doc = ""]
226 pub macro_def: Option<MacroStr>,
227 #[serde(
228 serialize_with = "crate::types::serialize_unsigned_int_optional",
229 deserialize_with = "crate::types::deserialize_unsigned_int_optional"
230 )]
231 #[serde(skip_serializing_if = "Option::is_none", default)]
232 #[doc = "Update rule at position \\\\<pos\\\\>."]
233 #[doc = ""]
234 pub pos: Option<u64>,
235 #[serde(skip_serializing_if = "Option::is_none", default)]
236 #[doc = "IP protocol. You can use protocol names ('tcp'/'udp') or simple numbers, as defined in '/etc/protocols'."]
237 #[doc = ""]
238 pub proto: Option<String>,
239 #[serde(skip_serializing_if = "Option::is_none", default)]
240 #[doc = "Restrict packet source address. This can refer to a single IP address, an IP set ('+ipsetname') or an IP alias definition. You can also specify an address range like '20.34.101.207-201.3.9.99', or a list of IP addresses and networks (entries are separated by comma). Please do not mix IPv4 and IPv6 addresses inside such lists."]
241 #[doc = ""]
242 pub source: Option<SourceStr>,
243 #[serde(skip_serializing_if = "Option::is_none", default)]
244 #[doc = "Restrict TCP/UDP source port. You can use service names or simple numbers (0-65535), as defined in '/etc/services'. Port ranges can be specified with '\\d+:\\d+', for example '80:85', and you can use comma separated list to match several ports or ranges."]
245 #[doc = ""]
246 pub sport: Option<String>,
247 #[serde(rename = "type")]
248 #[doc = "Rule type."]
249 #[doc = ""]
250 pub ty: Type,
251 #[serde(
252 flatten,
253 default,
254 skip_serializing_if = "::std::collections::HashMap::is_empty"
255 )]
256 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
257}
258#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
259#[doc = "Log level for firewall rule"]
260#[doc = ""]
261pub enum Log {
262 #[serde(rename = "alert")]
263 Alert,
264 #[serde(rename = "crit")]
265 Crit,
266 #[serde(rename = "debug")]
267 Debug,
268 #[serde(rename = "emerg")]
269 Emerg,
270 #[serde(rename = "err")]
271 Err,
272 #[serde(rename = "info")]
273 Info,
274 #[serde(rename = "nolog")]
275 Nolog,
276 #[serde(rename = "notice")]
277 Notice,
278 #[serde(rename = "warning")]
279 Warning,
280}
281impl TryFrom<&str> for Log {
282 type Error = String;
283 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
284 match value {
285 "alert" => Ok(Self::Alert),
286 "crit" => Ok(Self::Crit),
287 "debug" => Ok(Self::Debug),
288 "emerg" => Ok(Self::Emerg),
289 "err" => Ok(Self::Err),
290 "info" => Ok(Self::Info),
291 "nolog" => Ok(Self::Nolog),
292 "notice" => Ok(Self::Notice),
293 "warning" => Ok(Self::Warning),
294 v => Err(format!("Unknown variant {v}")),
295 }
296 }
297}
298#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
299#[doc = "Rule type."]
300#[doc = ""]
301pub enum Type {
302 #[serde(rename = "forward")]
303 Forward,
304 #[serde(rename = "group")]
305 Group,
306 #[serde(rename = "in")]
307 In,
308 #[serde(rename = "out")]
309 Out,
310}
311impl TryFrom<&str> for Type {
312 type Error = String;
313 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
314 match value {
315 "forward" => Ok(Self::Forward),
316 "group" => Ok(Self::Group),
317 "in" => Ok(Self::In),
318 "out" => Ok(Self::Out),
319 v => Err(format!("Unknown variant {v}")),
320 }
321 }
322}
323#[derive(Debug, Clone, PartialEq, PartialOrd)]
324pub struct ActionStr {
325 value: String,
326}
327impl crate::types::bounded_string::BoundedString for ActionStr {
328 const MIN_LENGTH: Option<usize> = Some(2usize);
329 const MAX_LENGTH: Option<usize> = Some(20usize);
330 const DEFAULT: Option<&'static str> = None::<&'static str>;
331 const PATTERN: Option<&'static str> = Some("[A-Za-z][A-Za-z0-9\\-\\_]+");
332 const TYPE_DESCRIPTION: &'static str =
333 "a string with pattern r\"[A-Za-z][A-Za-z0-9\\-\\_]+\" and length between 2 and 20";
334 fn get_value(&self) -> &str {
335 &self.value
336 }
337 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
338 Self::validate(&value)?;
339 Ok(Self { value })
340 }
341}
342impl std::convert::TryFrom<String> for ActionStr {
343 type Error = crate::types::bounded_string::BoundedStringError;
344 fn try_from(value: String) -> Result<Self, Self::Error> {
345 crate::types::bounded_string::BoundedString::new(value)
346 }
347}
348impl ::serde::Serialize for ActionStr {
349 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
350 where
351 S: ::serde::Serializer,
352 {
353 crate::types::bounded_string::serialize_bounded_string(self, serializer)
354 }
355}
356impl<'de> ::serde::Deserialize<'de> for ActionStr {
357 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
358 where
359 D: ::serde::Deserializer<'de>,
360 {
361 crate::types::bounded_string::deserialize_bounded_string(deserializer)
362 }
363}
364#[derive(Debug, Clone, PartialEq, PartialOrd)]
365pub struct DestStr {
366 value: String,
367}
368impl crate::types::bounded_string::BoundedString for DestStr {
369 const MIN_LENGTH: Option<usize> = None::<usize>;
370 const MAX_LENGTH: Option<usize> = Some(512usize);
371 const DEFAULT: Option<&'static str> = None::<&'static str>;
372 const PATTERN: Option<&'static str> = None::<&'static str>;
373 const TYPE_DESCRIPTION: &'static str = "a string with length at most 512";
374 fn get_value(&self) -> &str {
375 &self.value
376 }
377 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
378 Self::validate(&value)?;
379 Ok(Self { value })
380 }
381}
382impl std::convert::TryFrom<String> for DestStr {
383 type Error = crate::types::bounded_string::BoundedStringError;
384 fn try_from(value: String) -> Result<Self, Self::Error> {
385 crate::types::bounded_string::BoundedString::new(value)
386 }
387}
388impl ::serde::Serialize for DestStr {
389 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
390 where
391 S: ::serde::Serializer,
392 {
393 crate::types::bounded_string::serialize_bounded_string(self, serializer)
394 }
395}
396impl<'de> ::serde::Deserialize<'de> for DestStr {
397 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
398 where
399 D: ::serde::Deserializer<'de>,
400 {
401 crate::types::bounded_string::deserialize_bounded_string(deserializer)
402 }
403}
404#[derive(Debug, Clone, PartialEq, PartialOrd)]
405pub struct DigestStr {
406 value: String,
407}
408impl crate::types::bounded_string::BoundedString for DigestStr {
409 const MIN_LENGTH: Option<usize> = None::<usize>;
410 const MAX_LENGTH: Option<usize> = Some(64usize);
411 const DEFAULT: Option<&'static str> = None::<&'static str>;
412 const PATTERN: Option<&'static str> = None::<&'static str>;
413 const TYPE_DESCRIPTION: &'static str = "a string with length at most 64";
414 fn get_value(&self) -> &str {
415 &self.value
416 }
417 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
418 Self::validate(&value)?;
419 Ok(Self { value })
420 }
421}
422impl std::convert::TryFrom<String> for DigestStr {
423 type Error = crate::types::bounded_string::BoundedStringError;
424 fn try_from(value: String) -> Result<Self, Self::Error> {
425 crate::types::bounded_string::BoundedString::new(value)
426 }
427}
428impl ::serde::Serialize for DigestStr {
429 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
430 where
431 S: ::serde::Serializer,
432 {
433 crate::types::bounded_string::serialize_bounded_string(self, serializer)
434 }
435}
436impl<'de> ::serde::Deserialize<'de> for DigestStr {
437 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
438 where
439 D: ::serde::Deserializer<'de>,
440 {
441 crate::types::bounded_string::deserialize_bounded_string(deserializer)
442 }
443}
444#[derive(Debug, Clone, PartialEq, PartialOrd)]
445pub struct IfaceStr {
446 value: String,
447}
448impl crate::types::bounded_string::BoundedString for IfaceStr {
449 const MIN_LENGTH: Option<usize> = Some(2usize);
450 const MAX_LENGTH: Option<usize> = Some(20usize);
451 const DEFAULT: Option<&'static str> = None::<&'static str>;
452 const PATTERN: Option<&'static str> = None::<&'static str>;
453 const TYPE_DESCRIPTION: &'static str = "a string with length between 2 and 20";
454 fn get_value(&self) -> &str {
455 &self.value
456 }
457 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
458 Self::validate(&value)?;
459 Ok(Self { value })
460 }
461}
462impl std::convert::TryFrom<String> for IfaceStr {
463 type Error = crate::types::bounded_string::BoundedStringError;
464 fn try_from(value: String) -> Result<Self, Self::Error> {
465 crate::types::bounded_string::BoundedString::new(value)
466 }
467}
468impl ::serde::Serialize for IfaceStr {
469 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
470 where
471 S: ::serde::Serializer,
472 {
473 crate::types::bounded_string::serialize_bounded_string(self, serializer)
474 }
475}
476impl<'de> ::serde::Deserialize<'de> for IfaceStr {
477 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
478 where
479 D: ::serde::Deserializer<'de>,
480 {
481 crate::types::bounded_string::deserialize_bounded_string(deserializer)
482 }
483}
484#[derive(Debug, Clone, PartialEq, PartialOrd)]
485pub struct MacroStr {
486 value: String,
487}
488impl crate::types::bounded_string::BoundedString for MacroStr {
489 const MIN_LENGTH: Option<usize> = None::<usize>;
490 const MAX_LENGTH: Option<usize> = Some(128usize);
491 const DEFAULT: Option<&'static str> = None::<&'static str>;
492 const PATTERN: Option<&'static str> = None::<&'static str>;
493 const TYPE_DESCRIPTION: &'static str = "a string with length at most 128";
494 fn get_value(&self) -> &str {
495 &self.value
496 }
497 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
498 Self::validate(&value)?;
499 Ok(Self { value })
500 }
501}
502impl std::convert::TryFrom<String> for MacroStr {
503 type Error = crate::types::bounded_string::BoundedStringError;
504 fn try_from(value: String) -> Result<Self, Self::Error> {
505 crate::types::bounded_string::BoundedString::new(value)
506 }
507}
508impl ::serde::Serialize for MacroStr {
509 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
510 where
511 S: ::serde::Serializer,
512 {
513 crate::types::bounded_string::serialize_bounded_string(self, serializer)
514 }
515}
516impl<'de> ::serde::Deserialize<'de> for MacroStr {
517 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
518 where
519 D: ::serde::Deserializer<'de>,
520 {
521 crate::types::bounded_string::deserialize_bounded_string(deserializer)
522 }
523}
524#[derive(Debug, Clone, PartialEq, PartialOrd)]
525pub struct SourceStr {
526 value: String,
527}
528impl crate::types::bounded_string::BoundedString for SourceStr {
529 const MIN_LENGTH: Option<usize> = None::<usize>;
530 const MAX_LENGTH: Option<usize> = Some(512usize);
531 const DEFAULT: Option<&'static str> = None::<&'static str>;
532 const PATTERN: Option<&'static str> = None::<&'static str>;
533 const TYPE_DESCRIPTION: &'static str = "a string with length at most 512";
534 fn get_value(&self) -> &str {
535 &self.value
536 }
537 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
538 Self::validate(&value)?;
539 Ok(Self { value })
540 }
541}
542impl std::convert::TryFrom<String> for SourceStr {
543 type Error = crate::types::bounded_string::BoundedStringError;
544 fn try_from(value: String) -> Result<Self, Self::Error> {
545 crate::types::bounded_string::BoundedString::new(value)
546 }
547}
548impl ::serde::Serialize for SourceStr {
549 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
550 where
551 S: ::serde::Serializer,
552 {
553 crate::types::bounded_string::serialize_bounded_string(self, serializer)
554 }
555}
556impl<'de> ::serde::Deserialize<'de> for SourceStr {
557 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
558 where
559 D: ::serde::Deserializer<'de>,
560 {
561 crate::types::bounded_string::deserialize_bounded_string(deserializer)
562 }
563}
564impl<T> GroupClient<T>
565where
566 T: crate::client::Client,
567{
568 pub fn pos(&self, pos: &str) -> pos::PosClient<T> {
569 pos::PosClient::<T>::new(self.client.clone(), &self.path, pos)
570 }
571}