api/config: use param_bail for parameter errors
when using the 'extjs' formatter, it marks them in a way, so that the gui can mark the form fields with the error Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
4042eedf18
commit
8d6425aa24
|
@ -6,7 +6,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
OpenIdRealmConfig, OpenIdRealmConfigUpdater,
|
||||
|
@ -68,7 +68,7 @@ pub fn create_openid_realm(config: OpenIdRealmConfig) -> Result<(), Error> {
|
|||
config.realm == "pam" ||
|
||||
domains.sections.get(&config.realm).is_some()
|
||||
{
|
||||
bail!("realm '{}' already exists.", config.realm);
|
||||
param_bail!("realm", "realm '{}' already exists.", config.realm);
|
||||
}
|
||||
|
||||
domains.set_data(&config.realm, "openid", &config)?;
|
||||
|
|
|
@ -13,7 +13,7 @@ use hex::FromHex;
|
|||
use proxmox_router::{
|
||||
http_bail, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap,
|
||||
};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
use proxmox_sys::{task_log, task_warn};
|
||||
|
||||
use proxmox_acme_rs::account::AccountData as AcmeAccountData;
|
||||
|
@ -582,7 +582,7 @@ pub fn get_plugin(id: String, mut rpcenv: &mut dyn RpcEnvironment) -> Result<Plu
|
|||
pub fn add_plugin(r#type: String, core: DnsPluginCore, data: String) -> Result<(), Error> {
|
||||
// Currently we only support DNS plugins and the standalone plugin is "fixed":
|
||||
if r#type != "dns" {
|
||||
bail!("invalid ACME plugin type: {:?}", r#type);
|
||||
param_bail!("type", "invalid ACME plugin type: {:?}", r#type);
|
||||
}
|
||||
|
||||
let data = String::from_utf8(base64::decode(&data)?)
|
||||
|
@ -594,7 +594,7 @@ pub fn add_plugin(r#type: String, core: DnsPluginCore, data: String) -> Result<(
|
|||
|
||||
let (mut plugins, _digest) = plugin::config()?;
|
||||
if plugins.contains_key(&id) {
|
||||
bail!("ACME plugin ID {:?} already exists", id);
|
||||
param_bail!("id", "ACME plugin ID {:?} already exists", id);
|
||||
}
|
||||
|
||||
let plugin = serde_json::to_value(DnsPlugin { core, data })?;
|
||||
|
|
|
@ -4,7 +4,7 @@ use serde_json::Value;
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, ScsiTapeChanger, ScsiTapeChangerUpdater, LtoTapeDrive,
|
||||
|
@ -43,11 +43,11 @@ pub fn create_changer(config: ScsiTapeChanger) -> Result<(), Error> {
|
|||
|
||||
for changer in existing {
|
||||
if changer.name == config.name {
|
||||
bail!("Entry '{}' already exists", config.name);
|
||||
param_bail!("name", "Entry '{}' already exists", config.name);
|
||||
}
|
||||
|
||||
if changer.path == config.path {
|
||||
bail!("Path '{}' already in use by '{}'", config.path, changer.name);
|
||||
param_bail!("path", "Path '{}' already in use by '{}'", config.path, changer.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ pub fn delete_changer(name: String, _param: Value) -> Result<(), Error> {
|
|||
match config.sections.get(&name) {
|
||||
Some((section_type, _)) => {
|
||||
if section_type != "changer" {
|
||||
bail!("Entry '{}' exists, but is not a changer device", name);
|
||||
param_bail!("name", "Entry '{}' exists, but is not a changer device", name);
|
||||
}
|
||||
config.sections.remove(&name);
|
||||
},
|
||||
|
@ -263,7 +263,7 @@ pub fn delete_changer(name: String, _param: Value) -> Result<(), Error> {
|
|||
for drive in drive_list {
|
||||
if let Some(changer) = drive.changer {
|
||||
if changer == name {
|
||||
bail!("Delete changer '{}' failed - used by drive '{}'", name, drive.name);
|
||||
param_bail!("name", "Delete changer '{}' failed - used by drive '{}'", name, drive.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission};
|
||||
use proxmox_schema::{api, ApiType};
|
||||
use proxmox_schema::{api, param_bail, ApiType};
|
||||
use proxmox_section_config::SectionConfigData;
|
||||
use proxmox_sys::WorkerTaskContext;
|
||||
|
||||
|
@ -113,7 +113,7 @@ pub fn create_datastore(
|
|||
let (section_config, _digest) = pbs_config::datastore::config()?;
|
||||
|
||||
if section_config.sections.get(&config.name).is_some() {
|
||||
bail!("datastore '{}' already exists.", config.name);
|
||||
param_bail!("name", "datastore '{}' already exists.", config.name);
|
||||
}
|
||||
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, LtoTapeDrive, LtoTapeDriveUpdater, ScsiTapeChanger,
|
||||
|
@ -43,10 +43,10 @@ pub fn create_drive(config: LtoTapeDrive) -> Result<(), Error> {
|
|||
|
||||
for drive in existing {
|
||||
if drive.name == config.name {
|
||||
bail!("Entry '{}' already exists", config.name);
|
||||
param_bail!("name", "Entry '{}' already exists", config.name);
|
||||
}
|
||||
if drive.path == config.path {
|
||||
bail!("Path '{}' already used in drive '{}'", config.path, drive.name);
|
||||
param_bail!("path", "Path '{}' already used in drive '{}'", config.path, drive.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ pub fn update_drive(
|
|||
data.changer_drivenum = None;
|
||||
} else {
|
||||
if data.changer.is_none() {
|
||||
bail!("Option 'changer-drivenum' requires option 'changer'.");
|
||||
param_bail!("changer", format_err!("Option 'changer-drivenum' requires option 'changer'."));
|
||||
}
|
||||
data.changer_drivenum = Some(changer_drivenum);
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ pub fn delete_drive(name: String, _param: Value) -> Result<(), Error> {
|
|||
match config.sections.get(&name) {
|
||||
Some((section_type, _)) => {
|
||||
if section_type != "lto" {
|
||||
bail!("Entry '{}' exists, but is not a lto tape drive", name);
|
||||
param_bail!("name", "Entry '{}' exists, but is not a lto tape drive", name);
|
||||
}
|
||||
config.sections.remove(&name);
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::{bail, Error};
|
|||
use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, MediaPoolConfig, MediaPoolConfigUpdater, MEDIA_POOL_NAME_SCHEMA,
|
||||
|
@ -35,7 +35,7 @@ pub fn create_pool(
|
|||
let (mut section_config, _digest) = pbs_config::media_pool::config()?;
|
||||
|
||||
if section_config.sections.get(&config.name).is_some() {
|
||||
bail!("Media pool '{}' already exists", config.name);
|
||||
param_bail!("name", "Media pool '{}' already exists", config.name);
|
||||
}
|
||||
|
||||
section_config.set_data(&config.name, "pool", &config)?;
|
||||
|
|
|
@ -7,7 +7,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{http_err, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_client::{HttpClient, HttpClientOptions};
|
||||
use pbs_api_types::{
|
||||
|
@ -95,7 +95,7 @@ pub fn create_remote(
|
|||
let (mut section_config, _digest) = pbs_config::remote::config()?;
|
||||
|
||||
if section_config.sections.get(&name).is_some() {
|
||||
bail!("remote '{}' already exists.", name);
|
||||
param_bail!("name", "remote '{}' already exists.", name);
|
||||
}
|
||||
|
||||
let remote = Remote { name: name.clone(), config, password };
|
||||
|
@ -257,7 +257,7 @@ pub fn delete_remote(name: String, digest: Option<String>) -> Result<(), Error>
|
|||
let job_list: Vec<SyncJobConfig> = sync_jobs.convert_to_typed_array("sync")?;
|
||||
for job in job_list {
|
||||
if job.remote == name {
|
||||
bail!("remote '{}' is used by sync job '{}' (datastore '{}')", name, job.id, job.store);
|
||||
param_bail!("name", "remote '{}' is used by sync job '{}' (datastore '{}')", name, job.id, job.store);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, SyncJobConfig, SyncJobConfigUpdater, JOB_ID_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||
|
@ -133,7 +133,7 @@ pub fn create_sync_job(
|
|||
let (mut section_config, _digest) = sync::config()?;
|
||||
|
||||
if section_config.sections.get(&config.id).is_some() {
|
||||
bail!("job '{}' already exists.", config.id);
|
||||
param_bail!("id", "job '{}' already exists.", config.id);
|
||||
}
|
||||
|
||||
section_config.set_data(&config.id, "sync", &config)?;
|
||||
|
|
|
@ -4,7 +4,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, TapeBackupJobConfig, TapeBackupJobConfigUpdater,
|
||||
|
@ -77,7 +77,7 @@ pub fn create_tape_backup_job(
|
|||
let (mut config, _digest) = pbs_config::tape_job::config()?;
|
||||
|
||||
if config.sections.get(&job.id).is_some() {
|
||||
bail!("job '{}' already exists.", job.id);
|
||||
param_bail!("id", "job '{}' already exists.", job.id);
|
||||
}
|
||||
|
||||
config.set_data(&job.id, "backup", &job)?;
|
||||
|
|
|
@ -3,7 +3,7 @@ use serde_json::Value;
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, Fingerprint, KeyInfo, Kdf,
|
||||
|
@ -112,7 +112,7 @@ pub fn change_passphrase(
|
|||
let kdf = kdf.unwrap_or_default();
|
||||
|
||||
if let Kdf::None = kdf {
|
||||
bail!("Please specify a key derivation function (none is not allowed here).");
|
||||
param_bail!("kdf", format_err!("Please specify a key derivation function (none is not allowed here)."));
|
||||
}
|
||||
|
||||
let _lock = open_backup_lockfile(TAPE_KEYS_LOCKFILE, None, true)?;
|
||||
|
@ -137,8 +137,8 @@ pub fn change_passphrase(
|
|||
}
|
||||
|
||||
let (key, created, fingerprint) = match (force, &password) {
|
||||
(true, Some(_)) => bail!("password is not allowed when using force"),
|
||||
(false, None) => bail!("missing parameter: password"),
|
||||
(true, Some(_)) => param_bail!("password", format_err!("password is not allowed when using force")),
|
||||
(false, None) => param_bail!("password", format_err!("missing parameter: password")),
|
||||
(false, Some(pass)) => key_config.decrypt(&|| Ok(pass.as_bytes().to_vec()))?,
|
||||
(true, None) => {
|
||||
let key = load_keys()?.0.get(&fingerprint).ok_or_else(|| {
|
||||
|
@ -195,7 +195,7 @@ pub fn create_key(
|
|||
let kdf = kdf.unwrap_or_default();
|
||||
|
||||
if let Kdf::None = kdf {
|
||||
bail!("Please specify a key derivation function (none is not allowed here).");
|
||||
param_bail!("kdf", format_err!("Please specify a key derivation function (none is not allowed here)."));
|
||||
}
|
||||
|
||||
let (key, mut key_config) = KeyConfig::new(password.as_bytes(), kdf)?;
|
||||
|
|
|
@ -4,7 +4,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
TrafficControlRule, TrafficControlRuleUpdater,
|
||||
|
@ -62,7 +62,7 @@ pub fn create_traffic_control(config: TrafficControlRule) -> Result<(), Error> {
|
|||
let (mut section_config, _digest) = pbs_config::traffic_control::config()?;
|
||||
|
||||
if section_config.sections.get(&config.name).is_some() {
|
||||
bail!("traffic control rule '{}' already exists.", config.name);
|
||||
param_bail!("name", "traffic control rule '{}' already exists.", config.name);
|
||||
}
|
||||
|
||||
section_config.set_data(&config.name, "rule", &config)?;
|
||||
|
|
|
@ -4,7 +4,7 @@ use ::serde::{Deserialize, Serialize};
|
|||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::api;
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, VerificationJobConfig, VerificationJobConfigUpdater, JOB_ID_SCHEMA,
|
||||
|
@ -85,7 +85,7 @@ pub fn create_verification_job(
|
|||
let (mut section_config, _digest) = verify::config()?;
|
||||
|
||||
if section_config.sections.get(&config.id).is_some() {
|
||||
bail!("job '{}' already exists.", config.id);
|
||||
param_bail!("id", "job '{}' already exists.", config.id);
|
||||
}
|
||||
|
||||
section_config.set_data(&config.id, "verification", &config)?;
|
||||
|
|
Loading…
Reference in New Issue