Skip to main content

proxmox_api/generated/nodes/node/firewall/
rules.rs

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