From 7957fabff20a76abebd7ed53e5a7e781fac68474 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 8 Jul 2020 14:59:15 +0200 Subject: [PATCH] api: add ZPOOL_NAME_SCHEMA and regex poolnames can containe spaces and some other special characters Signed-off-by: Dominik Csapak --- src/api2/node/disks/zfs.rs | 5 ++++- src/api2/types.rs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index 3184a76d..be2a1630 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -41,6 +41,9 @@ pub const ZFS_ASHIFT_SCHEMA: Schema = IntegerSchema::new( .default(12) .schema(); +pub const ZPOOL_NAME_SCHEMA: Schema =StringSchema::new("ZFS Pool Name") + .format(&ApiStringFormat::Pattern(&ZPOOL_NAME_REGEX)) + .schema(); #[api( default: "On", @@ -157,7 +160,7 @@ pub fn list_zpools() -> Result, Error> { schema: NODE_SCHEMA, }, name: { - schema: DATASTORE_SCHEMA, + schema: ZPOOL_NAME_SCHEMA, }, }, }, diff --git a/src/api2/types.rs b/src/api2/types.rs index 7b902702..0d0fab3b 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -78,6 +78,8 @@ const_regex!{ pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$"); pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$"; + + pub ZPOOL_NAME_REGEX = r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$"; } pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat =