cleanup schema function calls

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2021-12-16 11:02:53 +01:00
parent 821aa8eae6
commit 9fa3026a08
14 changed files with 34 additions and 45 deletions

View File

@ -8,7 +8,7 @@ use proxmox_sys::sortable;
use proxmox_router::{
http_err, list_subdirs_api_method, Router, RpcEnvironment, SubdirMap, Permission,
};
use proxmox_schema::{api, parse_simple_value};
use proxmox_schema::api;
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig};
@ -158,13 +158,13 @@ pub fn openid_login(
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
let firstname = info["given_name"].as_str().map(|n| n.to_string())
.filter(|n| parse_simple_value(n, &FIRST_NAME_SCHEMA).is_ok());
.filter(|n| FIRST_NAME_SCHEMA.parse_simple_value(n).is_ok());
let lastname = info["family_name"].as_str().map(|n| n.to_string())
.filter(|n| parse_simple_value(n, &LAST_NAME_SCHEMA).is_ok());
.filter(|n| LAST_NAME_SCHEMA.parse_simple_value(n).is_ok());
let email = info["email"].as_str().map(|n| n.to_string())
.filter(|n| parse_simple_value(n, &EMAIL_SCHEMA).is_ok());
.filter(|n| EMAIL_SCHEMA.parse_simple_value(n).is_ok());
let user = User {
userid: user_id.clone(),

View File

@ -4,7 +4,7 @@ use serde_json::Value;
use hex::FromHex;
use proxmox_router::{Router, RpcEnvironment, Permission};
use proxmox_schema::{api, parse_property_string};
use proxmox_schema::api;
use pbs_api_types::{
Authid, ScsiTapeChanger, ScsiTapeChangerUpdater, LtoTapeDrive,
@ -205,9 +205,7 @@ pub fn update_changer(
}
if let Some(export_slots) = update.export_slots {
let slots: Value = parse_property_string(
&export_slots, &SLOT_ARRAY_SCHEMA
)?;
let slots: Value = SLOT_ARRAY_SCHEMA.parse_property_string(&export_slots)?;
let mut slots: Vec<String> = slots
.as_array()
.unwrap()

View File

@ -6,7 +6,7 @@ use ::serde::{Deserialize, Serialize};
use hex::FromHex;
use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission};
use proxmox_schema::{api, ApiType, parse_property_string};
use proxmox_schema::{api, ApiType};
use proxmox_section_config::SectionConfigData;
use proxmox_sys::WorkerTaskContext;
@ -283,7 +283,7 @@ pub fn update_datastore(
if update.keep_yearly.is_some() { data.keep_yearly = update.keep_yearly; }
if let Some(notify_str) = update.notify {
let value = parse_property_string(&notify_str, &DatastoreNotify::API_SCHEMA)?;
let value = DatastoreNotify::API_SCHEMA.parse_property_string(&notify_str)?;
let notify: DatastoreNotify = serde_json::from_value(value)?;
if let DatastoreNotify { gc: None, verify: None, sync: None } = notify {
data.notify = None;

View File

@ -2,7 +2,7 @@ use anyhow::{bail, Error};
use serde_json::{json, Value};
use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission};
use proxmox_schema::{api, parse_property_string};
use proxmox_schema::api;
use proxmox_sys::task_log;
use pbs_api_types::{
@ -173,7 +173,7 @@ pub fn create_zpool(
let ashift = ashift.unwrap_or(12);
let devices_text = devices.clone();
let devices = parse_property_string(&devices, &DISK_ARRAY_SCHEMA)?;
let devices = DISK_ARRAY_SCHEMA.parse_property_string(&devices)?;
let devices: Vec<String> = devices.as_array().unwrap().iter()
.map(|v| v.as_str().unwrap().to_string()).collect();

View File

@ -4,7 +4,7 @@ use ::serde::{Deserialize, Serialize};
use hex::FromHex;
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
use proxmox_schema::{api, parse_property_string};
use proxmox_schema::api;
use pbs_api_types::{
Authid, Interface, NetworkInterfaceType, LinuxBondMode, NetworkConfigMethod, BondXmitHashPolicy,
@ -17,7 +17,7 @@ use pbs_config::network::{self, NetworkConfig};
use proxmox_rest_server::WorkerTask;
fn split_interface_list(list: &str) -> Result<Vec<String>, Error> {
let value = parse_property_string(&list, &NETWORK_INTERFACE_ARRAY_SCHEMA)?;
let value = NETWORK_INTERFACE_ARRAY_SCHEMA.parse_property_string(&list)?;
Ok(value.as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_string()).collect())
}

View File

@ -11,7 +11,7 @@ use serde_json::Value;
use proxmox_sys::fs::{replace_file, CreateOptions};
use proxmox_io::ReadExt;
use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType};
use proxmox_schema::{api, parse_property_string};
use proxmox_schema::api;
use proxmox_section_config::SectionConfigData;
use proxmox_uuid::Uuid;
use proxmox_sys::{task_log, task_warn, WorkerTaskContext};
@ -79,7 +79,7 @@ impl TryFrom<String> for DataStoreMap {
type Error = Error;
fn try_from(value: String) -> Result<Self, Error> {
let value = parse_property_string(&value, &DATASTORE_MAP_ARRAY_SCHEMA)?;
let value = DATASTORE_MAP_ARRAY_SCHEMA.parse_property_string(&value)?;
let mut mapping: Vec<String> = value
.as_array()
.unwrap()