From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9BC9EAF9C for ; Tue, 8 Aug 2023 14:14:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7D9669744 for ; Tue, 8 Aug 2023 14:13:52 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 8 Aug 2023 14:13:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A0BED437CC for ; Tue, 8 Aug 2023 14:13:51 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 8 Aug 2023 14:13:41 +0200 Message-Id: <20230808121344.199500-4-h.laimer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808121344.199500-1-h.laimer@proxmox.com> References: <20230808121344.199500-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.017 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-backup-manager.rs] Subject: [pbs-devel] [PATCH proxmox-backup v3 3/6] manager: add completion for opt. Remote in SyncJob X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Aug 2023 12:14:22 -0000 Signed-off-by: Hannes Laimer --- src/bin/proxmox-backup-manager.rs | 67 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index b4cb6cb3..eadfe547 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -535,35 +535,33 @@ fn get_remote(param: &HashMap) -> Option { param.get("remote").map(|r| r.to_owned()).or_else(|| { if let Some(id) = param.get("id") { if let Ok(job) = get_sync_job(id) { - return Some(job.remote); + return job.remote; } } None }) } -fn get_remote_store(param: &HashMap) -> Option<(String, String)> { +fn get_remote_store(param: &HashMap) -> Option<(Option, String)> { let mut job: Option = None; let remote = param.get("remote").map(|r| r.to_owned()).or_else(|| { if let Some(id) = param.get("id") { job = get_sync_job(id).ok(); if let Some(ref job) = job { - return Some(job.remote.clone()); + return job.remote.clone(); } } None }); - if let Some(remote) = remote { - let store = param - .get("remote-store") - .map(|r| r.to_owned()) - .or_else(|| job.map(|job| job.remote_store)); + let store = param + .get("remote-store") + .map(|r| r.to_owned()) + .or_else(|| job.map(|job| job.remote_store)); - if let Some(store) = store { - return Some((remote, store)); - } + if let Some(store) = store { + return Some((remote, store)); } None @@ -584,7 +582,7 @@ fn get_remote_ns(param: &HashMap) -> Option { } // shell completion helper -pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap) -> Vec { +pub fn complete_remote_datastore_name(arg: &str, param: &HashMap) -> Vec { let mut list = Vec::new(); if let Some(remote) = get_remote(param) { @@ -595,7 +593,9 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap Vec { let mut list = Vec::new(); - if let Some((remote, remote_store)) = get_remote_store(param) { - if let Ok(data) = proxmox_async::runtime::block_on(async move { + if let Some(data) = match get_remote_store(param) { + Some((Some(remote), remote_store)) => proxmox_async::runtime::block_on(async move { crate::api2::config::remote::scan_remote_namespaces( remote.clone(), remote_store.clone(), ) .await - }) { - for item in data { - list.push(item.ns.name()); - } + .ok() + }), + Some((None, source_store)) => { + let mut rpcenv = CliEnvironment::new(); + rpcenv.set_auth_id(Some(String::from("root@pam"))); + crate::api2::admin::namespace::list_namespaces(source_store, None, None, &mut rpcenv) + .ok() + } + _ => None, + } { + for item in data { + list.push(item.ns.name()); } } @@ -662,19 +670,26 @@ pub fn complete_sync_local_datastore_namespace( pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap) -> Vec { let mut list = Vec::new(); - if let Some((remote, remote_store)) = get_remote_store(param) { - let ns = get_remote_ns(param); - if let Ok(data) = proxmox_async::runtime::block_on(async move { + let ns = get_remote_ns(param); + if let Some(data) = match get_remote_store(param) { + Some((Some(remote), remote_store)) => proxmox_async::runtime::block_on(async move { crate::api2::config::remote::scan_remote_groups( remote.clone(), remote_store.clone(), ns, ) .await - }) { - for item in data { - list.push(format!("{}/{}", item.backup.ty, item.backup.id)); - } + .ok() + }), + Some((None, source_store)) => { + let mut rpcenv = CliEnvironment::new(); + rpcenv.set_auth_id(Some(String::from("root@pam"))); + crate::api2::admin::datastore::list_groups(source_store, ns, &mut rpcenv).ok() + } + _ => None, + } { + for item in data { + list.push(format!("{}/{}", item.backup.ty, item.backup.id)); } } -- 2.39.2