From 40ad2a6ea9e6e3fd7d8af92bdcdd266134c481c3 Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 5 Jan 2026 23:18:08 +0800 Subject: [PATCH] Remove unused crates (#1394) --- Cargo.lock | 4 ---- crates/config/src/constants/app.rs | 6 ------ crates/credentials/src/constants.rs | 8 ++++---- crates/credentials/src/credentials.rs | 16 ++++++++-------- crates/ecstore/src/rpc/http_auth.rs | 23 ++++++++++++----------- crates/lock/Cargo.toml | 3 --- crates/protos/Cargo.toml | 3 +-- 7 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90501109..e356e602 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8130,11 +8130,9 @@ name = "rustfs-lock" version = "0.0.5" dependencies = [ "async-trait", - "bytes", "crossbeam-queue", "futures", "parking_lot", - "rustfs-protos", "serde", "serde_json", "smallvec", @@ -8143,7 +8141,6 @@ dependencies = [ "tokio", "tonic", "tracing", - "url", "uuid", ] @@ -8269,7 +8266,6 @@ dependencies = [ "flatbuffers", "prost 0.14.1", "rustfs-common", - "rustfs-credentials", "tonic", "tonic-prost", "tonic-prost-build", diff --git a/crates/config/src/constants/app.rs b/crates/config/src/constants/app.rs index 0b2035e4..a38affec 100644 --- a/crates/config/src/constants/app.rs +++ b/crates/config/src/constants/app.rs @@ -170,12 +170,6 @@ pub const KI_B: usize = 1024; /// Default value: 1048576 pub const MI_B: usize = 1024 * 1024; -/// Environment variable for gRPC authentication token -/// Used to set the authentication token for gRPC communication -/// Example: RUSTFS_GRPC_AUTH_TOKEN=your_token_here -/// Default value: No default value. RUSTFS_SECRET_KEY value is recommended. -pub const ENV_GRPC_AUTH_TOKEN: &str = "RUSTFS_GRPC_AUTH_TOKEN"; - #[cfg(test)] mod tests { use super::*; diff --git a/crates/credentials/src/constants.rs b/crates/credentials/src/constants.rs index 442e2833..b73968bf 100644 --- a/crates/credentials/src/constants.rs +++ b/crates/credentials/src/constants.rs @@ -27,11 +27,11 @@ pub const DEFAULT_ACCESS_KEY: &str = "rustfsadmin"; /// Example: --secret-key rustfsadmin pub const DEFAULT_SECRET_KEY: &str = "rustfsadmin"; -/// Environment variable for gRPC authentication token -/// Used to set the authentication token for gRPC communication -/// Example: RUSTFS_GRPC_AUTH_TOKEN=your_token_here +/// Environment variable for RPC authentication token +/// Used to set the authentication token for RPC communication +/// Example: RUSTFS_RPC_SECRET=your_token_here /// Default value: No default value. RUSTFS_SECRET_KEY value is recommended. -pub const ENV_GRPC_AUTH_TOKEN: &str = "RUSTFS_GRPC_AUTH_TOKEN"; +pub const ENV_RPC_SECRET: &str = "RUSTFS_RPC_SECRET"; /// IAM Policy Types /// Used to differentiate between embedded and inherited policies diff --git a/crates/credentials/src/credentials.rs b/crates/credentials/src/credentials.rs index 34aa0fe9..16990599 100644 --- a/crates/credentials/src/credentials.rs +++ b/crates/credentials/src/credentials.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{DEFAULT_SECRET_KEY, ENV_GRPC_AUTH_TOKEN, IAM_POLICY_CLAIM_NAME_SA, INHERITED_POLICY_TYPE}; +use crate::{DEFAULT_SECRET_KEY, ENV_RPC_SECRET, IAM_POLICY_CLAIM_NAME_SA, INHERITED_POLICY_TYPE}; use rand::{Rng, RngCore}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -25,8 +25,8 @@ use time::OffsetDateTime; /// Global active credentials static GLOBAL_ACTIVE_CRED: OnceLock = OnceLock::new(); -/// Global gRPC authentication token -static GLOBAL_GRPC_AUTH_TOKEN: OnceLock = OnceLock::new(); +/// Global RPC authentication token +pub static GLOBAL_RUSTFS_RPC_SECRET: OnceLock = OnceLock::new(); /// Initialize the global action credentials /// @@ -181,15 +181,15 @@ pub fn gen_secret_key(length: usize) -> std::io::Result { Ok(key_str) } -/// Get the gRPC authentication token from environment variable +/// Get the RPC authentication token from environment variable /// /// # Returns -/// * `String` - The gRPC authentication token +/// * `String` - The RPC authentication token /// -pub fn get_grpc_token() -> String { - GLOBAL_GRPC_AUTH_TOKEN +pub fn get_rpc_token() -> String { + GLOBAL_RUSTFS_RPC_SECRET .get_or_init(|| { - env::var(ENV_GRPC_AUTH_TOKEN) + env::var(ENV_RPC_SECRET) .unwrap_or_else(|_| get_global_secret_key_opt().unwrap_or_else(|| DEFAULT_SECRET_KEY.to_string())) }) .clone() diff --git a/crates/ecstore/src/rpc/http_auth.rs b/crates/ecstore/src/rpc/http_auth.rs index 525ecda2..e974e79b 100644 --- a/crates/ecstore/src/rpc/http_auth.rs +++ b/crates/ecstore/src/rpc/http_auth.rs @@ -15,11 +15,8 @@ use base64::Engine as _; use base64::engine::general_purpose; use hmac::{Hmac, KeyInit, Mac}; -use http::HeaderMap; -use http::HeaderValue; -use http::Method; -use http::Uri; -use rustfs_credentials::get_global_action_cred; +use http::{HeaderMap, HeaderValue, Method, Uri}; +use rustfs_credentials::{DEFAULT_SECRET_KEY, ENV_RPC_SECRET, get_global_secret_key_opt}; use sha2::Sha256; use time::OffsetDateTime; use tracing::error; @@ -33,12 +30,16 @@ pub const TONIC_RPC_PREFIX: &str = "/node_service.NodeService"; /// Get the shared secret for HMAC signing fn get_shared_secret() -> String { - if let Some(cred) = get_global_action_cred() { - cred.secret_key - } else { - // Fallback to environment variable if global credentials are not available - std::env::var("RUSTFS_RPC_SECRET").unwrap_or_else(|_| "rustfs-default-secret".to_string()) - } + rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET + .get_or_init(|| { + rustfs_utils::get_env_str( + ENV_RPC_SECRET, + get_global_secret_key_opt() + .unwrap_or_else(|| DEFAULT_SECRET_KEY.to_string()) + .as_str(), + ) + }) + .clone() } /// Generate HMAC-SHA256 signature for the given data diff --git a/crates/lock/Cargo.toml b/crates/lock/Cargo.toml index f574b685..ed0dd829 100644 --- a/crates/lock/Cargo.toml +++ b/crates/lock/Cargo.toml @@ -30,15 +30,12 @@ workspace = true [dependencies] async-trait.workspace = true -bytes.workspace = true futures.workspace = true -rustfs-protos.workspace = true serde.workspace = true serde_json.workspace = true tokio.workspace = true tonic.workspace = true tracing.workspace = true -url.workspace = true uuid.workspace = true thiserror.workspace = true parking_lot.workspace = true diff --git a/crates/protos/Cargo.toml b/crates/protos/Cargo.toml index 29ada67a..f0c7bd2a 100644 --- a/crates/protos/Cargo.toml +++ b/crates/protos/Cargo.toml @@ -34,10 +34,9 @@ path = "src/main.rs" [dependencies] rustfs-common.workspace = true -rustfs-credentials = { workspace = true } flatbuffers = { workspace = true } prost = { workspace = true } tonic = { workspace = true, features = ["transport"] } tonic-prost = { workspace = true } tonic-prost-build = { workspace = true } -tracing = { workspace = true } \ No newline at end of file +tracing = { workspace = true }