From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 7D1DE1FF15C
	for <inbox@lore.proxmox.com>; Wed, 18 Sep 2024 17:27:56 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 8EEBC82CE;
	Wed, 18 Sep 2024 17:27:35 +0200 (CEST)
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Wed, 18 Sep 2024 17:27:13 +0200
Message-Id: <20240918152716.511337-2-c.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20240918152716.511337-1-c.ebner@proxmox.com>
References: <20240918152716.511337-1-c.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.022 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. [pathpatterns.rs, lib.rs]
Subject: [pbs-devel] [PATCH v5 proxmox-backup 1/4] api-types: implement
 dedicated api type for match patterns
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

Introduces a dedicated api type `PathPattern` and the corresponding
format and input validation schema. Further, add a `PathPatterns`
type for collections of path patterns and implement required traits
to be able to replace currently defined api parameters.

In preparation for using this common api type for all api endpoints
exposing a match pattern parameter.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 4:
- no changes

 pbs-api-types/src/lib.rs          |  3 ++
 pbs-api-types/src/pathpatterns.rs | 55 +++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 pbs-api-types/src/pathpatterns.rs

diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs
index 635292a54..26e66afea 100644
--- a/pbs-api-types/src/lib.rs
+++ b/pbs-api-types/src/lib.rs
@@ -143,6 +143,9 @@ pub use ad::*;
 mod remote;
 pub use remote::*;
 
+mod pathpatterns;
+pub use pathpatterns::*;
+
 mod tape;
 pub use tape::*;
 
diff --git a/pbs-api-types/src/pathpatterns.rs b/pbs-api-types/src/pathpatterns.rs
new file mode 100644
index 000000000..c40926a44
--- /dev/null
+++ b/pbs-api-types/src/pathpatterns.rs
@@ -0,0 +1,55 @@
+use proxmox_schema::{const_regex, ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema};
+
+use serde::{Deserialize, Serialize};
+
+const_regex! {
+     pub PATH_PATTERN_REGEX = concat!(r"^.+[^\\]$");
+}
+
+pub const PATH_PATTERN_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&PATH_PATTERN_REGEX);
+
+pub const PATH_PATTERN_SCHEMA: Schema =
+    StringSchema::new("Path or match pattern for matching filenames.")
+        .format(&PATH_PATTERN_FORMAT)
+        .schema();
+
+pub const PATH_PATTERN_LIST_SCHEMA: Schema = ArraySchema::new(
+    "List of paths or match patterns for matching filenames.",
+    &PATH_PATTERN_SCHEMA,
+)
+.schema();
+
+#[derive(Default, Deserialize, Serialize)]
+/// Path or path pattern for filename matching
+pub struct PathPattern {
+    pattern: String,
+}
+
+impl ApiType for PathPattern {
+    const API_SCHEMA: Schema = PATH_PATTERN_SCHEMA;
+}
+
+impl AsRef<[u8]> for PathPattern {
+    fn as_ref(&self) -> &[u8] {
+        self.pattern.as_bytes()
+    }
+}
+
+#[derive(Default, Deserialize, Serialize)]
+/// Array of paths and/or path patterns for filename matching
+pub struct PathPatterns {
+    patterns: Vec<PathPattern>,
+}
+
+impl ApiType for PathPatterns {
+    const API_SCHEMA: Schema = PATH_PATTERN_LIST_SCHEMA;
+}
+
+impl IntoIterator for PathPatterns {
+    type Item = PathPattern;
+    type IntoIter = std::vec::IntoIter<PathPattern>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.patterns.into_iter()
+    }
+}
-- 
2.39.2



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