From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id C8B951FF190 for ; Fri, 10 Jan 2025 11:22:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 92A2129197; Fri, 10 Jan 2025 11:22:16 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 10 Jan 2025 11:21:38 +0100 Message-Id: <20250110102142.1212874-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110102142.1212874-1-d.csapak@proxmox.com> References: <20250110102142.1212874-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager 1/5] server: add an optional 'web-url' property for remotes X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" this contains two optional values to generate a URL for the UI: * per_node_template: a 'per node' template to generate an url, used for all places where we have node information. If not set we use the base_url as fallback to generate the url. * base_url: An URL for reaching the remote. This is e.g. useful if there is some reverse proxy or similar between the users browser and the remote. If none is set, the UI will still use the configured connections to generate an URL. Signed-off-by: Dominik Csapak --- lib/pdm-api-types/src/remotes.rs | 23 ++++++++++++++++++++++ server/src/api/pve/mod.rs | 2 ++ server/src/api/remotes.rs | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/lib/pdm-api-types/src/remotes.rs b/lib/pdm-api-types/src/remotes.rs index 2a8299b..01ee95a 100644 --- a/lib/pdm-api-types/src/remotes.rs +++ b/lib/pdm-api-types/src/remotes.rs @@ -36,6 +36,20 @@ pub struct NodeUrl { pub fingerprint: Option, } +#[api] +/// Options for the URLs used in the Web UI. +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[serde(rename_all = "kebab-case")] +pub struct WebUrl { + /// A base URL for accessing the remote. + #[serde(skip_serializing_if = "Option::is_none")] + pub base_url: Option, + + /// A template for a per node URL. replaces {{nodename}} with the nodename. + #[serde(skip_serializing_if = "Option::is_none")] + pub per_node_template: Option, +} + #[api] /// The type of a remote entry. #[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize, Ord, PartialOrd)] @@ -61,6 +75,10 @@ serde_plain::derive_fromstr_from_deserialize!(RemoteType); description: "A cluster node IP or hostname.", }, }, + "web-url": { + type: String, + optional: true, + }, }, )] /// The information required to connect to a remote instance. @@ -86,6 +104,11 @@ pub struct Remote { /// The access token's secret. #[updater(serde(skip_serializing_if = "Option::is_none"))] pub token: String, + + /// Configuration for the Web UI URL link generation. + #[updater(serde(skip_serializing_if = "Option::is_none"))] + #[serde(skip_serializing_if = "Option::is_none")] + pub web_url: Option>, } impl ApiSectionDataEntry for Remote { diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs index 0c0ae37..dccfb72 100644 --- a/server/src/api/pve/mod.rs +++ b/server/src/api/pve/mod.rs @@ -1306,6 +1306,7 @@ pub async fn scan_remote_pve( })], authid: authid.clone(), token, + web_url: None, }; let client = connect_or_login(&remote) @@ -1384,6 +1385,7 @@ pub async fn list_realm_remote_pve( })], authid: "root@pam".parse()?, token: String::new(), + web_url: None, }; let client = connection::make_pve_client(&remote)?; diff --git a/server/src/api/remotes.rs b/server/src/api/remotes.rs index d4412d0..e434e9b 100644 --- a/server/src/api/remotes.rs +++ b/server/src/api/remotes.rs @@ -3,6 +3,7 @@ use std::error::Error as _; use anyhow::{bail, format_err, Error}; +use serde::{Deserialize, Serialize}; use proxmox_access_control::CachedUserInfo; use proxmox_router::{ @@ -178,6 +179,15 @@ pub async fn add_remote(mut entry: Remote, create_token: Option) -> Resu Ok(()) } +#[api()] +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Deletable property name +pub enum DeletableProperty { + /// Delete the web-url property. + WebUrl, +} + // FIXME: Support `OneOf` in schema so we can use a derived Updater for all product types? // Otherwise we need to have a custom updater struct that covers all product remotes. #[api( @@ -188,6 +198,14 @@ pub async fn add_remote(mut entry: Remote, create_token: Option) -> Resu flatten: true, type: RemoteUpdater, }, + delete: { + description: "List of properties to delete.", + type: Array, + optional: true, + items: { + type: DeletableProperty, + } + }, digest: { optional: true, type: ConfigDigest, @@ -202,6 +220,7 @@ pub async fn add_remote(mut entry: Remote, create_token: Option) -> Resu pub fn update_remote( id: String, updater: RemoteUpdater, + delete: Option>, digest: Option, ) -> Result<(), Error> { let (mut remotes, config_digest) = pdm_config::remotes::config()?; @@ -211,6 +230,16 @@ pub fn update_remote( .get_mut(&id) .ok_or_else(|| http_err!(NOT_FOUND, "no such remote {id:?}"))?; + if let Some(delete) = delete { + for delete_prop in delete { + match delete_prop { + DeletableProperty::WebUrl => { + entry.web_url = None; + } + } + } + } + if let Some(v) = updater.nodes { entry.nodes = v; } @@ -221,6 +250,10 @@ pub fn update_remote( entry.token = v; } + if updater.web_url.is_some() { + entry.web_url = updater.web_url; + } + pdm_config::remotes::save_config(&remotes)?; Ok(()) -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel