public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 5/5] use `HttpError` and macros from `proxmox-http-error` crate
Date: Wed, 26 Jul 2023 14:50:06 +0200	[thread overview]
Message-ID: <20230726125006.616124-6-l.wagner@proxmox.com> (raw)
In-Reply-To: <20230726125006.616124-1-l.wagner@proxmox.com>

The `HttpError` type from `proxmox-router` has been moved into its
own crate.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 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<Response<Body>, 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::<HttpError>() {
-                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::<HttpError>() {
-            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





  parent reply	other threads:[~2023-07-26 12:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26 12:50 [pbs-devel] [PATCH proxmox{, -perl-rs, -backup} 0/5] move `HttpError` from `proxmox-router` into its own crate Lukas Wagner
2023-07-26 12:50 ` [pbs-devel] [PATCH proxmox 1/5] http-error: add new http-error crate Lukas Wagner
2023-07-26 13:35   ` Wolfgang Bumiller
2023-07-26 12:50 ` [pbs-devel] [PATCH proxmox 2/5] router: rest-server: auth-api: use " Lukas Wagner
2023-07-26 13:41   ` Wolfgang Bumiller
2023-07-26 13:45     ` Lukas Wagner
2023-07-26 12:50 ` [pbs-devel] [PATCH proxmox 3/5] notify: use HttpError from proxmox-http-error Lukas Wagner
2023-07-26 12:50 ` [pbs-devel] [PATCH proxmox-perl-rs 4/5] notify: use new HttpError type Lukas Wagner
2023-07-26 12:50 ` Lukas Wagner [this message]
2023-07-26 13:42   ` [pbs-devel] [PATCH proxmox-backup 5/5] use `HttpError` and macros from `proxmox-http-error` crate Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230726125006.616124-6-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal