tree-wide: rename 'backup-ns' API parameters to 'ns'

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-05-13 13:04:05 +02:00 committed by Thomas Lamprecht
parent f07e660153
commit bc21ade293
10 changed files with 111 additions and 115 deletions

View File

@ -60,7 +60,7 @@ impl BackupReader {
}); });
if !ns.is_root() { if !ns.is_root() {
param["backup-ns"] = serde_json::to_value(ns)?; param["ns"] = serde_json::to_value(ns)?;
} }
let req = HttpClient::request_builder( let req = HttpClient::request_builder(

View File

@ -101,7 +101,7 @@ impl BackupWriter {
}); });
if !ns.is_root() { if !ns.is_root() {
param["backup-ns"] = serde_json::to_value(ns)?; param["ns"] = serde_json::to_value(ns)?;
} }
let req = HttpClient::request_builder( let req = HttpClient::request_builder(

View File

@ -301,7 +301,7 @@ pub async fn complete_server_file_name_do(param: &HashMap<String, String>) -> Ve
}; };
let query = json_object_to_query(json!({ let query = json_object_to_query(json!({
"backup-ns": ns, "ns": ns,
"backup-type": snapshot.group.ty, "backup-type": snapshot.group.ty,
"backup-id": snapshot.group.id, "backup-id": snapshot.group.id,
"backup-time": snapshot.time, "backup-time": snapshot.time,

View File

@ -141,7 +141,7 @@ async fn api_datastore_list_snapshots(
None => json!({}), None => json!({}),
}; };
if !ns.is_root() { if !ns.is_root() {
args["backup-ns"] = serde_json::to_value(ns)?; args["ns"] = serde_json::to_value(ns)?;
} }
let mut result = client.get(&path, Some(args)).await?; let mut result = client.get(&path, Some(args)).await?;
@ -284,7 +284,7 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
&path, &path,
match backup_ns.is_root() { match backup_ns.is_root() {
true => None, true => None,
false => Some(json!({ "backup-ns": backup_ns })), false => Some(json!({ "ns": backup_ns })),
}, },
) )
.await?; .await?;

View File

@ -23,7 +23,7 @@ use crate::{
fn snapshot_args(ns: &BackupNamespace, snapshot: &BackupDir) -> Result<Value, Error> { fn snapshot_args(ns: &BackupNamespace, snapshot: &BackupDir) -> Result<Value, Error> {
let mut args = serde_json::to_value(snapshot)?; let mut args = serde_json::to_value(snapshot)?;
if !ns.is_root() { if !ns.is_root() {
args["backup-ns"] = serde_json::to_value(ns)?; args["ns"] = serde_json::to_value(ns)?;
} }
Ok(args) Ok(args)
} }

View File

@ -190,7 +190,7 @@ fn get_all_snapshot_files(
store: { store: {
schema: DATASTORE_SCHEMA, schema: DATASTORE_SCHEMA,
}, },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -206,15 +206,15 @@ fn get_all_snapshot_files(
/// List backup groups. /// List backup groups.
pub fn list_groups( pub fn list_groups(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<GroupListItem>, Error> { ) -> Result<Vec<GroupListItem>, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let list_all = !check_ns_privs( let list_all = !check_ns_privs(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -223,10 +223,10 @@ pub fn list_groups(
let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?; let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?;
datastore datastore
.iter_backup_groups(backup_ns.clone())? // FIXME: Namespaces and recursion parameters! .iter_backup_groups(ns.clone())? // FIXME: Namespaces and recursion parameters!
.try_fold(Vec::new(), |mut group_info, group| { .try_fold(Vec::new(), |mut group_info, group| {
let group = group?; let group = group?;
let owner = match datastore.get_owner(&backup_ns, group.as_ref()) { let owner = match datastore.get_owner(&ns, group.as_ref()) {
Ok(auth_id) => auth_id, Ok(auth_id) => auth_id,
Err(err) => { Err(err) => {
let id = &store; let id = &store;
@ -259,7 +259,7 @@ pub fn list_groups(
}) })
.to_owned(); .to_owned();
let note_path = get_group_note_path(&datastore, &backup_ns, group.as_ref()); let note_path = get_group_note_path(&datastore, &ns, group.as_ref());
let comment = file_read_firstline(&note_path).ok(); let comment = file_read_firstline(&note_path).ok();
group_info.push(GroupListItem { group_info.push(GroupListItem {
@ -279,7 +279,7 @@ pub fn list_groups(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -298,18 +298,18 @@ pub fn list_groups(
/// Delete backup group including all snapshots. /// Delete backup group including all snapshots.
pub fn delete_group( pub fn delete_group(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
group: pbs_api_types::BackupGroup, group: pbs_api_types::BackupGroup,
_info: &ApiMethod, _info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_PRUNE, PRIV_DATASTORE_PRUNE,
@ -317,7 +317,7 @@ pub fn delete_group(
&group, &group,
)?; )?;
if !datastore.remove_backup_group(&backup_ns, &group)? { if !datastore.remove_backup_group(&ns, &group)? {
bail!("group only partially deleted due to protected snapshots"); bail!("group only partially deleted due to protected snapshots");
} }
@ -328,7 +328,7 @@ pub fn delete_group(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -348,18 +348,18 @@ pub fn delete_group(
/// List snapshot files. /// List snapshot files.
pub fn list_snapshot_files( pub fn list_snapshot_files(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
_info: &ApiMethod, _info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<BackupContent>, Error> { ) -> Result<Vec<BackupContent>, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT | PRIV_DATASTORE_READ, PRIV_DATASTORE_AUDIT | PRIV_DATASTORE_READ,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -367,7 +367,7 @@ pub fn list_snapshot_files(
&backup_dir.group, &backup_dir.group,
)?; )?;
let snapshot = datastore.backup_dir(backup_ns, backup_dir)?; let snapshot = datastore.backup_dir(ns, backup_dir)?;
let info = BackupInfo::new(snapshot)?; let info = BackupInfo::new(snapshot)?;
@ -380,7 +380,7 @@ pub fn list_snapshot_files(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -399,17 +399,17 @@ pub fn list_snapshot_files(
/// Delete backup snapshot. /// Delete backup snapshot.
pub fn delete_snapshot( pub fn delete_snapshot(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
_info: &ApiMethod, _info: &ApiMethod,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_PRUNE, PRIV_DATASTORE_PRUNE,
@ -417,7 +417,7 @@ pub fn delete_snapshot(
&backup_dir.group, &backup_dir.group,
)?; )?;
let snapshot = datastore.backup_dir(backup_ns, backup_dir)?; let snapshot = datastore.backup_dir(ns, backup_dir)?;
snapshot.destroy(false)?; snapshot.destroy(false)?;
@ -429,7 +429,7 @@ pub fn delete_snapshot(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -453,7 +453,7 @@ pub fn delete_snapshot(
/// List backup snapshots. /// List backup snapshots.
pub fn list_snapshots( pub fn list_snapshots(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_type: Option<BackupType>, backup_type: Option<BackupType>,
backup_id: Option<String>, backup_id: Option<String>,
_param: Value, _param: Value,
@ -462,11 +462,11 @@ pub fn list_snapshots(
) -> Result<Vec<SnapshotListItem>, Error> { ) -> Result<Vec<SnapshotListItem>, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let list_all = !check_ns_privs( let list_all = !check_ns_privs(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -478,20 +478,20 @@ pub fn list_snapshots(
// backup group and provide an error free (Err -> None) accessor // backup group and provide an error free (Err -> None) accessor
let groups = match (backup_type, backup_id) { let groups = match (backup_type, backup_id) {
(Some(backup_type), Some(backup_id)) => { (Some(backup_type), Some(backup_id)) => {
vec![datastore.backup_group_from_parts(backup_ns, backup_type, backup_id)] vec![datastore.backup_group_from_parts(ns, backup_type, backup_id)]
} }
// FIXME: Recursion // FIXME: Recursion
(Some(backup_type), None) => datastore (Some(backup_type), None) => datastore
.iter_backup_groups_ok(backup_ns)? .iter_backup_groups_ok(ns)?
.filter(|group| group.backup_type() == backup_type) .filter(|group| group.backup_type() == backup_type)
.collect(), .collect(),
// FIXME: Recursion // FIXME: Recursion
(None, Some(backup_id)) => datastore (None, Some(backup_id)) => datastore
.iter_backup_groups_ok(backup_ns)? .iter_backup_groups_ok(ns)?
.filter(|group| group.backup_id() == backup_id) .filter(|group| group.backup_id() == backup_id)
.collect(), .collect(),
// FIXME: Recursion // FIXME: Recursion
(None, None) => datastore.list_backup_groups(backup_ns)?, (None, None) => datastore.list_backup_groups(ns)?,
}; };
let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| { let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| {
@ -701,7 +701,7 @@ pub fn status(
store: { store: {
schema: DATASTORE_SCHEMA, schema: DATASTORE_SCHEMA,
}, },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -746,7 +746,7 @@ pub fn status(
/// or all backups in the datastore. /// or all backups in the datastore.
pub fn verify( pub fn verify(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_type: Option<BackupType>, backup_type: Option<BackupType>,
backup_id: Option<String>, backup_id: Option<String>,
backup_time: Option<i64>, backup_time: Option<i64>,
@ -756,10 +756,10 @@ pub fn verify(
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let owner_check_required = check_ns_privs( let owner_check_required = check_ns_privs(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_VERIFY, PRIV_DATASTORE_VERIFY,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -779,17 +779,13 @@ pub fn verify(
worker_id = format!( worker_id = format!(
"{}:{}/{}/{}/{:08X}", "{}:{}/{}/{}/{:08X}",
store, store,
backup_ns.display_as_path(), ns.display_as_path(),
backup_type, backup_type,
backup_id, backup_id,
backup_time backup_time
); );
let dir = datastore.backup_dir_from_parts( let dir =
backup_ns.clone(), datastore.backup_dir_from_parts(ns.clone(), backup_type, backup_id, backup_time)?;
backup_type,
backup_id,
backup_time,
)?;
if owner_check_required { if owner_check_required {
let owner = datastore.get_owner(dir.backup_ns(), dir.as_ref())?; let owner = datastore.get_owner(dir.backup_ns(), dir.as_ref())?;
@ -803,25 +799,25 @@ pub fn verify(
worker_id = format!( worker_id = format!(
"{}:{}/{}/{}", "{}:{}/{}/{}",
store, store,
backup_ns.display_as_path(), ns.display_as_path(),
backup_type, backup_type,
backup_id backup_id
); );
let group = pbs_api_types::BackupGroup::from((backup_type, backup_id)); let group = pbs_api_types::BackupGroup::from((backup_type, backup_id));
if owner_check_required { if owner_check_required {
let owner = datastore.get_owner(&backup_ns, &group)?; let owner = datastore.get_owner(&ns, &group)?;
check_backup_owner(&owner, &auth_id)?; check_backup_owner(&owner, &auth_id)?;
} }
backup_group = Some(datastore.backup_group(backup_ns.clone(), group)); backup_group = Some(datastore.backup_group(ns.clone(), group));
worker_type = "verify_group"; worker_type = "verify_group";
} }
(None, None, None) => { (None, None, None) => {
worker_id = if backup_ns.is_root() { worker_id = if ns.is_root() {
store.clone() store.clone()
} else { } else {
format!("{store}:{}", backup_ns.display_as_path()) format!("{store}:{}", ns.display_as_path())
}; };
} }
_ => bail!("parameters do not specify a backup group or snapshot"), _ => bail!("parameters do not specify a backup group or snapshot"),
@ -866,7 +862,7 @@ pub fn verify(
verify_all_backups( verify_all_backups(
&verify_worker, &verify_worker,
worker.upid(), worker.upid(),
backup_ns, ns,
max_depth, max_depth,
owner, owner,
Some(&move |manifest| verify_filter(ignore_verified, outdated_after, manifest)), Some(&move |manifest| verify_filter(ignore_verified, outdated_after, manifest)),
@ -889,7 +885,7 @@ pub fn verify(
#[api( #[api(
input: { input: {
properties: { properties: {
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -921,7 +917,7 @@ pub fn verify(
)] )]
/// Prune a group on the datastore /// Prune a group on the datastore
pub fn prune( pub fn prune(
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
group: pbs_api_types::BackupGroup, group: pbs_api_types::BackupGroup,
dry_run: bool, dry_run: bool,
prune_options: PruneOptions, prune_options: PruneOptions,
@ -930,10 +926,10 @@ pub fn prune(
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_PRUNE, PRIV_DATASTORE_PRUNE,
@ -941,7 +937,7 @@ pub fn prune(
&group, &group,
)?; )?;
let group = datastore.backup_group(backup_ns, group); let group = datastore.backup_group(ns, group);
let worker_id = format!("{}:{}", store, group); let worker_id = format!("{}:{}", store, group);
@ -966,9 +962,9 @@ pub fn prune(
"keep": keep, "keep": keep,
"protected": mark.protected(), "protected": mark.protected(),
}); });
let ns = info.backup_dir.backup_ns(); let prune_ns = info.backup_dir.backup_ns();
if !ns.is_root() { if !prune_ns.is_root() {
result["backup-ns"] = serde_json::to_value(ns)?; result["ns"] = serde_json::to_value(prune_ns)?;
} }
prune_result.push(result); prune_result.push(result);
} }
@ -1244,7 +1240,7 @@ pub const API_METHOD_DOWNLOAD_FILE: ApiMethod = ApiMethod::new(
"Download single raw file from backup snapshot.", "Download single raw file from backup snapshot.",
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -1325,7 +1321,7 @@ pub const API_METHOD_DOWNLOAD_FILE_DECODED: ApiMethod = ApiMethod::new(
"Download single decoded file from backup snapshot. Only works if it's not encrypted.", "Download single decoded file from backup snapshot. Only works if it's not encrypted.",
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -1456,7 +1452,7 @@ pub const API_METHOD_UPLOAD_BACKUP_LOG: ApiMethod = ApiMethod::new(
"Upload the client backup log file into a backup snapshot ('client.log.blob').", "Upload the client backup log file into a backup snapshot ('client.log.blob').",
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -1526,7 +1522,7 @@ pub fn upload_backup_log(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -1549,16 +1545,16 @@ pub fn upload_backup_log(
/// Get the entries of the given path of the catalog /// Get the entries of the given path of the catalog
pub fn catalog( pub fn catalog(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
filepath: String, filepath: String,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<ArchiveEntry>, Error> { ) -> Result<Vec<ArchiveEntry>, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_READ, PRIV_DATASTORE_READ,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1566,7 +1562,7 @@ pub fn catalog(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
let file_name = CATALOG_NAME; let file_name = CATALOG_NAME;
@ -1608,7 +1604,7 @@ pub const API_METHOD_PXAR_FILE_DOWNLOAD: ApiMethod = ApiMethod::new(
"Download single file from pxar file of a backup snapshot. Only works if it's not encrypted.", "Download single file from pxar file of a backup snapshot. Only works if it's not encrypted.",
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -1634,11 +1630,11 @@ pub fn pxar_file_download(
async move { async move {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let store = required_string_param(&param, "store")?; let store = required_string_param(&param, "store")?;
let backup_ns = optional_ns_param(&param)?; let ns = optional_ns_param(&param)?;
let backup_dir: pbs_api_types::BackupDir = Deserialize::deserialize(&param)?; let backup_dir: pbs_api_types::BackupDir = Deserialize::deserialize(&param)?;
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_READ, PRIV_DATASTORE_READ,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1646,7 +1642,7 @@ pub fn pxar_file_download(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
let filepath = required_string_param(&param, "filepath")?.to_owned(); let filepath = required_string_param(&param, "filepath")?.to_owned();
@ -1817,7 +1813,7 @@ pub fn get_active_operations(store: String, _param: Value) -> Result<Value, Erro
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -1836,15 +1832,15 @@ pub fn get_active_operations(store: String, _param: Value) -> Result<Value, Erro
/// Get "notes" for a backup group /// Get "notes" for a backup group
pub fn get_group_notes( pub fn get_group_notes(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_group: pbs_api_types::BackupGroup, backup_group: pbs_api_types::BackupGroup,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> { ) -> Result<String, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1852,7 +1848,7 @@ pub fn get_group_notes(
&backup_group, &backup_group,
)?; )?;
let note_path = get_group_note_path(&datastore, &backup_ns, &backup_group); let note_path = get_group_note_path(&datastore, &ns, &backup_group);
Ok(file_read_optional_string(note_path)?.unwrap_or_else(|| "".to_owned())) Ok(file_read_optional_string(note_path)?.unwrap_or_else(|| "".to_owned()))
} }
@ -1860,7 +1856,7 @@ pub fn get_group_notes(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -1882,16 +1878,16 @@ pub fn get_group_notes(
/// Set "notes" for a backup group /// Set "notes" for a backup group
pub fn set_group_notes( pub fn set_group_notes(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_group: pbs_api_types::BackupGroup, backup_group: pbs_api_types::BackupGroup,
notes: String, notes: String,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1899,7 +1895,7 @@ pub fn set_group_notes(
&backup_group, &backup_group,
)?; )?;
let note_path = get_group_note_path(&datastore, &backup_ns, &backup_group); let note_path = get_group_note_path(&datastore, &ns, &backup_group);
replace_file(note_path, notes.as_bytes(), CreateOptions::new(), false)?; replace_file(note_path, notes.as_bytes(), CreateOptions::new(), false)?;
Ok(()) Ok(())
@ -1909,7 +1905,7 @@ pub fn set_group_notes(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -1928,15 +1924,15 @@ pub fn set_group_notes(
/// Get "notes" for a specific backup /// Get "notes" for a specific backup
pub fn get_notes( pub fn get_notes(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> { ) -> Result<String, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1944,7 +1940,7 @@ pub fn get_notes(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
let (manifest, _) = backup_dir.load_manifest()?; let (manifest, _) = backup_dir.load_manifest()?;
@ -1957,7 +1953,7 @@ pub fn get_notes(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -1979,16 +1975,16 @@ pub fn get_notes(
/// Set "notes" for a specific backup /// Set "notes" for a specific backup
pub fn set_notes( pub fn set_notes(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
notes: String, notes: String,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -1996,7 +1992,7 @@ pub fn set_notes(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
backup_dir backup_dir
.update_manifest(|manifest| { .update_manifest(|manifest| {
@ -2011,7 +2007,7 @@ pub fn set_notes(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -2030,15 +2026,15 @@ pub fn set_notes(
/// Query protection for a specific backup /// Query protection for a specific backup
pub fn get_protection( pub fn get_protection(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -2046,7 +2042,7 @@ pub fn get_protection(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
Ok(backup_dir.is_protected()) Ok(backup_dir.is_protected())
} }
@ -2055,7 +2051,7 @@ pub fn get_protection(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -2077,16 +2073,16 @@ pub fn get_protection(
/// En- or disable protection for a specific backup /// En- or disable protection for a specific backup
pub fn set_protection( pub fn set_protection(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_dir: pbs_api_types::BackupDir, backup_dir: pbs_api_types::BackupDir,
protected: bool, protected: bool,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let datastore = check_privs_and_load_store( let datastore = check_privs_and_load_store(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -2094,7 +2090,7 @@ pub fn set_protection(
&backup_dir.group, &backup_dir.group,
)?; )?;
let backup_dir = datastore.backup_dir(backup_ns, backup_dir)?; let backup_dir = datastore.backup_dir(ns, backup_dir)?;
datastore.update_protection(&backup_dir, protected) datastore.update_protection(&backup_dir, protected)
} }
@ -2103,7 +2099,7 @@ pub fn set_protection(
input: { input: {
properties: { properties: {
store: { schema: DATASTORE_SCHEMA }, store: { schema: DATASTORE_SCHEMA },
"backup-ns": { ns: {
type: BackupNamespace, type: BackupNamespace,
optional: true, optional: true,
}, },
@ -2125,16 +2121,16 @@ pub fn set_protection(
/// Change owner of a backup group /// Change owner of a backup group
pub fn set_backup_owner( pub fn set_backup_owner(
store: String, store: String,
backup_ns: Option<BackupNamespace>, ns: Option<BackupNamespace>,
backup_group: pbs_api_types::BackupGroup, backup_group: pbs_api_types::BackupGroup,
new_owner: Authid, new_owner: Authid,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let backup_ns = backup_ns.unwrap_or_default(); let ns = ns.unwrap_or_default();
let owner_check_required = check_ns_privs( let owner_check_required = check_ns_privs(
&store, &store,
&backup_ns, &ns,
&auth_id, &auth_id,
PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_MODIFY,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_BACKUP,
@ -2142,7 +2138,7 @@ pub fn set_backup_owner(
let datastore = DataStore::lookup_datastore(&store, Some(Operation::Write))?; let datastore = DataStore::lookup_datastore(&store, Some(Operation::Write))?;
let backup_group = datastore.backup_group(backup_ns, backup_group); let backup_group = datastore.backup_group(ns, backup_group);
if owner_check_required { if owner_check_required {
let owner = backup_group.get_owner()?; let owner = backup_group.get_owner()?;

View File

@ -44,7 +44,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."), concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."),
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),
@ -59,10 +59,10 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
); );
pub(crate) fn optional_ns_param(param: &Value) -> Result<BackupNamespace, Error> { pub(crate) fn optional_ns_param(param: &Value) -> Result<BackupNamespace, Error> {
match param.get("backup-ns") { match param.get("ns") {
Some(Value::String(ns)) => ns.parse(), Some(Value::String(ns)) => ns.parse(),
None => Ok(BackupNamespace::root()), None => Ok(BackupNamespace::root()),
_ => bail!("invalid backup-ns parameter"), _ => bail!("invalid ns parameter"),
} }
} }

View File

@ -482,7 +482,7 @@ pub async fn scan_remote_groups(
let client = remote_client(&remote, None).await.map_err(map_remote_err)?; let client = remote_client(&remote, None).await.map_err(map_remote_err)?;
let args = if let Some(ns) = namespace { let args = if let Some(ns) = namespace {
Some(json!({ "backup-ns": ns })) Some(json!({ "ns": ns }))
} else { } else {
None None
}; };

View File

@ -48,7 +48,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
), ),
&sorted!([ &sorted!([
("store", false, &DATASTORE_SCHEMA), ("store", false, &DATASTORE_SCHEMA),
("backup-ns", true, &BACKUP_NAMESPACE_SCHEMA), ("ns", true, &BACKUP_NAMESPACE_SCHEMA),
("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA),
("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA),
("backup-time", false, &BACKUP_TIME_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA),

View File

@ -624,7 +624,7 @@ async fn pull_group(
}); });
if !remote_ns.is_root() { if !remote_ns.is_root() {
args["backup-ns"] = serde_json::to_value(&remote_ns)?; args["ns"] = serde_json::to_value(&remote_ns)?;
} }
let target_ns = remote_ns.map_prefix(&params.remote_ns, &params.ns)?; let target_ns = remote_ns.map_prefix(&params.remote_ns, &params.ns)?;
@ -1055,7 +1055,7 @@ pub async fn pull_ns(
let args = if !source_ns.is_root() { let args = if !source_ns.is_root() {
Some(json!({ Some(json!({
"backup-ns": source_ns, "ns": source_ns,
})) }))
} else { } else {
None None