From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6B36661C13; Wed, 26 Jul 2023 14:50:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4831368A6; Wed, 26 Jul 2023 14:50:19 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS; Wed, 26 Jul 2023 14:50:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3D17A45946; Wed, 26 Jul 2023 14:50:16 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Wed, 26 Jul 2023 14:50:06 +0200 Message-Id: <20230726125006.616124-6-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230726125006.616124-1-l.wagner@proxmox.com> References: <20230726125006.616124-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.056 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup 5/5] use `HttpError` and macros from `proxmox-http-error` crate X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jul 2023 12:50:50 -0000 The `HttpError` type from `proxmox-router` has been moved into its own crate. Signed-off-by: Lukas Wagner --- Cargo.toml | 3 +++ src/api2/access/openid.rs | 5 ++--- src/api2/access/tfa.rs | 3 ++- src/api2/admin/datastore.rs | 5 +++-- src/api2/admin/namespace.rs | 3 ++- src/api2/backup/mod.rs | 5 +++-- src/api2/config/access/ldap.rs | 3 ++- src/api2/config/access/openid.rs | 3 ++- src/api2/config/acme.rs | 5 ++--- src/api2/config/changer.rs | 3 ++- src/api2/config/datastore.rs | 3 ++- src/api2/config/drive.rs | 3 ++- src/api2/config/media_pool.rs | 3 ++- src/api2/config/prune.rs | 3 ++- src/api2/config/remote.rs | 3 ++- src/api2/config/sync.rs | 3 ++- src/api2/config/tape_backup_job.rs | 3 ++- src/api2/config/tape_encryption_keys.rs | 3 ++- src/api2/config/traffic_control.rs | 3 ++- src/api2/config/verify.rs | 3 ++- src/api2/helpers.rs | 2 +- src/api2/reader/mod.rs | 5 +++-- src/auth.rs | 2 +- src/backup/hierarchy.rs | 2 +- src/server/pull.rs | 4 ++-- 25 files changed, 51 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e0aca5f..a4d6a8d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ proxmox-borrow = "1" proxmox-compression = "0.2" proxmox-fuse = "0.1.3" proxmox-http = { version = "0.9.0", features = [ "client", "http-helpers", "websocket" ] } # see below +proxmox-http-error = "0.1.0" proxmox-human-byte = "0.1" proxmox-io = "1.0.1" # tools and client use "tokio" feature proxmox-lang = "1.1" @@ -202,6 +203,7 @@ proxmox-async.workspace = true proxmox-auth-api = { workspace = true, features = [ "api", "pam-authenticator" ] } proxmox-compression.workspace = true proxmox-http = { workspace = true, features = [ "client-trait", "proxmox-async", "rate-limited-stream" ] } # pbs-client doesn't use these +proxmox-http-error.workspace = true proxmox-human-byte.workspace = true proxmox-io.workspace = true proxmox-lang.workspace = true @@ -246,6 +248,7 @@ proxmox-rrd.workspace = true #proxmox-compression = { path = "../proxmox/proxmox-compression" } #proxmox-fuse = { path = "../proxmox-fuse" } #proxmox-http = { path = "../proxmox/proxmox-http" } +#proxmox-http-error = { path = "../proxmox/proxmox-http-error" } #proxmox-io = { path = "../proxmox/proxmox-io" } #proxmox-lang = { path = "../proxmox/proxmox-lang" } #proxmox-rest-server = { path = "../proxmox/proxmox-rest-server" } diff --git a/src/api2/access/openid.rs b/src/api2/access/openid.rs index 8e39cbc9..6e703bac 100644 --- a/src/api2/access/openid.rs +++ b/src/api2/access/openid.rs @@ -4,9 +4,8 @@ use serde_json::{json, Value}; use proxmox_auth_api::api::ApiTicket; use proxmox_auth_api::ticket::Ticket; -use proxmox_router::{ - http_err, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap, -}; +use proxmox_http_error::http_err; +use proxmox_router::{list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap}; use proxmox_schema::api; use proxmox_sortable_macro::sortable; diff --git a/src/api2/access/tfa.rs b/src/api2/access/tfa.rs index 589535a6..4182aa18 100644 --- a/src/api2/access/tfa.rs +++ b/src/api2/access/tfa.rs @@ -2,7 +2,8 @@ use anyhow::Error; -use proxmox_router::{http_bail, http_err, Permission, Router, RpcEnvironment}; +use proxmox_http_error::{http_bail, http_err}; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::api; use proxmox_tfa::api::methods; diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index a95031e7..7f4b006f 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -17,9 +17,10 @@ use tokio_stream::wrappers::ReceiverStream; use proxmox_async::blocking::WrappedReaderStream; use proxmox_async::{io::AsyncChannelWriter, stream::AsyncReaderStream}; use proxmox_compression::zstd::ZstdEncoder; +use proxmox_http_error::http_err; use proxmox_router::{ - http_err, list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, - Router, RpcEnvironment, RpcEnvironmentType, SubdirMap, + list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, + RpcEnvironment, RpcEnvironmentType, SubdirMap, }; use proxmox_schema::*; use proxmox_sortable_macro::sortable; diff --git a/src/api2/admin/namespace.rs b/src/api2/admin/namespace.rs index b2b08ecc..ccf24616 100644 --- a/src/api2/admin/namespace.rs +++ b/src/api2/admin/namespace.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; use serde_json::Value; use pbs_config::CachedUserInfo; -use proxmox_router::{http_bail, ApiMethod, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment}; use proxmox_schema::*; use pbs_api_types::{ diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs index 652d5baa..1e31e954 100644 --- a/src/api2/backup/mod.rs +++ b/src/api2/backup/mod.rs @@ -9,7 +9,8 @@ use hyper::{Body, Request, Response, StatusCode}; use serde::Deserialize; use serde_json::{json, Value}; -use proxmox_router::{http_err, list_subdirs_api_method}; +use proxmox_http_error::{http_bail, http_err}; +use proxmox_router::list_subdirs_api_method; use proxmox_router::{ ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, SubdirMap, }; @@ -114,7 +115,7 @@ fn upgrade_to_backup_protocol( } if !datastore.namespace_path(&backup_ns).exists() { - proxmox_router::http_bail!(NOT_FOUND, "namespace not found"); + http_bail!(NOT_FOUND, "namespace not found"); } // FIXME: include namespace here? diff --git a/src/api2/config/access/ldap.rs b/src/api2/config/access/ldap.rs index 911142a0..e02b33db 100644 --- a/src/api2/config/access/ldap.rs +++ b/src/api2/config/access/ldap.rs @@ -4,8 +4,9 @@ use anyhow::{format_err, Error}; use hex::FromHex; use serde_json::Value; +use proxmox_http_error::http_bail; use proxmox_ldap::Connection; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/access/openid.rs b/src/api2/config/access/openid.rs index 4901880e..e4cb199f 100644 --- a/src/api2/config/access/openid.rs +++ b/src/api2/config/access/openid.rs @@ -4,7 +4,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index 1954318b..a5a2804b 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -10,9 +10,8 @@ use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use proxmox_router::{ - http_bail, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap, -}; +use proxmox_http_error::http_bail; +use proxmox_router::{list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap}; use proxmox_schema::{api, param_bail}; use proxmox_sys::{task_log, task_warn}; diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs index 01908e3b..e059ef7e 100644 --- a/src/api2/config/changer.rs +++ b/src/api2/config/changer.rs @@ -3,7 +3,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 5e013c39..41de8540 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -5,7 +5,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment, RpcEnvironmentType}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType}; use proxmox_schema::{api, param_bail, ApiType}; use proxmox_section_config::SectionConfigData; use proxmox_sys::{task_warn, WorkerTaskContext}; diff --git a/src/api2/config/drive.rs b/src/api2/config/drive.rs index 02589aaf..d7b5147c 100644 --- a/src/api2/config/drive.rs +++ b/src/api2/config/drive.rs @@ -3,7 +3,8 @@ use anyhow::{format_err, Error}; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/media_pool.rs b/src/api2/config/media_pool.rs index 4a4cec56..b9839e7b 100644 --- a/src/api2/config/media_pool.rs +++ b/src/api2/config/media_pool.rs @@ -1,7 +1,8 @@ use ::serde::{Deserialize, Serialize}; use anyhow::Error; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/prune.rs b/src/api2/config/prune.rs index 6f391722..5f19eade 100644 --- a/src/api2/config/prune.rs +++ b/src/api2/config/prune.rs @@ -3,7 +3,8 @@ use hex::FromHex; use serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 76dd3b89..cae45546 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -8,7 +8,8 @@ use proxmox_router::SubdirMap; use proxmox_sortable_macro::sortable; use serde_json::Value; -use proxmox_router::{http_bail, http_err, ApiMethod, Permission, Router, RpcEnvironment}; +use proxmox_http_error::{http_bail, http_err}; +use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index 01e5f2ce..0bcde927 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -3,7 +3,8 @@ use anyhow::{bail, Error}; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/tape_backup_job.rs b/src/api2/config/tape_backup_job.rs index 386ff530..f923e894 100644 --- a/src/api2/config/tape_backup_job.rs +++ b/src/api2/config/tape_backup_job.rs @@ -3,7 +3,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/tape_encryption_keys.rs b/src/api2/config/tape_encryption_keys.rs index 788ed0e7..c36103e6 100644 --- a/src/api2/config/tape_encryption_keys.rs +++ b/src/api2/config/tape_encryption_keys.rs @@ -2,7 +2,8 @@ use anyhow::{bail, format_err, Error}; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, ApiMethod, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/traffic_control.rs b/src/api2/config/traffic_control.rs index 30ea40ec..57124ef1 100644 --- a/src/api2/config/traffic_control.rs +++ b/src/api2/config/traffic_control.rs @@ -3,7 +3,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, ApiMethod, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/config/verify.rs b/src/api2/config/verify.rs index 82dbe43b..d1edad0e 100644 --- a/src/api2/config/verify.rs +++ b/src/api2/config/verify.rs @@ -3,7 +3,8 @@ use anyhow::Error; use hex::FromHex; use serde_json::Value; -use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; +use proxmox_http_error::http_bail; +use proxmox_router::{Permission, Router, RpcEnvironment}; use proxmox_schema::{api, param_bail}; use pbs_api_types::{ diff --git a/src/api2/helpers.rs b/src/api2/helpers.rs index 3dc1befc..d9c3c648 100644 --- a/src/api2/helpers.rs +++ b/src/api2/helpers.rs @@ -4,7 +4,7 @@ use anyhow::Error; use futures::stream::TryStreamExt; use hyper::{header, Body, Response, StatusCode}; -use proxmox_router::http_bail; +use proxmox_http_error::http_bail; pub async fn create_download_response(path: PathBuf) -> Result, Error> { let file = match tokio::fs::File::open(path.clone()).await { diff --git a/src/api2/reader/mod.rs b/src/api2/reader/mod.rs index b1a5612b..1ef9334a 100644 --- a/src/api2/reader/mod.rs +++ b/src/api2/reader/mod.rs @@ -9,9 +9,10 @@ use hyper::{Body, Request, Response, StatusCode}; use serde::Deserialize; use serde_json::Value; +use proxmox_http_error::http_err; use proxmox_router::{ - http_err, list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, - Router, RpcEnvironment, SubdirMap, + list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, + RpcEnvironment, SubdirMap, }; use proxmox_schema::{BooleanSchema, ObjectSchema}; use proxmox_sortable_macro::sortable; diff --git a/src/auth.rs b/src/auth.rs index 318d1ff2..d8e56df0 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -9,13 +9,13 @@ use std::pin::Pin; use anyhow::{bail, Error}; use futures::Future; use once_cell::sync::{Lazy, OnceCell}; -use proxmox_router::http_bail; use serde_json::json; use proxmox_auth_api::api::{Authenticator, LockedTfaConfig}; use proxmox_auth_api::ticket::{Empty, Ticket}; use proxmox_auth_api::types::Authid; use proxmox_auth_api::Keyring; +use proxmox_http_error::http_bail; use proxmox_ldap::{Config, Connection, ConnectionMode}; use proxmox_tfa::api::{OpenUserChallengeData, TfaConfig}; diff --git a/src/backup/hierarchy.rs b/src/backup/hierarchy.rs index 640a7762..204aee6e 100644 --- a/src/backup/hierarchy.rs +++ b/src/backup/hierarchy.rs @@ -62,7 +62,7 @@ pub fn check_ns_privs_full( let priv_names = privs_to_priv_names(full_access_privs | partial_access_privs).join("|"); let path = format!("/{}", acl_path.join("/")); - proxmox_router::http_bail!( + proxmox_http_error::http_bail!( FORBIDDEN, "permission check failed - missing {priv_names} on {path}" ); diff --git a/src/server/pull.rs b/src/server/pull.rs index a973a10e..97c306f8 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -386,7 +386,7 @@ async fn pull_snapshot( Ok(manifest_file) => manifest_file, Err(err) => { match err.downcast_ref::() { - Some(HttpError { code, message }) => match *code { + Some(HttpError { code, message, .. }) => match *code { StatusCode::NOT_FOUND => { task_log!( worker, @@ -805,7 +805,7 @@ async fn query_namespaces( let mut result = match client.get(&path, Some(data)).await { Ok(res) => res, Err(err) => match err.downcast_ref::() { - Some(HttpError { code, message }) => match *code { + Some(HttpError { code, message, .. }) => match *code { StatusCode::NOT_FOUND => { if params.remote_ns.is_root() && params.max_depth.is_none() { task_log!(worker, "Could not query remote for namespaces (404) -> temporarily switching to backwards-compat mode"); -- 2.39.2