cleanup: use const_regex, use BACKUP_ID_REGEX for api too

This commit is contained in:
Dietmar Maurer 2020-11-03 06:36:50 +01:00
parent e1c1533790
commit 038ee59960
2 changed files with 15 additions and 18 deletions

View File

@ -5,7 +5,7 @@ use proxmox::api::{api, schema::*};
use proxmox::const_regex; use proxmox::const_regex;
use proxmox::{IPRE, IPRE_BRACKET, IPV4RE, IPV6RE, IPV4OCTET, IPV6H16, IPV6LS32}; use proxmox::{IPRE, IPRE_BRACKET, IPV4RE, IPV6RE, IPV4OCTET, IPV6H16, IPV6LS32};
use crate::backup::CryptMode; use crate::backup::{CryptMode, BACKUP_ID_REGEX};
use crate::server::UPID; use crate::server::UPID;
#[macro_use] #[macro_use]
@ -101,6 +101,9 @@ pub const CERT_FINGERPRINT_SHA256_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 BACKUP_ID_FORMAT: ApiStringFormat =
ApiStringFormat::Pattern(&BACKUP_ID_REGEX);
pub const SINGLE_LINE_COMMENT_FORMAT: ApiStringFormat = pub const SINGLE_LINE_COMMENT_FORMAT: ApiStringFormat =
ApiStringFormat::Pattern(&SINGLE_LINE_COMMENT_REGEX); ApiStringFormat::Pattern(&SINGLE_LINE_COMMENT_REGEX);
@ -276,7 +279,7 @@ pub const BACKUP_TYPE_SCHEMA: Schema =
pub const BACKUP_ID_SCHEMA: Schema = pub const BACKUP_ID_SCHEMA: Schema =
StringSchema::new("Backup ID.") StringSchema::new("Backup ID.")
.format(&PROXMOX_SAFE_ID_FORMAT) .format(&BACKUP_ID_FORMAT)
.schema(); .schema();
pub const BACKUP_TIME_SCHEMA: Schema = pub const BACKUP_TIME_SCHEMA: Schema =

View File

@ -1,11 +1,11 @@
use crate::tools; use crate::tools;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use regex::Regex;
use std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use std::path::{PathBuf, Path}; use std::path::{PathBuf, Path};
use lazy_static::lazy_static;
use proxmox::const_regex;
use super::manifest::MANIFEST_BLOB_NAME; use super::manifest::MANIFEST_BLOB_NAME;
@ -13,25 +13,19 @@ macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9_][A-Za-z0-9._\-]*") }
macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") } macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") }
macro_rules! BACKUP_TIME_RE { () => (r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z") } macro_rules! BACKUP_TIME_RE { () => (r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z") }
lazy_static!{ const_regex!{
static ref BACKUP_FILE_REGEX: Regex = Regex::new( BACKUP_FILE_REGEX = r"^.*\.([fd]idx|blob)$";
r"^.*\.([fd]idx|blob)$").unwrap();
static ref BACKUP_TYPE_REGEX: Regex = Regex::new( BACKUP_TYPE_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), r")$");
concat!(r"^(", BACKUP_TYPE_RE!(), r")$")).unwrap();
static ref BACKUP_ID_REGEX: Regex = Regex::new( pub BACKUP_ID_REGEX = concat!(r"^", BACKUP_ID_RE!(), r"$");
concat!(r"^", BACKUP_ID_RE!(), r"$")).unwrap();
static ref BACKUP_DATE_REGEX: Regex = Regex::new( BACKUP_DATE_REGEX = concat!(r"^", BACKUP_TIME_RE!() ,r"$");
concat!(r"^", BACKUP_TIME_RE!() ,r"$")).unwrap();
static ref GROUP_PATH_REGEX: Regex = Regex::new( GROUP_PATH_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), r")$");
concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), r")$")).unwrap();
static ref SNAPSHOT_PATH_REGEX: Regex = Regex::new(
concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), ")/(", BACKUP_TIME_RE!(), r")$")).unwrap();
SNAPSHOT_PATH_REGEX = concat!(
r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), ")/(", BACKUP_TIME_RE!(), r")$");
} }
/// BackupGroup is a directory containing a list of BackupDir /// BackupGroup is a directory containing a list of BackupDir