[PATCH installer v3 34/38] fetch-answer: switch to types from proxmox-installer-types

Christoph Heiss
2026-04-03T16:57:50Z

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
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<Self> {
- 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<String> {
- 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