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 02C9B69F47 for ; Wed, 15 Sep 2021 15:42:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 00FB919BD3 for ; Wed, 15 Sep 2021 15:42:25 +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 id 4B47619BC7 for ; Wed, 15 Sep 2021 15:42:24 +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 1A0D5448A7 for ; Wed, 15 Sep 2021 15:42:24 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Wed, 15 Sep 2021 15:41:54 +0200 Message-Id: <20210915134157.19762-8-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210915134157.19762-1-f.gruenbichler@proxmox.com> References: <20210915134157.19762-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.382 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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. [remote.rs] Subject: [pve-devel] [PATCH v2 proxmox-backup 07/10] remote: add backup group scanning X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Sep 2021 13:42:25 -0000 Signed-off-by: Fabian Grünbichler --- Notes: used for bash completion (next patch) and potentially GUI (future work). could also be integrated into the 'remote' CLI/GUI.. src/api2/config/remote.rs | 73 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index acf7cfcf..ceca8109 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -3,13 +3,14 @@ use serde_json::Value; use ::serde::{Deserialize, Serialize}; use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::http_err; +use proxmox::api::router::SubdirMap; +use proxmox::{http_err, list_subdirs_api_method, sortable}; use pbs_client::{HttpClient, HttpClientOptions}; use pbs_api_types::{ REMOTE_ID_SCHEMA, REMOTE_PASSWORD_SCHEMA, Remote, RemoteConfig, RemoteConfigUpdater, - Authid, PROXMOX_CONFIG_DIGEST_SCHEMA, DataStoreListItem, SyncJobConfig, - PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY, + Authid, PROXMOX_CONFIG_DIGEST_SCHEMA, DATASTORE_SCHEMA, GroupListItem, + DataStoreListItem, SyncJobConfig, PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY, }; use pbs_config::sync; @@ -340,8 +341,72 @@ pub async fn scan_remote_datastores(name: String) -> Result Result, Error> { + let (remote_config, _digest) = pbs_config::remote::config()?; + let remote: Remote = remote_config.lookup("remote", &name)?; + + let map_remote_err = |api_err| { + http_err!(INTERNAL_SERVER_ERROR, + "failed to scan remote '{}' - {}", + &name, + api_err) + }; + + let client = remote_client(remote) + .await + .map_err(map_remote_err)?; + let api_res = client + .get(&format!("api2/json/admin/datastore/{}/groups", store), None) + .await + .map_err(map_remote_err)?; + let parse_res = match api_res.get("data") { + Some(data) => serde_json::from_value::>(data.to_owned()), + None => bail!("remote {} did not return any group list data", &name), + }; + + match parse_res { + Ok(parsed) => Ok(parsed), + Err(_) => bail!("Failed to parse remote scan api result."), + } +} + +#[sortable] +const DATASTORE_SCAN_SUBDIRS: SubdirMap = &[ + ( + "groups", + &Router::new() + .get(&API_METHOD_SCAN_REMOTE_GROUPS) + ), +]; + +const DATASTORE_SCAN_ROUTER: Router = Router::new() + .get(&list_subdirs_api_method!(DATASTORE_SCAN_SUBDIRS)) + .subdirs(DATASTORE_SCAN_SUBDIRS); + const SCAN_ROUTER: Router = Router::new() - .get(&API_METHOD_SCAN_REMOTE_DATASTORES); + .get(&API_METHOD_SCAN_REMOTE_DATASTORES) + .match_all("store", &DATASTORE_SCAN_ROUTER); const ITEM_ROUTER: Router = Router::new() .get(&API_METHOD_READ_REMOTE) -- 2.30.2