2021-07-07 07:24:39 +00:00
|
|
|
//! Basic API types used by most of the PBS code.
|
|
|
|
|
2021-07-07 12:37:47 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use proxmox::api::api;
|
2021-07-07 07:04:09 +00:00
|
|
|
use proxmox::api::schema::{ApiStringFormat, Schema, StringSchema};
|
|
|
|
use proxmox::const_regex;
|
|
|
|
|
2021-07-07 09:28:53 +00:00
|
|
|
#[rustfmt::skip]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! PROXMOX_SAFE_ID_REGEX_STR { () => { r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)" }; }
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9_][A-Za-z0-9._\-]*") }
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") }
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
#[macro_export]
|
|
|
|
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") }
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! SNAPSHOT_PATH_REGEX_STR {
|
|
|
|
() => (
|
|
|
|
concat!(r"(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), ")/(", BACKUP_TIME_RE!(), r")")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-07 07:53:48 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod userid;
|
|
|
|
pub use userid::Authid;
|
|
|
|
pub use userid::Userid;
|
|
|
|
pub use userid::{Realm, RealmRef};
|
|
|
|
pub use userid::{Tokenname, TokennameRef};
|
|
|
|
pub use userid::{Username, UsernameRef};
|
|
|
|
pub use userid::{PROXMOX_GROUP_ID_SCHEMA, PROXMOX_TOKEN_ID_SCHEMA, PROXMOX_TOKEN_NAME_SCHEMA};
|
|
|
|
|
2021-07-07 11:47:17 +00:00
|
|
|
pub mod upid;
|
2021-07-07 12:37:47 +00:00
|
|
|
pub use upid::UPID;
|
2021-07-07 11:47:17 +00:00
|
|
|
|
2021-07-07 07:04:09 +00:00
|
|
|
const_regex! {
|
2021-07-07 09:28:53 +00:00
|
|
|
pub BACKUP_TYPE_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), r")$");
|
|
|
|
|
|
|
|
pub BACKUP_ID_REGEX = concat!(r"^", BACKUP_ID_RE!(), r"$");
|
|
|
|
|
|
|
|
pub BACKUP_DATE_REGEX = concat!(r"^", BACKUP_TIME_RE!() ,r"$");
|
|
|
|
|
|
|
|
pub GROUP_PATH_REGEX = concat!(r"^(", BACKUP_TYPE_RE!(), ")/(", BACKUP_ID_RE!(), r")$");
|
|
|
|
|
|
|
|
pub BACKUP_FILE_REGEX = r"^.*\.([fd]idx|blob)$";
|
|
|
|
|
|
|
|
pub SNAPSHOT_PATH_REGEX = concat!(r"^", SNAPSHOT_PATH_REGEX_STR!(), r"$");
|
|
|
|
|
2021-07-07 07:04:09 +00:00
|
|
|
pub FINGERPRINT_SHA256_REGEX = r"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
|
2021-07-07 07:49:35 +00:00
|
|
|
|
|
|
|
/// Regex for safe identifiers.
|
|
|
|
///
|
|
|
|
/// This
|
|
|
|
/// [article](https://dwheeler.com/essays/fixing-unix-linux-filenames.html)
|
|
|
|
/// contains further information why it is reasonable to restict
|
|
|
|
/// names this way. This is not only useful for filenames, but for
|
|
|
|
/// any identifier command line tools work with.
|
|
|
|
pub PROXMOX_SAFE_ID_REGEX = concat!(r"^", PROXMOX_SAFE_ID_REGEX_STR!(), r"$");
|
|
|
|
|
|
|
|
pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$";
|
2021-07-07 07:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub const FINGERPRINT_SHA256_FORMAT: ApiStringFormat =
|
|
|
|
ApiStringFormat::Pattern(&FINGERPRINT_SHA256_REGEX);
|
|
|
|
|
|
|
|
pub const CERT_FINGERPRINT_SHA256_SCHEMA: Schema =
|
|
|
|
StringSchema::new("X509 certificate fingerprint (sha256).")
|
|
|
|
.format(&FINGERPRINT_SHA256_FORMAT)
|
|
|
|
.schema();
|
2021-07-07 07:49:35 +00:00
|
|
|
|
|
|
|
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 SINGLE_LINE_COMMENT_SCHEMA: Schema = StringSchema::new("Comment (single line).")
|
|
|
|
.format(&SINGLE_LINE_COMMENT_FORMAT)
|
|
|
|
.schema();
|
2021-07-07 09:28:53 +00:00
|
|
|
|
|
|
|
pub const BACKUP_ID_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&BACKUP_ID_REGEX);
|
2021-07-07 12:37:47 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
properties: {
|
|
|
|
"upid": {
|
|
|
|
optional: true,
|
|
|
|
type: UPID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
/// Garbage collection status.
|
|
|
|
pub struct GarbageCollectionStatus {
|
|
|
|
pub upid: Option<String>,
|
|
|
|
/// Number of processed index files.
|
|
|
|
pub index_file_count: usize,
|
|
|
|
/// Sum of bytes referred by index files.
|
|
|
|
pub index_data_bytes: u64,
|
|
|
|
/// Bytes used on disk.
|
|
|
|
pub disk_bytes: u64,
|
|
|
|
/// Chunks used on disk.
|
|
|
|
pub disk_chunks: usize,
|
|
|
|
/// Sum of removed bytes.
|
|
|
|
pub removed_bytes: u64,
|
|
|
|
/// Number of removed chunks.
|
|
|
|
pub removed_chunks: usize,
|
|
|
|
/// Sum of pending bytes (pending removal - kept for safety).
|
|
|
|
pub pending_bytes: u64,
|
|
|
|
/// Number of pending chunks (pending removal - kept for safety).
|
|
|
|
pub pending_chunks: usize,
|
|
|
|
/// Number of chunks marked as .bad by verify that have been removed by GC.
|
|
|
|
pub removed_bad: usize,
|
|
|
|
/// Number of chunks still marked as .bad after garbage collection.
|
|
|
|
pub still_bad: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for GarbageCollectionStatus {
|
|
|
|
fn default() -> Self {
|
|
|
|
GarbageCollectionStatus {
|
|
|
|
upid: None,
|
|
|
|
index_file_count: 0,
|
|
|
|
index_data_bytes: 0,
|
|
|
|
disk_bytes: 0,
|
|
|
|
disk_chunks: 0,
|
|
|
|
removed_bytes: 0,
|
|
|
|
removed_chunks: 0,
|
|
|
|
pending_bytes: 0,
|
|
|
|
pending_chunks: 0,
|
|
|
|
removed_bad: 0,
|
|
|
|
still_bad: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|