]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move json_object_to_query to proxmox-http+http-helpers
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 21 Jun 2022 12:32:02 +0000 (14:32 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 4 Jul 2022 08:08:53 +0000 (10:08 +0200)
it's used by the subscription code that will be extracted next.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
debian/control
pbs-client/Cargo.toml
pbs-client/src/http_client.rs
pbs-client/src/tools/mod.rs
pbs-client/src/vsock_client.rs
pbs-tools/src/json.rs
src/tools/subscription.rs

index 992bf264a1124661ef7c418614cf0a95de651669..3f513cdfe1153a7df8d9e676f32869c7bccc85b0 100644 (file)
@@ -47,10 +47,10 @@ Build-Depends: debhelper (>= 12),
  librust-proxmox-borrow-1+default-dev,
  librust-proxmox-compression-0.1+default-dev (>= 0.1.1-~~),
  librust-proxmox-fuse-0.1+default-dev (>= 0.1.3-~~),
- librust-proxmox-http-0.6+client-dev (>= 0.6.1-~~),
- librust-proxmox-http-0.6+default-dev (>= 0.6.1-~~),
- librust-proxmox-http-0.6+http-helpers-dev (>= 0.6.1-~~),
- librust-proxmox-http-0.6+websocket-dev (>= 0.6.1-~~),
+ librust-proxmox-http-0.6+client-dev (>= 0.6.3-~~),
+ librust-proxmox-http-0.6+default-dev (>= 0.6.3-~~),
+ librust-proxmox-http-0.6+http-helpers-dev (>= 0.6.3-~~),
+ librust-proxmox-http-0.6+websocket-dev (>= 0.6.3-~~),
  librust-proxmox-io-1+default-dev (>= 1.0.1-~~),
  librust-proxmox-io-1+tokio-dev (>= 1.0.1-~~),
  librust-proxmox-lang-1+default-dev (>= 1.1-~~),
index 40e34f9ad4384c7c1a883fd9a4e671228a2ddf3d..6bc02ecdb68a6ea3be2b2c7efc65fe298af3f032 100644 (file)
@@ -36,7 +36,7 @@ pathpatterns = "0.1.2"
 proxmox-async = "0.4"
 proxmox-compression = "0.1.1"
 proxmox-fuse = "0.1.3"
-proxmox-http = { version = "0.6", features = [ "client", "http-helpers", "websocket" ] }
+proxmox-http = { version = "0.6.3", features = [ "client", "http-helpers", "websocket" ] }
 proxmox-io = { version = "1.0.1", features = [ "tokio" ] }
 proxmox-lang = "1.1"
 proxmox-router = { version = "1.2.4", features = [ "cli" ] }
index 6d5d9ad51de871c99b683dc5694b76f47c350061..4ef1350b6206ba3acb8feb7d643c728d31b5b4fa 100644 (file)
@@ -23,11 +23,10 @@ use proxmox_sys::linux::tty;
 
 use proxmox_async::broadcast_future::BroadcastFuture;
 use proxmox_http::client::{HttpsConnector, RateLimiter};
-use proxmox_http::uri::build_authority;
+use proxmox_http::uri::{build_authority, json_object_to_query};
 
 use pbs_api_types::percent_encoding::DEFAULT_ENCODE_SET;
 use pbs_api_types::{Authid, RateLimitConfig, Userid};
-use pbs_tools::json::json_object_to_query;
 use pbs_tools::ticket;
 
 use super::pipe_to_stream::PipeToSendStream;
index 75c5ba32e9e1929c5d666aa89d0351a081a50edc..50e76a493e52ae25544873b65f381df679147bc2 100644 (file)
@@ -10,12 +10,12 @@ use anyhow::{bail, format_err, Context, Error};
 use serde_json::{json, Value};
 use xdg::BaseDirectories;
 
+use proxmox_http::uri::json_object_to_query;
 use proxmox_router::cli::{complete_file_name, shellword_split};
 use proxmox_schema::*;
 use proxmox_sys::fs::file_get_json;
 
 use pbs_api_types::{Authid, BackupNamespace, RateLimitConfig, UserWithTokens, BACKUP_REPO_URL};
-use pbs_tools::json::json_object_to_query;
 
 use crate::{BackupRepository, HttpClient, HttpClientOptions};
 
index 57a46d571a5b30d0531fc4217bc4cebaf52910db..6d62cd93fd6c4a6bb44e0bacfba0495e08e224bd 100644 (file)
@@ -13,6 +13,7 @@ use serde_json::Value;
 use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
 use tokio::net::UnixStream;
 
+use proxmox_http::uri::json_object_to_query;
 use proxmox_router::HttpError;
 
 pub const DEFAULT_VSOCK_PORT: u16 = 807;
@@ -240,7 +241,7 @@ impl VsockClient {
                 let request = builder.body(Body::from(data.to_string()))?;
                 return Ok(request);
             } else {
-                let query = pbs_tools::json::json_object_to_query(data)?;
+                let query = json_object_to_query(data)?;
                 let url: Uri =
                     format!("vsock://{}:{}/{}?{}", self.cid, self.port, path, query).parse()?;
                 let builder = make_builder("application/x-www-form-urlencoded", &url);
index 89706e7945cf278746567de14fb13f848dd860cb..d2a5b82d60b4ef3b127c8934160ca621fbc5307b 100644 (file)
@@ -1,47 +1,5 @@
-use anyhow::{bail, format_err, Error};
+use anyhow::{bail, Error};
 use serde_json::Value;
-pub fn json_object_to_query(data: Value) -> Result<String, Error> {
-    let mut query = url::form_urlencoded::Serializer::new(String::new());
-
-    let object = data.as_object().ok_or_else(|| {
-        format_err!("json_object_to_query: got wrong data type (expected object).")
-    })?;
-
-    for (key, value) in object {
-        match value {
-            Value::Bool(b) => {
-                query.append_pair(key, &b.to_string());
-            }
-            Value::Number(n) => {
-                query.append_pair(key, &n.to_string());
-            }
-            Value::String(s) => {
-                query.append_pair(key, s);
-            }
-            Value::Array(arr) => {
-                for element in arr {
-                    match element {
-                        Value::Bool(b) => {
-                            query.append_pair(key, &b.to_string());
-                        }
-                        Value::Number(n) => {
-                            query.append_pair(key, &n.to_string());
-                        }
-                        Value::String(s) => {
-                            query.append_pair(key, s);
-                        }
-                        _ => bail!(
-                            "json_object_to_query: unable to handle complex array data types."
-                        ),
-                    }
-                }
-            }
-            _ => bail!("json_object_to_query: unable to handle complex data types."),
-        }
-    }
-
-    Ok(query.finish())
-}
 
 pub fn required_string_param<'a>(param: &'a Value, name: &str) -> Result<&'a str, Error> {
     match param[name].as_str() {
index 14b95f30bf280d91d5d34477febd3523cbd27a4a..0cc112dc95ad95a208e74d778edd7a08275150cc 100644 (file)
@@ -7,10 +7,9 @@ use serde_json::json;
 use proxmox_schema::api;
 
 use proxmox_http::client::SimpleHttp;
+use proxmox_http::uri::json_object_to_query;
 use proxmox_sys::fs::{replace_file, CreateOptions};
 
-use pbs_tools::json::json_object_to_query;
-
 use crate::config::node;
 use crate::tools::{self, pbs_simple_http};