mirror of
				https://git.proxmox.com/git/proxmox
				synced 2025-11-04 01:10:17 +00:00 
			
		
		
		
	update to proxmox-sys 0.2 crate
- imported pbs-api-types/src/common_regex.rs from old proxmox crate - use hex crate to generate/parse hex digest - remove all reference to proxmox crate (use proxmox-sys and proxmox-serde instead) Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
		
							parent
							
								
									f6799e08af
								
							
						
					
					
						commit
						14f389d563
					
				@ -15,8 +15,10 @@ openssl = "0.10"
 | 
			
		||||
regex = "1.2"
 | 
			
		||||
serde = { version = "1.0", features = ["derive"] }
 | 
			
		||||
 | 
			
		||||
proxmox = "0.15.3"
 | 
			
		||||
proxmox-lang = "1.0.0"
 | 
			
		||||
proxmox-schema = { version = "1.0.1", features = [ "api-macro" ] }
 | 
			
		||||
proxmox-serde = "0.1"
 | 
			
		||||
proxmox-time = "1.1"
 | 
			
		||||
proxmox-uuid = { version = "1.0.0", features = [ "serde" ] }
 | 
			
		||||
 | 
			
		||||
proxmox-sys = "0.2" # only needed foör nodename()??
 | 
			
		||||
							
								
								
									
										78
									
								
								pbs-api-types/src/common_regex.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								pbs-api-types/src/common_regex.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,78 @@
 | 
			
		||||
//! Predefined Regular Expressions
 | 
			
		||||
//!
 | 
			
		||||
//! This is a collection of useful regular expressions
 | 
			
		||||
 | 
			
		||||
use lazy_static::lazy_static;
 | 
			
		||||
use regex::Regex;
 | 
			
		||||
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPV4OCTET { () => (r"(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])") }
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPV6H16 { () => (r"(?:[0-9a-fA-F]{1,4})") }
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPV6LS32 { () => (concat!(r"(?:(?:", IPV4RE!(), "|", IPV6H16!(), ":", IPV6H16!(), "))" )) }
 | 
			
		||||
 | 
			
		||||
/// Returns the regular expression string to match IPv4 addresses
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPV4RE { () => (concat!(r"(?:(?:", IPV4OCTET!(), r"\.){3}", IPV4OCTET!(), ")")) }
 | 
			
		||||
 | 
			
		||||
/// Returns the regular expression string to match IPv6 addresses
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPV6RE { () => (concat!(r"(?:",
 | 
			
		||||
    r"(?:(?:",                                               r"(?:", IPV6H16!(), r":){6})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:",                                             r"::(?:", IPV6H16!(), r":){5})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:",                            IPV6H16!(), r")?::(?:", IPV6H16!(), r":){4})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,1}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){3})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,2}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){2})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,3}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){1})", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,4}", IPV6H16!(), r")?::",                      ")", IPV6LS32!(), r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,5}", IPV6H16!(), r")?::",                      ")", IPV6H16!(),  r")|",
 | 
			
		||||
    r"(?:(?:(?:(?:", IPV6H16!(), r":){0,6}", IPV6H16!(), r")?::",                                        ")))"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Returns the regular expression string to match IP addresses (v4 or v6)
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
 | 
			
		||||
 | 
			
		||||
/// Regular expression string to match IP addresses where IPv6 addresses require brackets around
 | 
			
		||||
