api/config: use http_bail for 'not found' errors
the api should return a 404 error for entries that do not exist Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
8d6425aa24
commit
dcd1518e10
|
@ -1,11 +1,11 @@
|
|||
/// Configure OpenId realms
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -112,7 +112,7 @@ pub fn delete_openid_realm(
|
|||
}
|
||||
|
||||
if domains.sections.remove(&realm).is_none() {
|
||||
bail!("realm '{}' does not exist.", realm);
|
||||
http_bail!(NOT_FOUND, "realm '{}' does not exist.", realm);
|
||||
}
|
||||
|
||||
domains::save_config(&domains)?;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -256,7 +256,7 @@ pub fn delete_changer(name: String, _param: Value) -> Result<(), Error> {
|
|||
}
|
||||
config.sections.remove(&name);
|
||||
},
|
||||
None => bail!("Delete changer '{}' failed - no such entry", name),
|
||||
None => http_bail!(NOT_FOUND, "Delete changer '{}' failed - no such entry", name),
|
||||
}
|
||||
|
||||
let drive_list: Vec<LtoTapeDrive> = config.convert_to_typed_array("lto")?;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, RpcEnvironmentType, Permission};
|
||||
use proxmox_schema::{api, param_bail, ApiType};
|
||||
use proxmox_section_config::SectionConfigData;
|
||||
use proxmox_sys::WorkerTaskContext;
|
||||
|
@ -359,7 +359,7 @@ pub async fn delete_datastore(
|
|||
|
||||
match config.sections.get(&name) {
|
||||
Some(_) => { config.sections.remove(&name); },
|
||||
None => bail!("datastore '{}' does not exist.", name),
|
||||
None => http_bail!(NOT_FOUND, "datastore '{}' does not exist.", name),
|
||||
}
|
||||
|
||||
if !keep_job_configs {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, format_err, Error};
|
||||
use anyhow::{format_err, Error};
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -258,7 +258,7 @@ pub fn delete_drive(name: String, _param: Value) -> Result<(), Error> {
|
|||
}
|
||||
config.sections.remove(&name);
|
||||
},
|
||||
None => bail!("Delete drive '{}' failed - no such drive", name),
|
||||
None => http_bail!(NOT_FOUND, "Delete drive '{}' failed - no such drive", name),
|
||||
}
|
||||
|
||||
pbs_config::drive::save_config(&config)?;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -217,7 +217,7 @@ pub fn delete_pool(name: String) -> Result<(), Error> {
|
|||
|
||||
match config.sections.get(&name) {
|
||||
Some(_) => { config.sections.remove(&name); },
|
||||
None => bail!("delete pool '{}' failed - no such pool", name),
|
||||
None => http_bail!(NOT_FOUND, "delete pool '{}' failed - no such pool", name),
|
||||
}
|
||||
|
||||
pbs_config::media_pool::save_config(&config)?;
|
||||
|
|
|
@ -6,7 +6,7 @@ use serde_json::Value;
|
|||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{http_err, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, http_err, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_client::{HttpClient, HttpClientOptions};
|
||||
|
@ -272,7 +272,7 @@ pub fn delete_remote(name: String, digest: Option<String>) -> Result<(), Error>
|
|||
|
||||
match config.sections.get(&name) {
|
||||
Some(_) => { config.sections.remove(&name); },
|
||||
None => bail!("remote '{}' does not exist.", name),
|
||||
None => http_bail!(NOT_FOUND, "remote '{}' does not exist.", name),
|
||||
}
|
||||
|
||||
pbs_config::remote::save_config(&config)?;
|
||||
|
|
|
@ -3,7 +3,7 @@ use serde_json::Value;
|
|||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -367,7 +367,7 @@ pub fn delete_sync_job(
|
|||
}
|
||||
config.sections.remove(&id);
|
||||
},
|
||||
Err(_) => { bail!("job '{}' does not exist.", id) },
|
||||
Err(_) => { http_bail!(NOT_FOUND, "job '{}' does not exist.", id) },
|
||||
};
|
||||
|
||||
sync::save_config(&config)?;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -268,7 +268,7 @@ pub fn delete_tape_backup_job(
|
|||
Ok(_job) => {
|
||||
config.sections.remove(&id);
|
||||
},
|
||||
Err(_) => { bail!("job '{}' does not exist.", id) },
|
||||
Err(_) => { http_bail!(NOT_FOUND, "job '{}' does not exist.", id) },
|
||||
};
|
||||
|
||||
pbs_config::tape_job::save_config(&config)?;
|
||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::{format_err, bail, Error};
|
|||
use serde_json::Value;
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -126,7 +126,7 @@ pub fn change_passphrase(
|
|||
|
||||
let key_config = match config_map.get(&fingerprint) {
|
||||
Some(key_config) => key_config,
|
||||
None => bail!("tape encryption key configuration '{}' does not exist.", fingerprint),
|
||||
None => http_bail!(NOT_FOUND, "tape encryption key configuration '{}' does not exist.", fingerprint),
|
||||
};
|
||||
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
|
@ -234,7 +234,7 @@ pub fn read_key(
|
|||
|
||||
let key_config = match config_map.get(&fingerprint) {
|
||||
Some(key_config) => key_config,
|
||||
None => bail!("tape encryption key '{}' does not exist.", fingerprint),
|
||||
None => http_bail!(NOT_FOUND, "tape encryption key '{}' does not exist.", fingerprint),
|
||||
};
|
||||
|
||||
if key_config.kdf.is_none() {
|
||||
|
@ -281,7 +281,7 @@ pub fn delete_key(
|
|||
|
||||
match config_map.get(&fingerprint) {
|
||||
Some(_) => { config_map.remove(&fingerprint); },
|
||||
None => bail!("tape encryption key '{}' does not exist.", fingerprint),
|
||||
None => http_bail!(NOT_FOUND, "tape encryption key '{}' does not exist.", fingerprint),
|
||||
}
|
||||
save_key_configs(config_map)?;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -245,7 +245,7 @@ pub fn delete_traffic_control(name: String, digest: Option<String>) -> Result<()
|
|||
|
||||
match config.sections.get(&name) {
|
||||
Some(_) => { config.sections.remove(&name); },
|
||||
None => bail!("traffic control rule '{}' does not exist.", name),
|
||||
None => http_bail!(NOT_FOUND, "traffic control rule '{}' does not exist.", name),
|
||||
}
|
||||
|
||||
pbs_config::traffic_control::save_config(&config)?;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, Error};
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
use hex::FromHex;
|
||||
|
||||
use proxmox_router::{Router, RpcEnvironment, Permission};
|
||||
use proxmox_router::{http_bail, Router, RpcEnvironment, Permission};
|
||||
use proxmox_schema::{api, param_bail};
|
||||
|
||||
use pbs_api_types::{
|
||||
|
@ -287,7 +287,7 @@ pub fn delete_verification_job(
|
|||
|
||||
match config.sections.get(&id) {
|
||||
Some(_) => { config.sections.remove(&id); },
|
||||
None => bail!("job '{}' does not exist.", id),
|
||||
None => http_bail!(NOT_FOUND, "job '{}' does not exist.", id),
|
||||
}
|
||||
|
||||
verify::save_config(&config)?;
|
||||
|
|
Loading…
Reference in New Issue