use ApiType trait
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
		| @ -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, | ||||
|  | ||||
| @ -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 } | ||||
|     } | ||||
|  | ||||
| @ -6,7 +6,7 @@ use ::serde::{Deserialize, Serialize}; | ||||
|  | ||||
| use proxmox::api::{api, Router, RpcEnvironment, Permission}; | ||||
| use proxmox::api::section_config::SectionConfigData; | ||||
| use proxmox::api::schema::parse_property_string; | ||||
| use proxmox::api::schema::{ApiType, parse_property_string}; | ||||
| use pbs_datastore::task::TaskState; | ||||
|  | ||||
| use crate::api2::config::sync::delete_sync_job; | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}}; | ||||
| use proxmox::api::{api, schema::{ApiType, Schema, StringSchema, ApiStringFormat}}; | ||||
|  | ||||
| use crate::api2::types::{ | ||||
|     DNS_ALIAS_FORMAT, DNS_NAME_FORMAT, PROXMOX_SAFE_ID_FORMAT, | ||||
|  | ||||
| @ -35,8 +35,8 @@ pub enum MediaLocation { | ||||
| proxmox::forward_deserialize_to_from_str!(MediaLocation); | ||||
| proxmox::forward_serialize_to_display!(MediaLocation); | ||||
|  | ||||
| impl MediaLocation { | ||||
|     pub const API_SCHEMA: Schema = StringSchema::new( | ||||
| impl proxmox::api::schema::ApiType for MediaLocation { | ||||
|     const API_SCHEMA: Schema = StringSchema::new( | ||||
|         "Media location (e.g. 'offline', 'online-<changer_name>', 'vault-<vault_name>')") | ||||
|         .format(&ApiStringFormat::VerifyFn(|text| { | ||||
|             let location: MediaLocation = text.parse()?; | ||||
|  | ||||
| @ -4,6 +4,7 @@ use serde_json::{json, Value}; | ||||
| use proxmox::{ | ||||
|     api::{ | ||||
|         schema::{ | ||||
|             ApiType, | ||||
|             Schema, | ||||
|             ObjectSchemaType, | ||||
|             ApiStringFormat, | ||||
|  | ||||
| @ -16,6 +16,7 @@ use proxmox::api::{ | ||||
|         default_table_format_options, | ||||
|     }, | ||||
|     router::ReturnType, | ||||
|     schema::ApiType, | ||||
| }; | ||||
|  | ||||
| use pbs_client::tools::key_source::get_encryption_key_password; | ||||
|  | ||||
| @ -10,6 +10,7 @@ use proxmox::api::cli::{ | ||||
|     OUTPUT_FORMAT, | ||||
| }; | ||||
| use proxmox::api::router::ReturnType; | ||||
| use proxmox::api::schema::ApiType; | ||||
| use proxmox::sys::linux::tty; | ||||
| use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; | ||||
|  | ||||
|  | ||||
| @ -5,7 +5,7 @@ use serde::{Serialize, Deserialize}; | ||||
|  | ||||
| use proxmox::api::{ | ||||
|     api, | ||||
|     schema::{Schema, StringSchema, Updater}, | ||||
|     schema::{ApiType, Schema, StringSchema, Updater}, | ||||
|     section_config::{ | ||||
|         SectionConfig, | ||||
|         SectionConfigData, | ||||
|  | ||||
| @ -4,7 +4,7 @@ use anyhow::{bail, Error}; | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| use proxmox::api::api; | ||||
| use proxmox::api::schema::{ApiStringFormat, Updater}; | ||||
| use proxmox::api::schema::{ApiStringFormat, ApiType, Updater}; | ||||
|  | ||||
| use proxmox_http::ProxyConfig; | ||||
|  | ||||
|  | ||||
| @ -4,7 +4,7 @@ use serde_json::json; | ||||
| use handlebars::{Handlebars, Helper, Context, RenderError, RenderContext, Output, HelperResult, TemplateError}; | ||||
|  | ||||
| use proxmox::tools::email::sendmail; | ||||
| use proxmox::api::schema::parse_property_string; | ||||
| use proxmox::api::schema::{ApiType, parse_property_string}; | ||||
| use proxmox::try_block; | ||||
|  | ||||
| use pbs_tools::format::HumanByte; | ||||
|  | ||||
| @ -152,6 +152,8 @@ fn object_to_writer(output: &mut dyn Write, object: &Object) -> Result<(), Error | ||||
|  | ||||
| #[test] | ||||
| fn test() { | ||||
|     use proxmox::api::schema::ApiType; | ||||
|  | ||||
|     // let's just reuse some schema we actually have available: | ||||
|     use crate::config::node::NodeConfig; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user