src/api2/types.rs: define SINGLE_LINE_COMMENT_SCHEMA
This commit is contained in:
parent
167971ed49
commit
454c13edce
|
@ -42,7 +42,7 @@ pub fn list_datastores(
|
||||||
},
|
},
|
||||||
comment: {
|
comment: {
|
||||||
optional: true,
|
optional: true,
|
||||||
schema: datastore::COMMENT_SCHEMA,
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
schema: datastore::DIR_NAME_SCHEMA,
|
schema: datastore::DIR_NAME_SCHEMA,
|
||||||
|
@ -63,12 +63,6 @@ pub fn create_datastore(name: String, param: Value) -> Result<(), Error> {
|
||||||
bail!("datastore '{}' already exists.", name);
|
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 path: PathBuf = datastore.path.clone().into();
|
||||||
|
|
||||||
let backup_user = crate::backup::backup_user()?;
|
let backup_user = crate::backup::backup_user()?;
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn list_remotes(
|
||||||
},
|
},
|
||||||
comment: {
|
comment: {
|
||||||
optional: true,
|
optional: true,
|
||||||
schema: remotes::COMMENT_SCHEMA,
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
},
|
},
|
||||||
host: {
|
host: {
|
||||||
schema: remotes::REMOTE_HOST_SCHEMA,
|
schema: remotes::REMOTE_HOST_SCHEMA,
|
||||||
|
|
|
@ -29,6 +29,8 @@ const_regex!{
|
||||||
/// names this way. This is not only useful for filenames, but for
|
/// names this way. This is not only useful for filenames, but for
|
||||||
/// any identifier command line tools work with.
|
/// any identifier command line tools work with.
|
||||||
pub PROXMOX_SAFE_ID_REGEX = r"^[A-Za-z0-9_][A-Za-z0-9._\-]*";
|
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 =
|
pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat =
|
||||||
|
@ -43,6 +45,10 @@ pub const PVE_CONFIG_DIGEST_FORMAT: ApiStringFormat =
|
||||||
pub const PROXMOX_SAFE_ID_FORMAT: ApiStringFormat =
|
pub const PROXMOX_SAFE_ID_FORMAT: ApiStringFormat =
|
||||||
ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX);
|
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#"\
|
pub const PVE_CONFIG_DIGEST_SCHEMA: Schema = StringSchema::new(r#"\
|
||||||
Prevent changes if current configuration file has different SHA256 digest.
|
Prevent changes if current configuration file has different SHA256 digest.
|
||||||
This can be used to prevent concurrent modifications.
|
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)
|
.max_length(32)
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
|
pub const SINGLE_LINE_COMMENT_SCHEMA: Schema = StringSchema::new("Comment (single line).")
|
||||||
|
.format(&SINGLE_LINE_COMMENT_FORMAT)
|
||||||
|
.schema();
|
||||||
|
|
||||||
|
|
||||||
// Complex type definitions
|
// Complex type definitions
|
||||||
|
|
|
@ -16,13 +16,12 @@ lazy_static! {
|
||||||
// fixme: define better schemas
|
// fixme: define better schemas
|
||||||
|
|
||||||
pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema();
|
pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema();
|
||||||
pub const COMMENT_SCHEMA: Schema = StringSchema::new("Datastore comment").schema();
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
properties: {
|
properties: {
|
||||||
comment: {
|
comment: {
|
||||||
optional: true,
|
optional: true,
|
||||||
schema: COMMENT_SCHEMA,
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
schema: DIR_NAME_SCHEMA,
|
schema: DIR_NAME_SCHEMA,
|
||||||
|
|
|
@ -16,7 +16,6 @@ lazy_static! {
|
||||||
|
|
||||||
// fixme: define better schemas
|
// 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_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_USERID_SCHEMA: Schema = StringSchema::new("User ID").schema();
|
||||||
pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth token.").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: {
|
properties: {
|
||||||
comment: {
|
comment: {
|
||||||
optional: true,
|
optional: true,
|
||||||
schema: COMMENT_SCHEMA,
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
},
|
},
|
||||||
host: {
|
host: {
|
||||||
schema: REMOTE_HOST_SCHEMA,
|
schema: REMOTE_HOST_SCHEMA,
|
||||||
|
|
Loading…
Reference in New Issue