From 35e7f2f48e199436d3ffd8836bcd3236b423dd2f Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 25 Aug 2021 09:37:54 +0200 Subject: [PATCH] use ApiType trait Signed-off-by: Wolfgang Bumiller --- pbs-api-types/src/upid.rs | 8 +++++--- pbs-api-types/src/userid.rs | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pbs-api-types/src/upid.rs b/pbs-api-types/src/upid.rs index 5666df1e..9447b8a0 100644 --- a/pbs-api-types/src/upid.rs +++ b/pbs-api-types/src/upid.rs @@ -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, diff --git a/pbs-api-types/src/userid.rs b/pbs-api-types/src/userid.rs index 8418f13e..5ecae4df 100644 --- a/pbs-api-types/src/userid.rs +++ b/pbs-api-types/src/userid.rs @@ -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 } -impl Authid { - pub const API_SCHEMA: Schema = StringSchema::new("Authentication ID") + +impl Updatable for Authid { + type Updater = Option; + + 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) -> Self { Self { user, tokenname } }