Skip to content

Commit a11790c

Browse files
add validation for env
1 parent 038df7c commit a11790c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ pub struct Options {
373373
long,
374374
env = "P_OTEL_ATTRIBUTES_ALLOWED_LIMIT",
375375
default_value = "200",
376+
value_parser = validation::validate_otel_attributes_allowed_limit,
376377
help = "allowed limit for otel attributes"
377378
)]
378379
pub otel_attributes_allowed_limit: usize,

src/option.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,19 @@ pub mod validation {
173173
Err("Invalid value for max disk usage. It should be given as 90.0 for 90%".to_string())
174174
}
175175
}
176+
177+
pub fn validate_otel_attributes_allowed_limit(s: &str) -> Result<usize, String> {
178+
if let Ok(size) = s.parse::<usize>() {
179+
if (1..=200).contains(&size) {
180+
Ok(size)
181+
} else {
182+
Err(format!(
183+
"Invalid value for size. It should be between 1 and {}",
184+
200
185+
))
186+
}
187+
} else {
188+
Err("Invalid value for size. It should be given as integer value".to_string())
189+
}
190+
}
176191
}

0 commit comments

Comments
 (0)