forked from Proxmox/proxmox
formatting fixup
add #[rustfmt::skip] to our macros... Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d6d65be42e
commit
d78142302c
@ -42,12 +42,7 @@ pub enum ConsoleMode {
|
||||
pub mod mount_options {
|
||||
pub const NAME: &'static str = "mount options";
|
||||
|
||||
const VALID_MOUNT_OPTIONS: &[&'static str] = &[
|
||||
"noatime",
|
||||
"nodev",
|
||||
"noexec",
|
||||
"nosuid",
|
||||
];
|
||||
const VALID_MOUNT_OPTIONS: &[&'static str] = &["noatime", "nodev", "noexec", "nosuid"];
|
||||
|
||||
pub fn verify<T: crate::schema::tools::StringContainer>(value: &T) -> bool {
|
||||
value.all(|s| VALID_MOUNT_OPTIONS.contains(&s))
|
||||
|
@ -73,10 +73,7 @@ pub mod safe_path {
|
||||
|
||||
pub fn verify<T: crate::schema::tools::StringContainer>(value: &T) -> bool {
|
||||
value.all(|s| {
|
||||
s != ".."
|
||||
&& !s.starts_with("../")
|
||||
&& !s.ends_with("/..")
|
||||
&& !s.contains("/../")
|
||||
s != ".." && !s.starts_with("../") && !s.ends_with("/..") && !s.contains("/../")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,9 @@ impl<'de> serde::de::Visitor<'de> for StringListVisitor {
|
||||
}
|
||||
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
||||
let mut out = seq.size_hint().map_or_else(Vec::new, |size| Vec::with_capacity(size));
|
||||
let mut out = seq
|
||||
.size_hint()
|
||||
.map_or_else(Vec::new, |size| Vec::with_capacity(size));
|
||||
loop {
|
||||
match seq.next_element::<String>()? {
|
||||
Some(el) => out.push(el),
|
||||
|
@ -33,7 +33,10 @@ where
|
||||
value
|
||||
.for_each_str(|s| {
|
||||
if s.contains(';') {
|
||||
bail!("cannot include value \"{}\" in a semicolon separated list", s);
|
||||
bail!(
|
||||
"cannot include value \"{}\" in a semicolon separated list",
|
||||
s
|
||||
);
|
||||
}
|
||||
|
||||
if !data.is_empty() {
|
||||
|
@ -33,7 +33,9 @@ impl StringContainer for Vec<String> {
|
||||
|
||||
impl StringContainer for Option<Vec<String>> {
|
||||
fn all<F: Fn(&str) -> bool>(&self, pred: F) -> bool {
|
||||
self.as_ref().map(|c| StringContainer::all(c, pred)).unwrap_or(true)
|
||||
self.as_ref()
|
||||
.map(|c| StringContainer::all(c, pred))
|
||||
.unwrap_or(true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,6 +47,8 @@ impl StringContainer for HashSet<String> {
|
||||
|
||||
impl StringContainer for Option<HashSet<String>> {
|
||||
fn all<F: Fn(&str) -> bool>(&self, pred: F) -> bool {
|
||||
self.as_ref().map(|c| StringContainer::all(c, pred)).unwrap_or(true)
|
||||
self.as_ref()
|
||||
.map(|c| StringContainer::all(c, pred))
|
||||
.unwrap_or(true)
|
||||
}
|
||||
}
|
||||
|
@ -337,10 +337,8 @@ fn parse_path_name(tokens: &mut TokenIter) -> Result<Path, Error> {
|
||||
if group.delimiter() != Delimiter::Brace {
|
||||
bail!("invalid path component: {:?}", group);
|
||||
}
|
||||
let name = need_hyphenated_name(
|
||||
group.span(),
|
||||
&mut group.stream().into_iter().peekable(),
|
||||
)?;
|
||||
let name =
|
||||
need_hyphenated_name(group.span(), &mut group.stream().into_iter().peekable())?;
|
||||
push_component(&mut path, &mut component, &mut span);
|
||||
path.push(Component::Match(name));
|
||||
|
||||
|
@ -385,13 +385,14 @@ impl ParseCli for String {
|
||||
|
||||
impl ParseCli for HashSet<String> {
|
||||
fn parse_cli(name: &str, value: Option<&str>) -> Result<Value, Error> {
|
||||
Ok(serde_json::Value::Array(value
|
||||
.ok_or_else(|| format_err!("missing value for parameter '{}'", name))?
|
||||
.split(';')
|
||||
.fold(Vec::new(), |mut list, entry| {
|
||||
list.push(serde_json::Value::String(entry.trim().to_string()));
|
||||
list
|
||||
})
|
||||
Ok(serde_json::Value::Array(
|
||||
value
|
||||
.ok_or_else(|| format_err!("missing value for parameter '{}'", name))?
|
||||
.split(';')
|
||||
.fold(Vec::new(), |mut list, entry| {
|
||||
list.push(serde_json::Value::String(entry.trim().to_string()));
|
||||
list
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -5,18 +5,23 @@
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPV4OCTET { () => (r"(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])") }
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPV6H16 { () => (r"(?:[0-9a-fA-F]{1,4})") }
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPV6LS32 { () => (concat!(r"(?:(?:", IPV4RE!(), "|", IPV6H16!(), ":", IPV6H16!(), "))" )) }
|
||||
|
||||
/// Returns the regular expression string to match IPv4 addresses
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPV4RE { () => (concat!(r"(?:(?:", IPV4OCTET!(), r"\.){3}", IPV4OCTET!(), ")")) }
|
||||
|
||||
/// Returns the regular expression string to match IPv6 addresses
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPV6RE { () => (concat!(r"(?:",
|
||||
r"(?:(?:", r"(?:", IPV6H16!(), r":){6})", IPV6LS32!(), r")|",
|
||||
@ -31,17 +36,13 @@ macro_rules! IPV6RE { () => (concat!(r"(?:",
|
||||
}
|
||||
|
||||
/// Returns the regular expression string to match IP addresses (v4 or v6)
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
|
||||
|
||||
lazy_static! {
|
||||
pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap();
|
||||
|
||||
pub static ref SHA256_HEX_REGEX: Regex =
|
||||
Regex::new(r"^[a-f0-9]{64}$")
|
||||
.unwrap();
|
||||
|
||||
pub static ref SHA256_HEX_REGEX: Regex = Regex::new(r"^[a-f0-9]{64}$").unwrap();
|
||||
pub static ref SYSTEMD_DATETIME_REGEX: Regex =
|
||||
Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$")
|
||||
.unwrap();
|
||||
Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$").unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user