src/api2/types.rs: add schema/format for file names

This commit is contained in:
Dietmar Maurer 2019-05-15 07:14:08 +02:00
parent e3dbd41b20
commit 4e93f8c164
2 changed files with 17 additions and 3 deletions

View File

@ -159,7 +159,7 @@ Download the dynamic chunk index from the previous backup.
Simply returns an empty list if this is the first backup.
"###
)
.required("archive-name", StringSchema::new("Backup archive name."))
.required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone())
)
}
@ -167,7 +167,7 @@ pub fn api_method_create_dynamic_index() -> ApiMethod {
ApiMethod::new(
create_dynamic_index,
ObjectSchema::new("Create dynamic chunk index file.")
.required("archive-name", StringSchema::new("Backup archive name."))
.required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone())
)
}

View File

@ -7,6 +7,17 @@ use crate::tools::{self, common_regex};
lazy_static!{
// File names: may not contain slashes, may not start with "."
pub static ref FILENAME_FORMAT: Arc<ApiStringFormat> = Arc::new(ApiStringFormat::VerifyFn(|name| {
if name.starts_with('.') {
bail!("file names may not start with '.'");
}
if name.contains('/') {
bail!("file names may not contain slashes");
}
Ok(())
})).into();
pub static ref IP_FORMAT: Arc<ApiStringFormat> = ApiStringFormat::Pattern(&common_regex::IP_REGEX).into();
pub static ref PVE_CONFIG_DIGEST_FORMAT: Arc<ApiStringFormat> =
@ -23,7 +34,7 @@ lazy_static!{
if node == "localhost" || node == tools::nodename() {
Ok(())
} else {
Err(format_err!("no such node '{}'", node))
bail!("no such node '{}'", node);
}
}))
)
@ -45,5 +56,8 @@ lazy_static!{
StringSchema::new("Third name server IP address.")
.format(IP_FORMAT.clone()).into();
pub static ref BACKUP_ARCHIVE_NAME_SCHEMA: Arc<Schema> =
StringSchema::new("Backup archive name.")
.format(FILENAME_FORMAT.clone()).into();
}