cleanup schema function calls
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
@ -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(),
|
||||
|
@ -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()
|
||||
|
@ -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(¬ify_str, &DatastoreNotify::API_SCHEMA)?;
|
||||
let value = DatastoreNotify::API_SCHEMA.parse_property_string(¬ify_str)?;
|
||||
let notify: DatastoreNotify = serde_json::from_value(value)?;
|
||||
if let DatastoreNotify { gc: None, verify: None, sync: None } = notify {
|
||||
data.notify = None;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -8,7 +8,7 @@ use tokio::signal::unix::{signal, SignalKind};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use proxmox_router::{cli::*, ApiHandler, ApiMethod, RpcEnvironment, SubRoute};
|
||||
use proxmox_schema::{api, parse_parameter_strings, ApiType, ParameterSchema, Schema};
|
||||
use proxmox_schema::{api, ApiType, ParameterSchema, Schema};
|
||||
use proxmox_schema::format::DocumentationFormat;
|
||||
|
||||
use pbs_api_types::{PROXMOX_UPID_REGEX, UPID};
|
||||
@ -161,7 +161,7 @@ fn merge_parameters(
|
||||
}
|
||||
}
|
||||
|
||||
let params = parse_parameter_strings(¶m_list, schema, true)?;
|
||||
let params = schema.parse_parameter_strings(¶m_list, true)?;
|
||||
|
||||
Ok(params)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use handlebars::{Handlebars, Helper, Context, RenderError, RenderContext, Output
|
||||
|
||||
use proxmox_sys::email::sendmail;
|
||||
use proxmox_lang::try_block;
|
||||
use proxmox_schema::{parse_property_string, ApiType};
|
||||
use proxmox_schema::ApiType;
|
||||
|
||||
use pbs_api_types::{
|
||||
User, TapeBackupJobSetup, SyncJobConfig, VerificationJobConfig,
|
||||
@ -578,7 +578,7 @@ pub fn lookup_datastore_notify_settings(
|
||||
|
||||
let notify_str = config.notify.unwrap_or_default();
|
||||
|
||||
if let Ok(value) = parse_property_string(¬ify_str, &DatastoreNotify::API_SCHEMA) {
|
||||
if let Ok(value) = DatastoreNotify::API_SCHEMA.parse_property_string(¬ify_str) {
|
||||
if let Ok(notify) = serde_json::from_value(value) {
|
||||
return (email, notify);
|
||||
}
|
||||
|
@ -6,9 +6,7 @@ use anyhow::{bail, format_err, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox_schema::{
|
||||
parse_property_string, parse_simple_value, verify_json_object, ObjectSchemaType, Schema,
|
||||
};
|
||||
use proxmox_schema::{ObjectSchemaType, Schema};
|
||||
|
||||
type Object = serde_json::Map<String, Value>;
|
||||
|
||||
@ -100,7 +98,7 @@ fn parse_key_value(
|
||||
fn parse_value(value: &str, schema: Option<&'static Schema>) -> Result<Value, Error> {
|
||||
match schema {
|
||||
None => Ok(Value::String(value.to_owned())),
|
||||
Some(schema) => parse_simple_value(value, schema),
|
||||
Some(schema) => schema.parse_simple_value(value),
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,9 +108,7 @@ pub fn from_property_string<T>(input: &str, schema: &'static Schema) -> Result<T
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
Ok(serde_json::from_value(parse_property_string(
|
||||
input, schema,
|
||||
)?)?)
|
||||
Ok(serde_json::from_value(schema.parse_property_string(input)?)?)
|
||||
}
|
||||
|
||||
/// Serialize a data structure using a 'key: value' config file format.
|
||||
@ -124,7 +120,7 @@ pub fn to_bytes<T: Serialize>(value: &T, schema: &'static Schema) -> Result<Vec<
|
||||
pub fn value_to_bytes(value: &Value, schema: &'static Schema) -> Result<Vec<u8>, Error> {
|
||||
let schema = object_schema(schema)?;
|
||||
|
||||
verify_json_object(value, schema)?;
|
||||
schema.verify_json(value)?;
|
||||
|
||||
let object = value
|
||||
.as_object()
|
||||
|
Reference in New Issue
Block a user