use ApiType trait

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-08-25 09:37:54 +02:00
parent d0103000b8
commit 35e7f2f48e
2 changed files with 21 additions and 8 deletions

View File

@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use anyhow::{bail, Error};
use proxmox::api::schema::{ApiStringFormat, Schema, StringSchema};
use proxmox::api::schema::{ApiStringFormat, ApiType, Schema, StringSchema};
use proxmox::const_regex;
use proxmox::sys::linux::procfs;
@ -54,13 +54,15 @@ const_regex! {
pub const PROXMOX_UPID_FORMAT: ApiStringFormat =
ApiStringFormat::Pattern(&PROXMOX_UPID_REGEX);
impl UPID {
pub const API_SCHEMA: Schema = StringSchema::new("Unique Process/Task Identifier")
impl ApiType for UPID {
const API_SCHEMA: Schema = StringSchema::new("Unique Process/Task Identifier")
.min_length("UPID:N:12345678:12345678:12345678:::".len())
.max_length(128) // arbitrary
.format(&PROXMOX_UPID_FORMAT)
.schema();
}
impl UPID {
/// Create a new UPID
pub fn new(
worker_type: &str,

View File

@ -30,7 +30,7 @@ use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use proxmox::api::api;
use proxmox::api::schema::{ApiStringFormat, Schema, StringSchema, Updatable};
use proxmox::api::schema::{ApiStringFormat, ApiType, Schema, StringSchema, Updatable};
use proxmox::const_regex;
// we only allow a limited set of characters
@ -409,13 +409,15 @@ impl Updatable for Userid {
const UPDATER_IS_OPTION: bool = true;
}
impl Userid {
pub const API_SCHEMA: Schema = StringSchema::new("User ID")
impl ApiType for Userid {
const API_SCHEMA: Schema = StringSchema::new("User ID")
.format(&PROXMOX_USER_ID_FORMAT)
.min_length(3)
.max_length(64)
.schema();
}
impl Userid {
const fn new(data: String, name_len: usize) -> Self {
Self { data, name_len }
}
@ -538,13 +540,22 @@ pub struct Authid {
tokenname: Option<Tokenname>
}
impl Authid {
pub const API_SCHEMA: Schema = StringSchema::new("Authentication ID")
impl Updatable for Authid {
type Updater = Option<Authid>;
const UPDATER_IS_OPTION: bool = true;
}
impl ApiType for Authid {
const API_SCHEMA: Schema = StringSchema::new("Authentication ID")
.format(&PROXMOX_AUTH_ID_FORMAT)
.min_length(3)
.max_length(64)
.schema();
}
impl Authid {
const fn new(user: Userid, tokenname: Option<Tokenname>) -> Self {
Self { user, tokenname }
}