mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-17 19:39:40 +00:00
tree-wide: remove DatastoreWithNamespace
instead move the acl_path helper to BackupNamespace, and introduce a new helper for printing a store+ns when logging/generating error messages. Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
bbfbd9297f
commit
f6a37f40f6
@ -694,6 +694,17 @@ impl BackupNamespace {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn acl_path<'a>(&'a self, store: &'a str) -> Vec<&'a str> {
|
||||||
|
let mut path: Vec<&str> = vec!["datastore", store];
|
||||||
|
|
||||||
|
if self.is_root() {
|
||||||
|
path
|
||||||
|
} else {
|
||||||
|
path.extend(self.inner.iter().map(|comp| comp.as_str()));
|
||||||
|
path
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for BackupNamespace {
|
impl fmt::Display for BackupNamespace {
|
||||||
@ -1026,35 +1037,6 @@ impl fmt::Display for BackupDir {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper struct for places where sensible formatting of store+NS combo is required
|
|
||||||
pub struct DatastoreWithNamespace {
|
|
||||||
pub store: String,
|
|
||||||
pub ns: BackupNamespace,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for DatastoreWithNamespace {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
if self.ns.is_root() {
|
|
||||||
write!(f, "datastore {}, root namespace", self.store)
|
|
||||||
} else {
|
|
||||||
write!(f, "datastore '{}', namespace '{}'", self.store, self.ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DatastoreWithNamespace {
|
|
||||||
pub fn acl_path(&self) -> Vec<&str> {
|
|
||||||
let mut path: Vec<&str> = vec!["datastore", &self.store];
|
|
||||||
|
|
||||||
if self.ns.is_root() {
|
|
||||||
path
|
|
||||||
} else {
|
|
||||||
path.extend(self.ns.inner.iter().map(|comp| comp.as_str()));
|
|
||||||
path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used when both a backup group or a directory can be valid.
|
/// Used when both a backup group or a directory can be valid.
|
||||||
pub enum BackupPart {
|
pub enum BackupPart {
|
||||||
Group(BackupGroup),
|
Group(BackupGroup),
|
||||||
@ -1479,3 +1461,12 @@ pub fn print_ns_and_snapshot(ns: &BackupNamespace, dir: &BackupDir) -> String {
|
|||||||
format!("{}/{}", ns.display_as_path(), dir)
|
format!("{}/{}", ns.display_as_path(), dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prints a Datastore name and [`BackupNamespace`] for logs/errors.
|
||||||
|
pub fn print_store_and_ns(store: &str, ns: &BackupNamespace) -> String {
|
||||||
|
if ns.is_root() {
|
||||||
|
format!("datastore '{}', root namespace", store)
|
||||||
|
} else {
|
||||||
|
format!("datastore '{}', namespace '{}'", store, ns)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
use proxmox_schema::*;
|
use proxmox_schema::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Authid, BackupNamespace, BackupType, DatastoreWithNamespace, RateLimitConfig, Userid,
|
Authid, BackupNamespace, BackupType, RateLimitConfig, Userid, BACKUP_GROUP_SCHEMA,
|
||||||
BACKUP_GROUP_SCHEMA, BACKUP_NAMESPACE_SCHEMA, DATASTORE_SCHEMA, DRIVE_NAME_SCHEMA,
|
BACKUP_NAMESPACE_SCHEMA, DATASTORE_SCHEMA, DRIVE_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA,
|
||||||
MEDIA_POOL_NAME_SCHEMA, NS_MAX_DEPTH_REDUCED_SCHEMA, PROXMOX_SAFE_ID_FORMAT, REMOTE_ID_SCHEMA,
|
NS_MAX_DEPTH_REDUCED_SCHEMA, PROXMOX_SAFE_ID_FORMAT, REMOTE_ID_SCHEMA,
|
||||||
SINGLE_LINE_COMMENT_SCHEMA,
|
SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -224,10 +224,10 @@ pub struct VerificationJobConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VerificationJobConfig {
|
impl VerificationJobConfig {
|
||||||
pub fn store_with_ns(&self) -> DatastoreWithNamespace {
|
pub fn acl_path(&self) -> Vec<&str> {
|
||||||
DatastoreWithNamespace {
|
match self.ns.as_ref() {
|
||||||
store: self.store.clone(),
|
Some(ns) => ns.acl_path(&self.store),
|
||||||
ns: self.ns.clone().unwrap_or_default(),
|
None => vec!["datastore", &self.store],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,10 +508,10 @@ pub struct SyncJobConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SyncJobConfig {
|
impl SyncJobConfig {
|
||||||
pub fn store_with_ns(&self) -> DatastoreWithNamespace {
|
pub fn acl_path(&self) -> Vec<&str> {
|
||||||
DatastoreWithNamespace {
|
match self.ns.as_ref() {
|
||||||
store: self.store.clone(),
|
Some(ns) => ns.acl_path(&self.store),
|
||||||
ns: self.ns.clone().unwrap_or_default(),
|
None => vec!["datastore", &self.store],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user