pub mod pos;
#[derive(Debug, Clone)]
pub struct GroupClient<T> {
client: T,
path: String,
}
impl<T> GroupClient<T>
where
T: crate::client::Client,
{
pub fn new(client: T, parent_path: &str, group: &str) -> Self {
Self {
client,
path: format!("{}/{}", parent_path, group),
}
}
}
impl<T> GroupClient<T>
where
T: crate::client::Client,
{
#[doc = "Delete security group."]
#[doc = ""]
#[doc = "Permission check: perm(\"/\", [\"Sys.Modify\"])"]
pub async fn delete(&self) -> Result<(), T::Error> {
let path = self.path.to_string();
self.client.delete(&path, &()).await
}
}
impl<T> GroupClient<T>
where
T: crate::client::Client,
{
#[doc = "List rules."]
#[doc = ""]
#[doc = "Permission check: perm(\"/\", [\"Sys.Audit\"])"]
pub async fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
let path = self.path.to_string();
let optional_vec: Option<Vec<GetOutputItems>> = self.client.get(&path, &()).await?;
Ok(optional_vec.unwrap_or_default())
}
}
impl<T> GroupClient<T>
where
T: crate::client::Client,
{
#[doc = "Create new rule."]
#[doc = ""]
#[doc = "Permission check: perm(\"/\", [\"Sys.Modify\"])"]
pub async fn post(&self, params: PostParams) -> Result<(), T::Error> {
let path = self.path.to_string();
self.client.post(&path, ¶ms).await
}
}
impl GetOutputItems {
pub fn new(action: String, pos: i64, ty: String) -> Self {
Self {
action,
pos,
ty,
comment: ::std::default::Default::default(),
dest: ::std::default::Default::default(),
dport: ::std::default::Default::default(),
enable: ::std::default::Default::default(),
icmp_type: ::std::default::Default::default(),
iface: ::std::default::Default::default(),
ipversion: ::std::default::Default::default(),
log: ::std::default::Default::default(),
macro_def: ::std::default::Default::default(),
proto: ::std::default::Default::default(),
source: ::std::default::Default::default(),
sport: ::std::default::Default::default(),
additional_properties: ::std::default::Default::default(),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
pub struct GetOutputItems {
#[doc = "Rule action ('ACCEPT', 'DROP', 'REJECT') or security group name"]
#[doc = ""]
pub action: String,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Descriptive comment"]
#[doc = ""]
pub comment: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Restrict packet destination address"]
#[doc = ""]
pub dest: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Restrict TCP/UDP destination port"]
#[doc = ""]
pub dport: Option<String>,
#[serde(
serialize_with = "crate::types::serialize_int_optional",
deserialize_with = "crate::types::deserialize_int_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Flag to enable/disable a rule"]
#[doc = ""]
pub enable: Option<i64>,
#[serde(rename = "icmp-type")]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Specify icmp-type. Only valid if proto equals 'icmp' or 'icmpv6'/'ipv6-icmp'"]
#[doc = ""]
pub icmp_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Network interface name. You have to use network configuration key names for VMs and containers"]
#[doc = ""]
pub iface: Option<String>,
#[serde(
serialize_with = "crate::types::serialize_int_optional",
deserialize_with = "crate::types::deserialize_int_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "IP version (4 or 6) - automatically determined from source/dest addresses"]
#[doc = ""]
pub ipversion: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Log level for firewall rule"]
#[doc = ""]
pub log: Option<Log>,
#[serde(rename = "macro")]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Use predefined standard macro"]
#[doc = ""]
pub macro_def: Option<String>,
#[serde(
serialize_with = "crate::types::serialize_int",
deserialize_with = "crate::types::deserialize_int"
)]
#[doc = "Rule position in the ruleset"]
#[doc = ""]
pub pos: i64,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "IP protocol. You can use protocol names ('tcp'/'udp') or simple numbers, as defined in '/etc/protocols'"]
#[doc = ""]
pub proto: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Restrict packet source address"]
#[doc = ""]
pub source: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Restrict TCP/UDP source port"]
#[doc = ""]
pub sport: Option<String>,
#[serde(rename = "type")]
#[doc = "Rule type"]
#[doc = ""]
pub ty: String,
#[serde(
flatten,
default,
skip_serializing_if = "::std::collections::HashMap::is_empty"
)]
pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
}
impl PostParams {
pub fn new(action: ActionStr, ty: Type) -> Self {
Self {
action,
ty,
comment: ::std::default::Default::default(),
dest: ::std::default::Default::default(),
digest: ::std::default::Default::default(),
dport: ::std::default::Default::default(),
enable: ::std::default::Default::default(),
icmp_type: ::std::default::Default::default(),
iface: ::std::default::Default::default(),
log: ::std::default::Default::default(),
macro_def: ::std::default::Default::default(),
pos: ::std::default::Default::default(),
proto: ::std::default::Default::default(),
source: ::std::default::Default::default(),
sport: ::std::default::Default::default(),
additional_properties: ::std::default::Default::default(),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
pub struct PostParams {
#[doc = "Rule action ('ACCEPT', 'DROP', 'REJECT') or security group name."]
#[doc = ""]
pub action: ActionStr,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Descriptive comment."]
#[doc = ""]
pub comment: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[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."]
#[doc = ""]
pub dest: Option<DestStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Prevent changes if current configuration file has a different digest. This can be used to prevent concurrent modifications."]
#[doc = ""]
pub digest: Option<DigestStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[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."]
#[doc = ""]
pub dport: Option<String>,
#[serde(
serialize_with = "crate::types::serialize_unsigned_int_optional",
deserialize_with = "crate::types::deserialize_unsigned_int_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Flag to enable/disable a rule."]
#[doc = ""]
pub enable: Option<u64>,
#[serde(rename = "icmp-type")]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Specify icmp-type. Only valid if proto equals 'icmp' or 'icmpv6'/'ipv6-icmp'."]
#[doc = ""]
pub icmp_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[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."]
#[doc = ""]
pub iface: Option<IfaceStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Log level for firewall rule."]
#[doc = ""]
pub log: Option<Log>,
#[serde(rename = "macro")]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Use predefined standard macro."]
#[doc = ""]
pub macro_def: Option<MacroStr>,
#[serde(
serialize_with = "crate::types::serialize_unsigned_int_optional",
deserialize_with = "crate::types::deserialize_unsigned_int_optional"
)]
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "Update rule at position \\\\<pos\\\\>."]
#[doc = ""]
pub pos: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[doc = "IP protocol. You can use protocol names ('tcp'/'udp') or simple numbers, as defined in '/etc/protocols'."]
#[doc = ""]
pub proto: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[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."]
#[doc = ""]
pub source: Option<SourceStr>,
#[serde(skip_serializing_if = "Option::is_none", default)]
#[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."]
#[doc = ""]
pub sport: Option<String>,
#[serde(rename = "type")]
#[doc = "Rule type."]
#[doc = ""]
pub ty: Type,
#[serde(
flatten,
default,
skip_serializing_if = "::std::collections::HashMap::is_empty"
)]
pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
#[doc = "Log level for firewall rule"]
#[doc = ""]
pub enum Log {
#[serde(rename = "alert")]
Alert,
#[serde(rename = "crit")]
Crit,
#[serde(rename = "debug")]
Debug,
#[serde(rename = "emerg")]
Emerg,
#[serde(rename = "err")]
Err,
#[serde(rename = "info")]
Info,
#[serde(rename = "nolog")]
Nolog,
#[serde(rename = "notice")]
Notice,
#[serde(rename = "warning")]
Warning,
}
impl TryFrom<&str> for Log {
type Error = String;
fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
match value {
"alert" => Ok(Self::Alert),
"crit" => Ok(Self::Crit),
"debug" => Ok(Self::Debug),
"emerg" => Ok(Self::Emerg),
"err" => Ok(Self::Err),
"info" => Ok(Self::Info),
"nolog" => Ok(Self::Nolog),
"notice" => Ok(Self::Notice),
"warning" => Ok(Self::Warning),
v => Err(format!("Unknown variant {v}")),
}
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
#[doc = "Rule type."]
#[doc = ""]
pub enum Type {
#[serde(rename = "forward")]
Forward,
#[serde(rename = "group")]
Group,
#[serde(rename = "in")]
In,
#[serde(rename = "out")]
Out,
}
impl TryFrom<&str> for Type {
type Error = String;
fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
match value {
"forward" => Ok(Self::Forward),
"group" => Ok(Self::Group),
"in" => Ok(Self::In),
"out" => Ok(Self::Out),
v => Err(format!("Unknown variant {v}")),
}
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct ActionStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for ActionStr {
const MIN_LENGTH: Option<usize> = Some(2usize);
const MAX_LENGTH: Option<usize> = Some(20usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = Some("[A-Za-z][A-Za-z0-9\\-\\_]+");
const TYPE_DESCRIPTION: &'static str =
"a string with pattern r\"[A-Za-z][A-Za-z0-9\\-\\_]+\" and length between 2 and 20";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for ActionStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for ActionStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for ActionStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct DestStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for DestStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(512usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 512";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for DestStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for DestStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for DestStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct DigestStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for DigestStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(64usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 64";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for DigestStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for DigestStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for DigestStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct IfaceStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for IfaceStr {
const MIN_LENGTH: Option<usize> = Some(2usize);
const MAX_LENGTH: Option<usize> = Some(20usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length between 2 and 20";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for IfaceStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for IfaceStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for IfaceStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct MacroStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for MacroStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(128usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 128";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for MacroStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for MacroStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for MacroStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct SourceStr {
value: String,
}
impl crate::types::bounded_string::BoundedString for SourceStr {
const MIN_LENGTH: Option<usize> = None::<usize>;
const MAX_LENGTH: Option<usize> = Some(512usize);
const DEFAULT: Option<&'static str> = None::<&'static str>;
const PATTERN: Option<&'static str> = None::<&'static str>;
const TYPE_DESCRIPTION: &'static str = "a string with length at most 512";
fn get_value(&self) -> &str {
&self.value
}
fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
Self::validate(&value)?;
Ok(Self { value })
}
}
impl std::convert::TryFrom<String> for SourceStr {
type Error = crate::types::bounded_string::BoundedStringError;
fn try_from(value: String) -> Result<Self, Self::Error> {
crate::types::bounded_string::BoundedString::new(value)
}
}
impl ::serde::Serialize for SourceStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
crate::types::bounded_string::serialize_bounded_string(self, serializer)
}
}
impl<'de> ::serde::Deserialize<'de> for SourceStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
crate::types::bounded_string::deserialize_bounded_string(deserializer)
}
}
impl<T> GroupClient<T>
where
T: crate::client::Client,
{
pub fn pos(&self, pos: &str) -> pos::PosClient<T> {
pos::PosClient::<T>::new(self.client.clone(), &self.path, pos)
}
}