From 926d2531269964f8a4fab4f453728ac8fd2e10df Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 30 Oct 2020 12:56:35 +0100 Subject: [PATCH] api: define subscription key schema and use it nicer to have the correct regex checked in parameter verification already Signed-off-by: Thomas Lamprecht --- src/api2/node/subscription.rs | 6 ++---- src/api2/types/mod.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/api2/node/subscription.rs b/src/api2/node/subscription.rs index 3ce7ce98..309d0960 100644 --- a/src/api2/node/subscription.rs +++ b/src/api2/node/subscription.rs @@ -7,7 +7,7 @@ use crate::tools; use crate::tools::subscription::{self, SubscriptionStatus, SubscriptionInfo}; use crate::config::acl::{PRIV_SYS_AUDIT,PRIV_SYS_MODIFY}; use crate::config::cached_user_info::CachedUserInfo; -use crate::api2::types::{NODE_SCHEMA, Authid}; +use crate::api2::types::{NODE_SCHEMA, SUBSCRIPTION_KEY_SCHEMA, Authid}; #[api( input: { @@ -124,9 +124,7 @@ fn get_subscription( schema: NODE_SCHEMA, }, key: { - description: "Proxmox Backup Server subscription key", - type: String, - max_length: 32, + schema: SUBSCRIPTION_KEY_SCHEMA, }, }, }, diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index bfa46382..f67d48ed 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -73,6 +73,8 @@ const_regex!{ pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$"); + pub SUBSCRIPTION_KEY_REGEX = concat!(r"^pbs(?:[cbsp])-[0-9a-f]{10}$"); + 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\-_.:]+$"; @@ -129,6 +131,9 @@ pub const CIDR_V6_FORMAT: ApiStringFormat = pub const CIDR_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&CIDR_REGEX); +pub const SUBSCRIPTION_KEY_FORMAT: ApiStringFormat = + ApiStringFormat::Pattern(&SUBSCRIPTION_KEY_REGEX); + pub const BLOCKDEVICE_NAME_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&BLOCKDEVICE_NAME_REGEX); @@ -348,6 +353,12 @@ pub const DNS_NAME_OR_IP_SCHEMA: Schema = StringSchema::new("DNS name or IP addr .format(&DNS_NAME_OR_IP_FORMAT) .schema(); +pub const SUBSCRIPTION_KEY_SCHEMA: Schema = StringSchema::new("Proxmox Backup Server subscription key.") + .format(&SUBSCRIPTION_KEY_FORMAT) + .min_length(15) + .max_length(16) + .schema(); + pub const BLOCKDEVICE_NAME_SCHEMA: Schema = StringSchema::new("Block device name (/sys/block/).") .format(&BLOCKDEVICE_NAME_FORMAT) .min_length(3)