From 454c13edce2f07f82c0faa94a899798de0bb3c52 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 13 Jan 2020 12:02:13 +0100 Subject: [PATCH] src/api2/types.rs: define SINGLE_LINE_COMMENT_SCHEMA --- src/api2/config/datastore.rs | 8 +------- src/api2/config/remotes.rs | 2 +- src/api2/types.rs | 9 +++++++++ src/config/datastore.rs | 3 +-- src/config/remotes.rs | 3 +-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 82c2266d..adc9cf1c 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -42,7 +42,7 @@ pub fn list_datastores( }, comment: { optional: true, - schema: datastore::COMMENT_SCHEMA, + schema: SINGLE_LINE_COMMENT_SCHEMA, }, path: { schema: datastore::DIR_NAME_SCHEMA, @@ -63,12 +63,6 @@ pub fn create_datastore(name: String, param: Value) -> Result<(), Error> { bail!("datastore '{}' already exists.", name); } - if let Some(ref comment) = datastore.comment { - if comment.find(|c: char| c.is_control()).is_some() { - bail!("comment must not contain control characters!"); - } - } - let path: PathBuf = datastore.path.clone().into(); let backup_user = crate::backup::backup_user()?; diff --git a/src/api2/config/remotes.rs b/src/api2/config/remotes.rs index d0f185f5..8c6dae87 100644 --- a/src/api2/config/remotes.rs +++ b/src/api2/config/remotes.rs @@ -39,7 +39,7 @@ pub fn list_remotes( }, comment: { optional: true, - schema: remotes::COMMENT_SCHEMA, + schema: SINGLE_LINE_COMMENT_SCHEMA, }, host: { schema: remotes::REMOTE_HOST_SCHEMA, diff --git a/src/api2/types.rs b/src/api2/types.rs index 3a3365e7..54b7a8f1 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -29,6 +29,8 @@ const_regex!{ /// names this way. This is not only useful for filenames, but for /// any identifier command line tools work with. pub PROXMOX_SAFE_ID_REGEX = r"^[A-Za-z0-9_][A-Za-z0-9._\-]*"; + + pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$"; } pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat = @@ -43,6 +45,10 @@ pub const PVE_CONFIG_DIGEST_FORMAT: ApiStringFormat = pub const PROXMOX_SAFE_ID_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX); +pub const SINGLE_LINE_COMMENT_FORMAT: ApiStringFormat = + ApiStringFormat::Pattern(&SINGLE_LINE_COMMENT_REGEX); + + pub const PVE_CONFIG_DIGEST_SCHEMA: Schema = StringSchema::new(r#"\ Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications. @@ -123,6 +129,9 @@ pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.") .max_length(32) .schema(); +pub const SINGLE_LINE_COMMENT_SCHEMA: Schema = StringSchema::new("Comment (single line).") + .format(&SINGLE_LINE_COMMENT_FORMAT) + .schema(); // Complex type definitions diff --git a/src/config/datastore.rs b/src/config/datastore.rs index e27f81db..ded6ca82 100644 --- a/src/config/datastore.rs +++ b/src/config/datastore.rs @@ -16,13 +16,12 @@ lazy_static! { // fixme: define better schemas pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema(); -pub const COMMENT_SCHEMA: Schema = StringSchema::new("Datastore comment").schema(); #[api( properties: { comment: { optional: true, - schema: COMMENT_SCHEMA, + schema: SINGLE_LINE_COMMENT_SCHEMA, }, path: { schema: DIR_NAME_SCHEMA, diff --git a/src/config/remotes.rs b/src/config/remotes.rs index 30ff257a..f4705c23 100644 --- a/src/config/remotes.rs +++ b/src/config/remotes.rs @@ -16,7 +16,6 @@ lazy_static! { // fixme: define better schemas -pub const COMMENT_SCHEMA: Schema = StringSchema::new("Comment").schema(); pub const REMOTE_HOST_SCHEMA: Schema = StringSchema::new("Host IP address or DNS name.").schema(); pub const REMOTE_USERID_SCHEMA: Schema = StringSchema::new("User ID").schema(); pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth token.").schema(); @@ -25,7 +24,7 @@ pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth t properties: { comment: { optional: true, - schema: COMMENT_SCHEMA, + schema: SINGLE_LINE_COMMENT_SCHEMA, }, host: { schema: REMOTE_HOST_SCHEMA,