From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager v4 22/23] ui: pve wizard: connect: use scan api endpoint instead of realms
Date: Fri, 22 Aug 2025 10:32:40 +0200 [thread overview]
Message-ID: <20250822085409.1139639-23-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250822085409.1139639-1-d.csapak@proxmox.com>
Since we don't need to query the realms anymore for the next page, we
can now use the scan api endpoint without credentials to probe the
connection to see if TLS works and if the certificate is trusted and/or
if the fingerprint is correct.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/remotes/wizard_page_connect.rs | 157 ++++++++++++--------------
1 file changed, 73 insertions(+), 84 deletions(-)
diff --git a/ui/src/remotes/wizard_page_connect.rs b/ui/src/remotes/wizard_page_connect.rs
index 6d48264..5122743 100644
--- a/ui/src/remotes/wizard_page_connect.rs
+++ b/ui/src/remotes/wizard_page_connect.rs
@@ -2,22 +2,19 @@ use std::rc::Rc;
use anyhow::{bail, Error};
use serde::{Deserialize, Serialize};
-use serde_json::json;
use yew::html::IntoEventCallback;
use yew::virtual_dom::{Key, VComp, VNode};
use pwt::css::FlexFit;
use pwt::widget::form::{Field, FormContext, FormContextObserver};
use pwt::widget::{error_message, Column, InputPanel, Mask};
-use pwt::{prelude::*, AsyncPool};
+use pwt::{prelude::*, AsyncAbortGuard};
+use pwt_macros::builder;
use proxmox_yew_comp::{SchemaValidation, WizardPageRenderInfo};
-use pdm_api_types::remotes::RemoteType;
+use pdm_api_types::remotes::{RemoteType, TlsProbeOutcome};
use pdm_api_types::CERT_FINGERPRINT_SHA256_SCHEMA;
-use pdm_client::types::ListRealm;
-
-use pwt_macros::builder;
#[derive(Clone, PartialEq, Properties)]
#[builder]
@@ -37,69 +34,46 @@ impl WizardPageConnect {
}
}
-async fn list_realms(
- hostname: String,
- fingerprint: Option<String>,
-) -> Result<Vec<ListRealm>, Error> {
- let mut params = json!({
- "hostname": hostname,
- });
- if let Some(fp) = fingerprint {
- params["fingerprint"] = fp.into();
- }
- let result: Vec<ListRealm> = proxmox_yew_comp::http_get("/pve/realms", Some(params)).await?;
-
- Ok(result)
-}
-
#[derive(PartialEq, Clone, Deserialize, Serialize)]
/// Parameters for connect call.
pub struct ConnectParams {
pub hostname: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub fingerprint: Option<String>,
- #[serde(default)]
- pub realms: Vec<ListRealm>,
}
-async fn connect(form_ctx: FormContext, remote_type: RemoteType) -> Result<ConnectParams, Error> {
- let data = form_ctx.get_submit_data();
- let mut data: ConnectParams = serde_json::from_value(data.clone())?;
- data.hostname = normalize_hostname(data.hostname);
+async fn connect(form_ctx: FormContext, remote_type: RemoteType) -> Result<TlsProbeOutcome, Error> {
+ match remote_type {
+ RemoteType::Pve => {
+ let hostname = normalize_hostname(form_ctx.read().get_field_text("hostname"));
+ let fingerprint = get_fingerprint(&form_ctx);
+ let res = crate::pdm_client()
+ .pve_probe_tls(&hostname, fingerprint.as_deref())
+ .await
+ .map_err(Error::from);
+
+ if let Ok(TlsProbeOutcome::UntrustedCertificate(_)) = &res {
+ bail!("Untrusted Certificate, please enter fingerprint");
+ }
- let realms = match remote_type {
- RemoteType::Pve => list_realms(data.hostname.clone(), data.fingerprint.clone()).await?,
+ res
+ }
RemoteType::Pbs => bail!("not implemented"),
- };
-
- data.realms = realms;
- Ok(data)
+ }
}
pub enum Msg {
FormChange,
Connect,
- ConnectResult(Result<ConnectParams, Error>),
+ ConnectResult(Result<TlsProbeOutcome, Error>),
}
pub struct PdmWizardPageConnect {
- connect_info: Option<ConnectParams>,
_form_observer: FormContextObserver,
- form_valid: bool,
loading: bool,
- last_error: Option<Error>,
- async_pool: AsyncPool,
+ scan_result: Option<Result<TlsProbeOutcome, Error>>,
+ scan_guard: Option<AsyncAbortGuard>,
}
-impl PdmWizardPageConnect {
- fn update_connect_info(&mut self, ctx: &Context<Self>, info: Option<ConnectParams>) {
- let props = ctx.props();
- self.connect_info = info.clone();
- props.info.page_lock(info.is_none());
- if let Some(on_connect_change) = &props.on_connect_change {
- on_connect_change.emit(info);
- }
- }
-}
impl Component for PdmWizardPageConnect {
type Message = Msg;
type Properties = WizardPageConnect;
@@ -122,12 +96,10 @@ impl Component for PdmWizardPageConnect {
});
Self {
- connect_info: None,
_form_observer,
- form_valid: false,
loading: false,
- last_error: None,
- async_pool: AsyncPool::new(),
+ scan_result: None,
+ scan_guard: None,
}
}
@@ -135,49 +107,43 @@ impl Component for PdmWizardPageConnect {
let props = ctx.props();
match msg {
Msg::FormChange => {
- self.form_valid = props.info.form_ctx.read().is_valid();
- match props.remote_type {
- RemoteType::Pve => {
- self.update_connect_info(ctx, None);
- }
- RemoteType::Pbs => {
- return <Self as yew::Component>::update(self, ctx, Msg::Connect)
- }
- }
- props.info.page_lock(!self.form_valid);
+ props.info.page_lock(!props.info.form_ctx.read().is_valid());
+ props.info.reset_remaining_valid_pages();
for page in ["nodes", "info"] {
if let Some(form_ctx) = props.info.lookup_form_context(&Key::from(page)) {
form_ctx.write().reset_form();
}
}
+ self.scan_result = None;
}
Msg::Connect => {
- let link = ctx.link().clone();
- self.update_connect_info(ctx, None);
- let form_ctx = props.info.form_ctx.clone();
self.loading = true;
- self.last_error = None;
+ props.info.page_lock(true);
- let remote_type = props.remote_type;
- self.async_pool.spawn(async move {
- let result = connect(form_ctx, remote_type).await;
- link.send_message(Msg::ConnectResult(result));
- });
+ self.scan_guard = Some(AsyncAbortGuard::spawn({
+ let link = ctx.link().clone();
+ let form_ctx = props.info.form_ctx.clone();
+ let remote_type = props.remote_type;
+
+ async move {
+ let result = connect(form_ctx, remote_type).await;
+ link.send_message(Msg::ConnectResult(result));
+ }
+ }));
}
- Msg::ConnectResult(server_info) => {
+ Msg::ConnectResult(scan_result) => {
self.loading = false;
- match server_info {
- Ok(connect_info) => {
- self.update_connect_info(ctx, Some(connect_info));
+ props.info.page_lock(false);
+ self.scan_result = Some(scan_result);
+ match &self.scan_result {
+ Some(Ok(TlsProbeOutcome::TrustedCertificate)) => {
+ call_on_connect_change(props);
+ self.scan_result = None;
+ props.info.reset_remaining_valid_pages();
+ props.info.go_to_next_page();
}
- Err(err) => {
- self.last_error = Some(err);
- }
- }
-
- props.info.reset_remaining_valid_pages();
- if self.connect_info.is_some() {
- props.info.go_to_next_page();
+ Some(Err(_)) => props.info.page_lock(true),
+ _ => {}
}
}
}
@@ -185,7 +151,10 @@ impl Component for PdmWizardPageConnect {
}
fn view(&self, _ctx: &Context<Self>) -> Html {
- let error = self.last_error.as_ref();
+ let error = match &self.scan_result {
+ Some(Err(err)) => Some(err),
+ _ => None,
+ };
let input_panel = InputPanel::new()
.class(FlexFit)
// FIXME: input panel css style is not optimal here...
@@ -217,6 +186,26 @@ impl Component for PdmWizardPageConnect {
}
}
+fn get_fingerprint(form_ctx: &FormContext) -> Option<String> {
+ let fingerprint = form_ctx.read().get_field_text("fingerprint");
+ let fingerprint = if fingerprint.is_empty() {
+ None
+ } else {
+ Some(fingerprint)
+ };
+ fingerprint
+}
+
+fn call_on_connect_change(props: &WizardPageConnect) {
+ if let Some(on_connect_change) = &props.on_connect_change {
+ let fingerprint = get_fingerprint(&props.info.form_ctx);
+ on_connect_change.emit(Some(ConnectParams {
+ hostname: normalize_hostname(props.info.form_ctx.read().get_field_text("hostname")),
+ fingerprint,
+ }));
+ }
+}
+
fn normalize_hostname(hostname: String) -> String {
let mut result = hostname;
if let Some(hostname) = result.strip_prefix("http://") {
--
2.47.2
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-08-22 8:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 8:32 [pdm-devel] [PATCH datacenter-manager v4 00/23] improve remote wizard Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 01/23] server/ui: pve: change 'realm list' api call to GET Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 02/23] api types: RemoteType: put default port info to the type Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 03/23] server: connection: add probe_tls_connection helper Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 04/23] server: add probe-tls endpoint Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 05/23] server: pve api: extend 'scan' so it tls-probes the nodes Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 06/23] pdm-client: add scan_remote and probe_tls methods Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 07/23] ui: remotes: node url list: add placeholder and clear trigger Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 08/23] ui: remotes: node url list: make column header clearer Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 09/23] ui: remotes: node url list: handle changing default Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 10/23] ui: pve wizard: rename 'realm' variable to 'info' Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 11/23] ui: pve wizard: summary: add default text for fingerprint Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 12/23] ui: pve wizard: nodes: improve info text Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 13/23] ui: pve wizard: nodes: probe hosts to verify fingerprint settings Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 14/23] ui: pve wizard: info: use pdm_client for scanning Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 15/23] ui: pve wizard: info: detect hostname and fingerprint Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 16/23] ui: pve wizard: info: remove manual scan button Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 17/23] ui: widget: add pve realm selector Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 18/23] ui: pve wizard: info: use " Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 19/23] ui: pve wizard: connect: factor out normalize_hostname Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 20/23] ui: pve wizard: connect: move connection logic to next button Dominik Csapak
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 21/23] ui: pve wizard: connect: reset later pages when form changes Dominik Csapak
2025-08-22 8:32 ` Dominik Csapak [this message]
2025-08-22 8:32 ` [pdm-devel] [PATCH datacenter-manager v4 23/23] ui: pve wizard: connect: add certificate confirmation dialog Dominik Csapak
2025-08-22 13:30 ` [pdm-devel] [PATCH datacenter-manager v4 00/23] improve remote wizard Lukas Wagner
2025-08-22 14:07 ` [pdm-devel] applied: " Lukas Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250822085409.1139639-23-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox