From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v6 proxmox-backup 1/4] api-types: implement dedicated api type for match patterns
Date: Tue, 12 Nov 2024 11:43:13 +0100 [thread overview]
Message-ID: <20241112104316.206282-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20241112104316.206282-1-c.ebner@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 5:
- 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 460c7da7c..75dc42407 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.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2024-11-12 10:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 10:43 [pbs-devel] [PATCH v6 proxmox-backup 0/4] fix #2996: client: allow optional match patterns for restore Christian Ebner
2024-11-12 10:43 ` Christian Ebner [this message]
2024-11-12 10:43 ` [pbs-devel] [PATCH v6 proxmox-backup 2/4] pxar: bin: use dedicated api type for restore pattern Christian Ebner
2024-11-12 10:43 ` [pbs-devel] [PATCH v6 proxmox-backup 3/4] client: catalog shell: use dedicated api type for patterns Christian Ebner
2024-11-12 10:43 ` [pbs-devel] [PATCH v6 proxmox-backup 4/4] fix #2996: client: allow optional match patterns for restore Christian Ebner
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=20241112104316.206282-2-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-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