From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 1C58F1FF13E for ; Fri, 03 Apr 2026 18:57:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CAEA09463; Fri, 3 Apr 2026 18:58:20 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH installer v3 34/38] fetch-answer: switch to types from proxmox-installer-types Date: Fri, 3 Apr 2026 18:54:06 +0200 Message-ID: <20260403165437.2166551-35-c.heiss@proxmox.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403165437.2166551-1-c.heiss@proxmox.com> References: <20260403165437.2166551-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775235401444 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.068 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 Message-ID-Hash: OWPXHL72PQV3VDG3IDXTC4IBHAJ6NK2F X-Message-ID-Hash: OWPXHL72PQV3VDG3IDXTC4IBHAJ6NK2F X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: No functional changes. Signed-off-by: Christoph Heiss --- Changes v2 -> v3: * new patch proxmox-fetch-answer/Cargo.toml | 1 - .../src/fetch_plugins/http.rs | 72 ++----------------- 2 files changed, 7 insertions(+), 66 deletions(-) diff --git a/proxmox-fetch-answer/Cargo.toml b/proxmox-fetch-answer/Cargo.toml index 2d3b149..93c11bb 100644 --- a/proxmox-fetch-answer/Cargo.toml +++ b/proxmox-fetch-answer/Cargo.toml @@ -16,6 +16,5 @@ log.workspace = true proxmox-auto-installer.workspace = true proxmox-installer-common = { workspace = true, features = ["http"] } proxmox-installer-types.workspace = true -serde = { workspace = true, features = ["derive"] } serde_json.workspace = true toml.workspace = true diff --git a/proxmox-fetch-answer/src/fetch_plugins/http.rs b/proxmox-fetch-answer/src/fetch_plugins/http.rs index fceabc2..9e5a87a 100644 --- a/proxmox-fetch-answer/src/fetch_plugins/http.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/http.rs @@ -1,14 +1,14 @@ use anyhow::{Result, bail}; use log::info; -use serde::Serialize; use std::{ fs::{self, read_to_string}, process::Command, }; use proxmox_auto_installer::{sysinfo, utils::HttpOptions}; -use proxmox_installer_common::http::{self, header::HeaderMap}; -use proxmox_installer_types::SystemInfo; +use proxmox_installer_common::http::{self, header::HeaderMap, +}; +use proxmox_installer_types::answer::fetch::{AnswerFetchData, AnswerFetchDataSchema}; static ANSWER_URL_SUBDOMAIN: &str = "proxmox-auto-installer"; static ANSWER_CERT_FP_SUBDOMAIN: &str = "proxmox-auto-installer-cert-fingerprint"; @@ -31,67 +31,6 @@ static DHCP_URL_OPTION: &str = "proxmox-auto-installer-manifest-url"; static DHCP_CERT_FP_OPTION: &str = "proxmox-auto-installer-cert-fingerprint"; static DHCP_LEASE_FILE: &str = "/var/lib/dhcp/dhclient.leases"; -/// Metadata of the HTTP POST payload, such as schema version of the document. -#[derive(Serialize)] -#[serde(rename_all = "kebab-case")] -struct HttpFetchInfoSchema { - /// major.minor version describing the schema version of this document, in a semanticy-version - /// way. - /// - /// major: Incremented for incompatible/breaking API changes, e.g. removing an existing - /// field. - /// minor: Incremented when adding functionality in a backwards-compatible matter, e.g. - /// adding a new field. - version: String, -} - -impl HttpFetchInfoSchema { - const SCHEMA_VERSION: &str = "1.0"; -} - -impl Default for HttpFetchInfoSchema { - fn default() -> Self { - Self { - version: Self::SCHEMA_VERSION.to_owned(), - } - } -} - -/// All data sent as request payload with the answerfile fetch POST request. -/// -/// NOTE: The format is versioned through `schema.version` (`$schema.version` in the -/// resulting JSON), ensure you update it when this struct or any of its members gets modified. -#[derive(Serialize)] -#[serde(rename_all = "kebab-case")] -struct HttpFetchPayload { - /// Metadata for the answerfile fetch payload - // This field is prefixed by `$` on purpose, to indicate that it is document metadata and not - // part of the actual content itself. (E.g. JSON Schema uses a similar naming scheme) - #[serde(rename = "$schema")] - schema: HttpFetchInfoSchema, - /// Information about the running system, flattened into this structure directly. - #[serde(flatten)] - sysinfo: SystemInfo, -} - -impl HttpFetchPayload { - /// Retrieves the required information from the system and constructs the - /// full payload including meta data. - fn get() -> Result { - Ok(Self { - schema: HttpFetchInfoSchema::default(), - sysinfo: sysinfo::get()?, - }) - } - - /// Retrieves the required information from the system and constructs the - /// full payload including meta data, serialized as JSON. - pub fn as_json() -> Result { - let info = Self::get()?; - Ok(serde_json::to_string(&info)?) - } -} - pub struct FetchFromHTTP; impl FetchFromHTTP { @@ -129,7 +68,10 @@ impl FetchFromHTTP { } info!("Gathering system information."); - let payload = HttpFetchPayload::as_json()?; + let payload = serde_json::to_string(&AnswerFetchData { + schema: AnswerFetchDataSchema::default(), + sysinfo: sysinfo::get()?, + })?; info!("Sending POST request to '{answer_url}'."); -- 2.53.0