]> git.proxmox.com Git - proxmox-backup.git/commitdiff
use ApiType trait
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 25 Aug 2021 07:37:54 +0000 (09:37 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 25 Aug 2021 08:43:58 +0000 (10:43 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
12 files changed:
pbs-api-types/src/upid.rs
pbs-api-types/src/userid.rs
src/api2/config/datastore.rs
src/api2/types/acme.rs
src/api2/types/tape/media_location.rs
src/bin/docgen.rs
src/bin/proxmox_backup_client/benchmark.rs
src/bin/proxmox_backup_client/key.rs
src/config/datastore.rs
src/config/node.rs
src/server/email_notifications.rs
src/tools/config.rs

index 5666df1ea40aec9739691e518a04e14f158c5384..9447b8a01983c2bbd4e96d82dcac850fba44cda8 100644 (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,
index 8418f13ecebe2e0c50bbe4cd68c9523588b51099..5ecae4df7e1b20a674d65ac544acece2fb97ed31 100644 (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 }
     }
index aa75480842bc3f031d90de3c925f607686e44e35..b0a5b0d20e53ad9e6e62c7a7c893defe94447d0d 100644 (file)
@@ -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;
index 87b86537e32217bf2958ba4b508d84e4bde61ed2..4370d6a6773a31c2f1e9330ac8d1558f4aa53b01 100644 (file)
@@ -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,
index 031369e39f735244c3e227a823c214b9cf290a4d..6040655aa360dda76c9cde0ee21f1d02855e7454 100644 (file)
@@ -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()?;
index 3a387e1cfa979e0963f388526edf3e1884b1aa1c..1fba9bafbc1b7a35c33286bd44c47f42f9743cf6 100644 (file)
@@ -4,6 +4,7 @@ use serde_json::{json, Value};
 use proxmox::{
     api::{
         schema::{
+            ApiType,
             Schema,
             ObjectSchemaType,
             ApiStringFormat,
index 442bd03f10acaf35e10c64335160043def78d195..9f205c27c1a3bacea3d5425efe4238c7c645044a 100644 (file)
@@ -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;
index cd2958bac3b1115251f9959130fc8f5f5c3604fd..c06926e331f92b72f4e2fda5bd7615c0d074376c 100644 (file)
@@ -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};
 
index 5409c7c2b9ca303bcd026d416c2cc534a2fcf777..cfa03547e603333a9b576d4a71ba54efaf3c7c3a 100644 (file)
@@ -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,
index c03078bbe4fca9ed6590a13375810cb9bbcfcdf2..a46aabedae57a85417ace29eb54ae03c7b124055 100644 (file)
@@ -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;
 
index 2362b6733ce136ab10a31fa994de83d9a0caebd6..708309155e6402db957d8329401cbf59c1cacd52 100644 (file)
@@ -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;
index 499bd187f12ffdb3f6139e3ac7ad5c16b0314045..f908d67cb00b4f898618e0a4d238a9a0b810c65c 100644 (file)
@@ -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;