Skip to content

Commit

Permalink
do some todos (#501)
Browse files Browse the repository at this point in the history
Co-authored-by: Malte Janduda <malte.janduda@sap.com>
  • Loading branch information
dmah42 and MalteJ authored Feb 14, 2024
1 parent 6256012 commit 46d90dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions auraed/src/cells/cell_service/cells/cgroups/cpuset/cpus.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use fancy_regex::Regex;

use lazy_static::lazy_static;
use std::{
fmt::{Display, Formatter},
ops::Deref,
};

use validation::{ValidatedField, ValidationError};

lazy_static! {
// input should be a comma seperated list of numbers with optional -s
// or the empty string.
static ref CPUS_INPUT_REGEX: Regex = {
Regex::new(r"^(\d(-\d)?,?)*$").expect("regex construction")
};
}

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Cpus(String);

Expand All @@ -29,12 +36,12 @@ impl ValidatedField<String> for Cpus {
) -> Result<Self, ValidationError> {
let input = validation::required(input, field_name, parent_name)?;

// TODO: maybe lazy_static this
// input should be a comma seperated list of numbers with optional -s
// or the empty string.
let pattern: Regex =
Regex::new(r"^(\d(-\d)?,?)*$").expect("regex construction");
validation::allow_regex(&input, &pattern, field_name, parent_name)?;
validation::allow_regex(
&input,
&CPUS_INPUT_REGEX,
field_name,
parent_name,
)?;

Ok(Self(input))
}
Expand Down
23 changes: 15 additions & 8 deletions auraed/src/cells/cell_service/cells/cgroups/cpuset/mems.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use fancy_regex::Regex;

use lazy_static::lazy_static;
use std::{
fmt::{Display, Formatter},
ops::Deref,
};

use validation::{ValidatedField, ValidationError};

lazy_static! {
// input should be a comma seperated list of numbers with optional -s
// or the empty string.
static ref MEMS_INPUT_REGEX: Regex = {
Regex::new(r"^(\d(-\d)?,?)*$").expect("regex construction")
};
}

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Mems(String);

Expand All @@ -29,12 +36,12 @@ impl ValidatedField<String> for Mems {
) -> Result<Self, ValidationError> {
let input = validation::required(input, field_name, parent_name)?;

// TODO: maybe lazy_static this
// input should be a comma seperated list of numbers with optional -s
// or the empty string.
let pattern: Regex =
Regex::new(r"^(\d(-\d)?,?)*$").expect("regex construction");
validation::allow_regex(&input, &pattern, field_name, parent_name)?;
validation::allow_regex(
&input,
&MEMS_INPUT_REGEX,
field_name,
parent_name,
)?;

Ok(Self(input))
}
Expand Down

0 comments on commit 46d90dd

Please sign in to comment.