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 31C2A1FF17A for ; Tue, 11 Nov 2025 11:50:55 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CC100650C; Tue, 11 Nov 2025 11:51:40 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Tue, 11 Nov 2025 11:50:52 +0100 Message-ID: <20251111105059.148997-2-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251111105059.148997-1-l.wagner@proxmox.com> References: <20251111105059.148997-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762858243148 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Subject: [pdm-devel] [PATCH datacenter-manager 1/8] pdm-api-types: move RemoteUpid to its own module 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" lib.rs re-exports all public member of the new remote_upid module, so for callers this change is non-breaking. Signed-off-by: Lukas Wagner --- lib/pdm-api-types/src/lib.rs | 91 ++------------------------- lib/pdm-api-types/src/remote_upid.rs | 93 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 87 deletions(-) create mode 100644 lib/pdm-api-types/src/remote_upid.rs diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs index ee4dfb2b..ad52372e 100644 --- a/lib/pdm-api-types/src/lib.rs +++ b/lib/pdm-api-types/src/lib.rs @@ -1,13 +1,11 @@ //! Basic API types used by most of the PDM code. use std::collections::HashMap; -use std::fmt; -use anyhow::{bail, Error}; use const_format::concatcp; use serde::{Deserialize, Serialize}; -use proxmox_schema::api_types::{DNS_NAME_STR, IPRE_BRACKET_STR, PORT_REGEX_STR, SAFE_ID_REGEX}; +use proxmox_schema::api_types::{DNS_NAME_STR, IPRE_BRACKET_STR, PORT_REGEX_STR}; use proxmox_schema::{ api, const_regex, ApiStringFormat, ApiType, ArraySchema, IntegerSchema, ReturnType, Schema, StringSchema, Updater, @@ -23,6 +21,9 @@ pub use node_config::*; mod metric_collection; pub use metric_collection::*; +mod remote_upid; +pub use remote_upid::*; + mod proxy; pub use proxy::HTTP_PROXY_SCHEMA; @@ -410,90 +411,6 @@ impl ConfigurationState { serde_plain::derive_display_from_serialize!(ConfigurationState); serde_plain::derive_fromstr_from_deserialize!(ConfigurationState); -pub const REMOTE_UPID_SCHEMA: Schema = StringSchema::new("A remote UPID") - .min_length("C!UPID:N:12345678:12345678:12345678:::".len()) - .schema(); - -#[derive(Clone, Debug, Eq, PartialEq, Hash)] -pub struct RemoteUpid { - remote: String, - /// This is usually a pve upid, but may also be a pbs upid, they have distinct formats. - pub upid: String, -} - -impl RemoteUpid { - pub fn remote(&self) -> &str { - &self.remote - } - - pub fn into_remote(self) -> String { - self.remote - } -} - -impl ApiType for RemoteUpid { - const API_SCHEMA: Schema = REMOTE_UPID_SCHEMA; -} - -impl TryFrom<(String, String)> for RemoteUpid { - type Error = Error; - - fn try_from((remote, upid): (String, String)) -> Result { - if !SAFE_ID_REGEX.is_match(&remote) { - bail!("bad remote id in remote upid"); - } - Ok(Self { remote, upid }) - } -} - -impl TryFrom<(String, &str)> for RemoteUpid { - type Error = Error; - - fn try_from((remote, upid): (String, &str)) -> Result { - if !SAFE_ID_REGEX.is_match(&remote) { - bail!("bad remote id in remote upid"); - } - Ok(Self { - remote, - upid: upid.to_string(), - }) - } -} - -impl TryFrom<(&str, &str)> for RemoteUpid { - type Error = Error; - - fn try_from((remote, upid): (&str, &str)) -> Result { - if !SAFE_ID_REGEX.is_match(remote) { - bail!("bad remote id in remote upid"); - } - Ok(Self { - remote: remote.to_string(), - upid: upid.to_string(), - }) - } -} - -impl std::str::FromStr for RemoteUpid { - type Err = Error; - - fn from_str(s: &str) -> Result { - match s.find('!') { - None => bail!("missing '!' separator in remote upid"), - Some(pos) => (&s[..pos], &s[(pos + 1)..]).try_into(), - } - } -} - -impl fmt::Display for RemoteUpid { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}!{}", self.remote, self.upid) - } -} - -serde_plain::derive_deserialize_from_fromstr!(RemoteUpid, "valid remote upid"); -serde_plain::derive_serialize_from_display!(RemoteUpid); - fn limit_default() -> u64 { 50 } diff --git a/lib/pdm-api-types/src/remote_upid.rs b/lib/pdm-api-types/src/remote_upid.rs new file mode 100644 index 00000000..bf7c1797 --- /dev/null +++ b/lib/pdm-api-types/src/remote_upid.rs @@ -0,0 +1,93 @@ +use std::fmt; + +use anyhow::{bail, Error}; + +use proxmox_schema::api_types::SAFE_ID_REGEX; +use proxmox_schema::{ApiType, Schema, StringSchema}; + +pub const REMOTE_UPID_SCHEMA: Schema = StringSchema::new("A remote UPID") + .min_length("C!UPID:N:12345678:12345678:12345678:::".len()) + .schema(); + +#[derive(Clone, Debug, Eq, PartialEq, Hash)] +pub struct RemoteUpid { + remote: String, + /// This is usually a pve upid, but may also be a pbs upid, they have distinct formats. + pub upid: String, +} + +impl RemoteUpid { + pub fn remote(&self) -> &str { + &self.remote + } + + pub fn into_remote(self) -> String { + self.remote + } +} + +impl ApiType for RemoteUpid { + const API_SCHEMA: Schema = REMOTE_UPID_SCHEMA; +} + +impl TryFrom<(String, String)> for RemoteUpid { + type Error = Error; + + fn try_from((remote, upid): (String, String)) -> Result { + if !SAFE_ID_REGEX.is_match(&remote) { + bail!("bad remote id in remote upid"); + } + + Ok(Self { remote, upid }) + } +} + +impl TryFrom<(String, &str)> for RemoteUpid { + type Error = Error; + + fn try_from((remote, upid): (String, &str)) -> Result { + if !SAFE_ID_REGEX.is_match(&remote) { + bail!("bad remote id in remote upid"); + } + + Ok(Self { + remote, + upid: upid.to_string(), + }) + } +} + +impl TryFrom<(&str, &str)> for RemoteUpid { + type Error = Error; + + fn try_from((remote, upid): (&str, &str)) -> Result { + if !SAFE_ID_REGEX.is_match(remote) { + bail!("bad remote id in remote upid"); + } + + Ok(Self { + remote: remote.to_string(), + upid: upid.to_string(), + }) + } +} + +impl std::str::FromStr for RemoteUpid { + type Err = Error; + + fn from_str(s: &str) -> Result { + match s.find('!') { + None => bail!("missing '!' separator in remote upid"), + Some(pos) => (&s[..pos], &s[(pos + 1)..]).try_into(), + } + } +} + +impl fmt::Display for RemoteUpid { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}!{}", self.remote, self.upid) + } +} + +serde_plain::derive_deserialize_from_fromstr!(RemoteUpid, "valid remote upid"); +serde_plain::derive_serialize_from_display!(RemoteUpid); -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel