From f4c4cc91c04cdd1afa11722c360b36255bbb2b2f Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Thu, 24 Aug 2023 14:02:46 +0800 Subject: [PATCH] drop Arc in egress path json value --- Cargo.lock | 8 ++++---- g3proxy/src/config/auth/user/json.rs | 4 +--- g3proxy/src/config/auth/user/yaml.rs | 3 +-- lib/g3-types/src/route/egress_path.rs | 11 ++++------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e97a8b5..04e43637 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,9 +585,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erased-serde" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc978899517288e3ebbd1a3bfc1d9537dbb87eeab149e53ea490e63bcdff561a" +checksum = "837c0466252947ada828b975e12daf82e18bb5444e4df87be6038d4469e2a3d2" dependencies = [ "serde", ] @@ -2457,9 +2457,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b83c2a964b8b68e6c9c616f09b735b436a78843704fa6979a076073e622f69dc" +checksum = "e13f81c9a9d574310b8351f8666f5a93ac3b0069c45c28ad52c10291389a7cf9" dependencies = [ "bytes", "rand", diff --git a/g3proxy/src/config/auth/user/json.rs b/g3proxy/src/config/auth/user/json.rs index 42ec3e2b..c207b145 100644 --- a/g3proxy/src/config/auth/user/json.rs +++ b/g3proxy/src/config/auth/user/json.rs @@ -14,8 +14,6 @@ * limitations under the License. */ -use std::sync::Arc; - use anyhow::{anyhow, Context}; use serde_json::{Map, Value}; @@ -208,7 +206,7 @@ impl UserConfig { .parse_json(v) .context(format!("invalid user audit config value for key {k}")), "egress_path" => { - self.egress_path_selection = EgressPathSelection::JsonValue(Arc::new(v.clone())); + self.egress_path_selection = EgressPathSelection::JsonValue(v.clone()); Ok(()) } _ => Err(anyhow!("invalid key {k}")), diff --git a/g3proxy/src/config/auth/user/yaml.rs b/g3proxy/src/config/auth/user/yaml.rs index eb6b2132..d8a7ca83 100644 --- a/g3proxy/src/config/auth/user/yaml.rs +++ b/g3proxy/src/config/auth/user/yaml.rs @@ -15,7 +15,6 @@ */ use std::str::FromStr; -use std::sync::Arc; use anyhow::{anyhow, Context}; use yaml_rust::{yaml, Yaml}; @@ -210,7 +209,7 @@ impl UserConfig { if let Yaml::String(s) = v { let v = serde_json::Value::from_str(s) .map_err(|e| anyhow!("invalid json string value for key {k}: {e}"))?; - self.egress_path_selection = EgressPathSelection::JsonValue(Arc::new(v)); + self.egress_path_selection = EgressPathSelection::JsonValue(v); Ok(()) } else { Err(anyhow!("invalid json string value for key {k}")) diff --git a/lib/g3-types/src/route/egress_path.rs b/lib/g3-types/src/route/egress_path.rs index 86c19bab..8dff1244 100644 --- a/lib/g3-types/src/route/egress_path.rs +++ b/lib/g3-types/src/route/egress_path.rs @@ -15,7 +15,6 @@ */ use std::str::FromStr; -use std::sync::Arc; #[cfg(feature = "json")] use serde_json::Value; @@ -26,7 +25,7 @@ pub enum EgressPathSelection { Default, Index(usize), #[cfg(feature = "json")] - JsonValue(Arc), + JsonValue(Value), } impl EgressPathSelection { @@ -51,11 +50,9 @@ impl EgressPathSelection { #[cfg(feature = "json")] pub fn select_json_value_by_key(&self, key: &str) -> Option<&Value> { - if let EgressPathSelection::JsonValue(v) = self { - if let Value::Object(map) = v.as_ref() { - if let Some(v) = map.get(key) { - return Some(v); - } + if let EgressPathSelection::JsonValue(Value::Object(map)) = self { + if let Some(v) = map.get(key) { + return Some(v); } } None