config: add UUID validation

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-06-06 03:42:15 +05:30
parent f343ff783b
commit f0dff60d74
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80
2 changed files with 9 additions and 2 deletions

View File

@ -8,3 +8,4 @@ edition = "2018"
[dependencies]
ureq = "1.1.1"
uuid = { version = "0.8.1", default-features = false, features = [ "v1" ] }

View File

@ -1,9 +1,15 @@
use uuid::Uuid;
pub struct HealthcheckConfig {
pub uuid: String,
}
pub fn create_config(uuid: &str) -> HealthcheckConfig {
HealthcheckConfig {
uuid: uuid.to_string(),
if let Ok(_) = Uuid::parse_str(uuid) {
HealthcheckConfig {
uuid: uuid.to_string(),
}
} else {
panic!("Invalid UUID: {}", uuid)
}
}