/// them, while for IPv4 they are forbidden.
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! IPRE_BRACKET { () => (
 | 
			
		||||
    concat!(r"(?:",
 | 
			
		||||
        IPV4RE!(),
 | 
			
		||||
        r"|\[(?:",
 | 
			
		||||
            IPV6RE!(),
 | 
			
		||||
        r")\]",
 | 
			
		||||
    r")"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
lazy_static! {
 | 
			
		||||
    pub static ref IP_REGEX: Regex = Regex::new(concat!(r"^", IPRE!(), r"$")).unwrap();
 | 
			
		||||
    pub static ref IP_BRACKET_REGEX: Regex =
 | 
			
		||||
        Regex::new(concat!(r"^", IPRE_BRACKET!(), r"$")).unwrap();
 | 
			
		||||
    pub static ref SHA256_HEX_REGEX: Regex = Regex::new(r"^[a-f0-9]{64}$").unwrap();
 | 
			
		||||
    pub static ref SYSTEMD_DATETIME_REGEX: Regex =
 | 
			
		||||
        Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$").unwrap();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_regexes() {
 | 
			
		||||
    assert!(IP_REGEX.is_match("127.0.0.1"));
 | 
			
		||||
    assert!(IP_REGEX.is_match("::1"));
 | 
			
		||||
    assert!(IP_REGEX.is_match("2014:b3a::27"));
 | 
			
		||||
    assert!(IP_REGEX.is_match("2014:b3a::192.168.0.1"));
 | 
			
		||||
    assert!(IP_REGEX.is_match("2014:b3a:0102:adf1:1234:4321:4afA:BCDF"));
 | 
			
		||||
 | 
			
		||||
    assert!(IP_BRACKET_REGEX.is_match("127.0.0.1"));
 | 
			
		||||
    assert!(IP_BRACKET_REGEX.is_match("[::1]"));
 | 
			
		||||
    assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::27]"));
 | 
			
		||||
    assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::192.168.0.1]"));
 | 
			
		||||
    assert!(IP_BRACKET_REGEX.is_match("[2014:b3a:0102:adf1:1234:4321:4afA:BCDF]"));
 | 
			
		||||
}
 | 
			
		||||
@ -51,7 +51,8 @@ impl std::str::FromStr for Fingerprint {
 | 
			
		||||
    fn from_str(s: &str) -> Result<Self, Error> {
 | 
			
		||||
        let mut tmp = s.to_string();
 | 
			
		||||
        tmp.retain(|c| c != ':');
 | 
			
		||||
        let bytes = proxmox::tools::hex_to_digest(&tmp)?;
 | 
			
		||||
        let mut bytes = [0u8; 32];
 | 
			
		||||
        hex::decode_to_slice(&tmp, &mut bytes)?;
 | 
			
		||||
        Ok(Fingerprint::new(bytes))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -216,8 +216,8 @@ impl std::str::FromStr for HumanByte {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
proxmox::forward_deserialize_to_from_str!(HumanByte);
 | 
			
		||||
proxmox::forward_serialize_to_display!(HumanByte);
 | 
			
		||||
proxmox_serde::forward_deserialize_to_from_str!(HumanByte);
 | 
			
		||||
proxmox_serde::forward_serialize_to_display!(HumanByte);
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_human_byte_parser() -> Result<(), Error> {
 | 
			
		||||
 | 
			
		||||
@ -365,8 +365,8 @@ impl std::fmt::Display for GroupFilter {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
proxmox::forward_deserialize_to_from_str!(GroupFilter);
 | 
			
		||||
proxmox::forward_serialize_to_display!(GroupFilter);
 | 
			
		||||
proxmox_serde::forward_deserialize_to_from_str!(GroupFilter);
 | 
			
		||||
proxmox_serde::forward_serialize_to_display!(GroupFilter);
 | 
			
		||||
 | 
			
		||||
fn verify_group_filter(input: &str) -> Result<(), anyhow::Error> {
 | 
			
		||||
    GroupFilter::from_str(input).map(|_| ())
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,11 @@
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use anyhow::bail;
 | 
			
		||||
 | 
			
		||||
pub mod common_regex;
 | 
			
		||||
 | 
			
		||||
use proxmox_schema::{
 | 
			
		||||
    api, const_regex, ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema, ReturnType,
 | 
			
		||||
};
 | 
			
		||||
use proxmox::{IPRE, IPRE_BRACKET, IPV4OCTET, IPV4RE, IPV6H16, IPV6LS32, IPV6RE};
 | 
			
		||||
use proxmox_time::parse_daily_duration;
 | 
			
		||||
 | 
			
		||||
#[rustfmt::skip]
 | 
			
		||||
@ -199,7 +200,7 @@ pub const DNS_NAME_OR_IP_SCHEMA: Schema = StringSchema::new("DNS name or IP addr
 | 
			
		||||
 | 
			
		||||
pub const NODE_SCHEMA: Schema = StringSchema::new("Node name (or 'localhost')")
 | 
			
		||||
    .format(&ApiStringFormat::VerifyFn(|node| {
 | 
			
		||||
        if node == "localhost" || node == proxmox::tools::nodename() {
 | 
			
		||||
        if node == "localhost" || node == proxmox_sys::nodename() {
 | 
			
		||||
            Ok(())
 | 
			
		||||
        } else {
 | 
			
		||||
            bail!("no such node '{}'", node);
 | 
			
		||||
 | 
			
		||||
@ -79,7 +79,7 @@ pub struct Remote {
 | 
			
		||||
    pub name: String,
 | 
			
		||||
    // Note: The stored password is base64 encoded
 | 
			
		||||
    #[serde(skip_serializing_if="String::is_empty")]
 | 
			
		||||
    #[serde(with = "proxmox::tools::serde::string_as_base64")]
 | 
			
		||||
    #[serde(with = "proxmox_serde::string_as_base64")]
 | 
			
		||||
    pub password: String,
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
    pub config: RemoteConfig,
 | 
			
		||||
 | 
			
		||||
@ -22,8 +22,8 @@ pub enum MediaLocation {
 | 
			
		||||
    Vault(String),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
proxmox::forward_deserialize_to_from_str!(MediaLocation);
 | 
			
		||||
proxmox::forward_serialize_to_display!(MediaLocation);
 | 
			
		||||
proxmox_serde::forward_deserialize_to_from_str!(MediaLocation);
 | 
			
		||||
proxmox_serde::forward_serialize_to_display!(MediaLocation);
 | 
			
		||||
 | 
			
		||||
impl proxmox_schema::ApiType for MediaLocation {
 | 
			
		||||
    const API_SCHEMA: Schema = StringSchema::new(
 | 
			
		||||
 | 
			
		||||
@ -685,8 +685,8 @@ fn test_token_id() {
 | 
			
		||||
    assert_eq!(auth_id.to_string(), "test@pam!bar".to_string());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
proxmox::forward_deserialize_to_from_str!(Userid);
 | 
			
		||||
proxmox::forward_serialize_to_display!(Userid);
 | 
			
		||||
proxmox_serde::forward_deserialize_to_from_str!(Userid);
 | 
			
		||||
proxmox_serde::forward_serialize_to_display!(Userid);
 | 
			
		||||
 | 
			
		||||
proxmox::forward_deserialize_to_from_str!(Authid);
 | 
			
		||||
proxmox::forward_serialize_to_display!(Authid);
 | 
			
		||||
proxmox_serde::forward_deserialize_to_from_str!(Authid);
 | 
			
		||||
proxmox_serde::forward_serialize_to_display!(Authid);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user