public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH datacenter-manager] ui: pbs wizard: strip http(s):// prefix on remote creation
@ 2025-10-14  7:11 Dominik Csapak
  2025-10-14  8:55 ` Christian Ebner
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2025-10-14  7:11 UTC (permalink / raw)
  To: pdm-devel

by reusing our 'normalize_hostname' helper. Move that to the remote
module, make it (crate) public, and use it for the case when we don't
have a nodes list (which is only pbs at the moment).

This strips the 'http(s)://' prefix when submitting the remote to the
backend, and preventing the 'invalid uri character' error there.

Reported in the forum:
https://forum.proxmox.com/threads/cant-add-proxmox-backup-server-node.173560/

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/remotes/config.rs              |  4 +++-
 ui/src/remotes/mod.rs                 | 15 +++++++++++++++
 ui/src/remotes/wizard_page_connect.rs | 16 ++--------------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/ui/src/remotes/config.rs b/ui/src/remotes/config.rs
index c8c7815d..6e9ae490 100644
--- a/ui/src/remotes/config.rs
+++ b/ui/src/remotes/config.rs
@@ -7,6 +7,7 @@ use anyhow::Error;
 use proxmox_schema::property_string::PropertyString;
 
 use crate::remotes::edit_remote::EditRemote;
+use crate::remotes::normalize_hostname;
 //use pwt::widget::form::{Field, FormContext, InputType};
 
 use pdm_api_types::remotes::Remote;
@@ -50,8 +51,9 @@ async fn delete_item(key: Key) -> Result<(), Error> {
 
 pub async fn create_remote(mut data: Value, remote_type: RemoteType) -> Result<(), Error> {
     if data.get("nodes").is_none() {
+        let hostname = data["hostname"].as_str().unwrap_or_default().to_string();
         let nodes = vec![PropertyString::new(NodeUrl {
-            hostname: data["hostname"].as_str().unwrap_or_default().to_string(),
+            hostname: normalize_hostname(hostname),
             fingerprint: data["fingerprint"].as_str().map(|fp| fp.to_string()),
         })];
         data["nodes"] = serde_json::to_value(nodes)?;
diff --git a/ui/src/remotes/mod.rs b/ui/src/remotes/mod.rs
index 83b3331b..fa091753 100644
--- a/ui/src/remotes/mod.rs
+++ b/ui/src/remotes/mod.rs
@@ -57,3 +57,18 @@ pub fn system_configuration() -> Html {
 
     NavigationContainer::new().with_child(panel).into()
 }
+
+/// normalize hostname for use in config
+pub(crate) fn normalize_hostname(hostname: String) -> String {
+    let mut result = hostname;
+    if let Some(hostname) = result.strip_prefix("http://") {
+        result = hostname.to_string();
+    }
+    if let Some(hostname) = result.strip_prefix("https://") {
+        result = hostname.to_string();
+    }
+    if let Some(hostname) = result.strip_suffix("/") {
+        result = hostname.to_string();
+    }
+    result
+}
diff --git a/ui/src/remotes/wizard_page_connect.rs b/ui/src/remotes/wizard_page_connect.rs
index bc45df61..9f5ba3ff 100644
--- a/ui/src/remotes/wizard_page_connect.rs
+++ b/ui/src/remotes/wizard_page_connect.rs
@@ -18,6 +18,8 @@ use pdm_api_types::remotes::{RemoteType, TlsProbeOutcome};
 use pdm_api_types::CERT_FINGERPRINT_SHA256_SCHEMA;
 use proxmox_acme_api::CertificateInfo;
 
+use crate::remotes::normalize_hostname;
+
 #[derive(Clone, PartialEq, Properties)]
 #[builder]
 pub struct WizardPageConnect {
@@ -278,20 +280,6 @@ fn call_on_connect_change(props: &WizardPageConnect, certificate_info: Option<Ce
     }
 }
 
-fn normalize_hostname(hostname: String) -> String {
-    let mut result = hostname;
-    if let Some(hostname) = result.strip_prefix("http://") {
-        result = hostname.to_string();
-    }
-    if let Some(hostname) = result.strip_prefix("https://") {
-        result = hostname.to_string();
-    }
-    if let Some(hostname) = result.strip_suffix("/") {
-        result = hostname.to_string();
-    }
-    result
-}
-
 fn rows() -> Vec<KVGridRow> {
     let render_date = |_name: &str, value: &Value, _record: &Value| -> Html {
         match value.as_i64() {
-- 
2.47.3



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-14  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-14  7:11 [pdm-devel] [PATCH datacenter-manager] ui: pbs wizard: strip http(s):// prefix on remote creation Dominik Csapak
2025-10-14  8:55 ` Christian Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal