]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/types.rs: define SINGLE_LINE_COMMENT_SCHEMA
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 13 Jan 2020 11:02:13 +0000 (12:02 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 13 Jan 2020 11:02:13 +0000 (12:02 +0100)
src/api2/config/datastore.rs
src/api2/config/remotes.rs
src/api2/types.rs
src/config/datastore.rs
src/config/remotes.rs

index 82c2266d9e9bad655d4447f1dfb9f5ca2574aaf7..adc9cf1c012c123e91f7b466d032053f0d3113fb 100644 (file)
@@ -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()?;
index d0f185f5a7ee0a9d43e82001539b4ff725d65b82..8c6dae874dc1c38647a204f8b6526eba3a52d934 100644 (file)
@@ -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,
index 3a3365e77315476cc0db86eafd02f073c1709754..54b7a8f1463d91aaf667166d6d96c9d32f157f91 100644 (file)
@@ -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
index e27f81db861040bc61622f1259e9bb90c4556814..ded6ca82420af98a68fbcc82aabef8c0849fe35b 100644 (file)
@@ -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,
index 30ff257a67e4769dca0ccc522577732ebb6b9fa4..f4705c23068fcaf1eaa743c18c676d38c64037d0 100644 (file)
@@ -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,