all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/4] proxmox-auth-api: use const_format to define static strings
Date: Fri, 15 Mar 2024 12:27:30 +0100	[thread overview]
Message-ID: <20240315112732.368831-2-dietmar@proxmox.com> (raw)
In-Reply-To: <20240315112732.368831-1-dietmar@proxmox.com>

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 proxmox-auth-api/Cargo.toml   |  4 +--
 proxmox-auth-api/src/types.rs | 62 ++++++++++-------------------------
 2 files changed, 20 insertions(+), 46 deletions(-)

diff --git a/proxmox-auth-api/Cargo.toml b/proxmox-auth-api/Cargo.toml
index 6e4a626..ecea701 100644
--- a/proxmox-auth-api/Cargo.toml
+++ b/proxmox-auth-api/Cargo.toml
@@ -14,7 +14,7 @@ required-features = [ "pam-authenticator" ]
 
 [dependencies]
 anyhow.workspace = true
-
+const_format = { workspace = true, optional = true }
 base64 = { workspace = true, optional = true }
 lazy_static = { workspace = true, optional = true }
 libc = { workspace = true, optional = true }
@@ -37,7 +37,7 @@ proxmox-tfa = { workspace = true, optional = true, features = [ "api" ] }
 default = []
 
 ticket = [ "dep:base64", "dep:percent-encoding", "dep:openssl" ]
-api-types = [ "dep:lazy_static", "dep:regex", "dep:serde", "dep:serde_plain", "dep:proxmox-schema" ]
+api-types = [ "dep:const_format", "dep:lazy_static", "dep:regex", "dep:serde", "dep:serde_plain", "dep:proxmox-schema" ]
 api = [
     "api-types",
     "ticket",
diff --git a/proxmox-auth-api/src/types.rs b/proxmox-auth-api/src/types.rs
index 319ac4b..e11d0b1 100644
--- a/proxmox-auth-api/src/types.rs
+++ b/proxmox-auth-api/src/types.rs
@@ -27,62 +27,36 @@ use std::fmt;
 use anyhow::{bail, format_err, Error};
 use lazy_static::lazy_static;
 use serde::{Deserialize, Serialize};
+use const_format::concatcp;
 
 use proxmox_schema::{
     api, const_regex, ApiStringFormat, ApiType, Schema, StringSchema, UpdaterType,
 };
 
+use proxmox_schema::api_types::SAFE_ID_REGEX_STR;
+
 // we only allow a limited set of characters
 // colon is not allowed, because we store usernames in
 // colon separated lists)!
 // slash is not allowed because it is used as pve API delimiter
 // also see "man useradd"
-#[macro_export]
-macro_rules! USER_NAME_REGEX_STR {
-    () => {
-        r"(?:[^\s:/[:cntrl:]]+)"
-    };
-}
-#[macro_export]
-macro_rules! GROUP_NAME_REGEX_STR {
-    () => {
-        $crate::USER_NAME_REGEX_STR!()
-    };
-}
-#[macro_export]
-macro_rules! TOKEN_NAME_REGEX_STR {
-    () => {
-        proxmox_schema::SAFE_ID_REGEX_STR!()
-    };
-}
-#[macro_export]
-macro_rules! USER_ID_REGEX_STR {
-    () => {
-        concat!(
-            $crate::USER_NAME_REGEX_STR!(),
-            r"@",
-            proxmox_schema::SAFE_ID_REGEX_STR!()
-        )
-    };
-}
-#[macro_export]
-macro_rules! APITOKEN_ID_REGEX_STR {
-    () => {
-        concat!(
-            $crate::USER_ID_REGEX_STR!(),
-            r"!",
-            $crate::TOKEN_NAME_REGEX_STR!()
-        )
-    };
-}
+pub const USER_NAME_REGEX_STR: &str = r"(?:[^\s:/[:cntrl:]]+)";
+
+pub const GROUP_NAME_REGEX_STR: &str = USER_NAME_REGEX_STR;
+
+pub const TOKEN_NAME_REGEX_STR: &str = SAFE_ID_REGEX_STR;
+
+pub const USER_ID_REGEX_STR: &str = concatcp!(USER_NAME_REGEX_STR, r"@", SAFE_ID_REGEX_STR);
+
+pub const APITOKEN_ID_REGEX_STR: &str = concatcp!(USER_ID_REGEX_STR, r"!", TOKEN_NAME_REGEX_STR);
 
 const_regex! {
-    pub PROXMOX_USER_NAME_REGEX = concat!(r"^",  USER_NAME_REGEX_STR!(), r"$");
-    pub PROXMOX_TOKEN_NAME_REGEX = concat!(r"^", TOKEN_NAME_REGEX_STR!(), r"$");
-    pub PROXMOX_USER_ID_REGEX = concat!(r"^",  USER_ID_REGEX_STR!(), r"$");
-    pub PROXMOX_APITOKEN_ID_REGEX = concat!(r"^", APITOKEN_ID_REGEX_STR!(), r"$");
-    pub PROXMOX_AUTH_ID_REGEX = concat!(r"^", r"(?:", USER_ID_REGEX_STR!(), r"|", APITOKEN_ID_REGEX_STR!(), r")$");
-    pub PROXMOX_GROUP_ID_REGEX = concat!(r"^",  GROUP_NAME_REGEX_STR!(), r"$");
+    pub PROXMOX_USER_NAME_REGEX = concatcp!(r"^",  USER_NAME_REGEX_STR, r"$");
+    pub PROXMOX_TOKEN_NAME_REGEX = concatcp!(r"^", TOKEN_NAME_REGEX_STR, r"$");
+    pub PROXMOX_USER_ID_REGEX = concatcp!(r"^",  USER_ID_REGEX_STR, r"$");
+    pub PROXMOX_APITOKEN_ID_REGEX = concatcp!(r"^", APITOKEN_ID_REGEX_STR, r"$");
+    pub PROXMOX_AUTH_ID_REGEX = concatcp!(r"^", r"(?:", USER_ID_REGEX_STR, r"|", APITOKEN_ID_REGEX_STR, r")$");
+    pub PROXMOX_GROUP_ID_REGEX = concatcp!(r"^",  GROUP_NAME_REGEX_STR, r"$");
 }
 
 pub const PROXMOX_USER_NAME_FORMAT: ApiStringFormat =
-- 
2.39.2




  reply	other threads:[~2024-03-15 11:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15 11:27 [pbs-devel] [PATCH proxmox 1/4] proxmox-schema: " Dietmar Maurer
2024-03-15 11:27 ` Dietmar Maurer [this message]
2024-03-15 11:27 ` [pbs-devel] [PATCH proxmox 3/4] proxmox-schema: add IP address regex/api-types Dietmar Maurer
2024-03-15 11:27 ` [pbs-devel] [PATCH proxmox 4/4] proxmox-schema: moved common api types from pbs-api-types Dietmar Maurer
2024-03-19 10:14 ` [pbs-devel] applied-series: [PATCH proxmox 1/4] proxmox-schema: use const_format to define static strings Wolfgang Bumiller

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=20240315112732.368831-2-dietmar@proxmox.com \
    --to=dietmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal