refactor(runtime): guard rpc secret global (#4043)

This commit is contained in:
Zhengchao An
2026-06-29 14:02:03 +08:00
committed by GitHub
parent 6093eb0c9c
commit 4567f6f521
4 changed files with 20 additions and 2 deletions
+5 -1
View File
@@ -30,7 +30,7 @@ use time::OffsetDateTime;
static GLOBAL_ACTIVE_CRED: OnceLock<Credentials> = OnceLock::new();
/// Global RPC authentication token
pub static GLOBAL_RUSTFS_RPC_SECRET: OnceLock<String> = OnceLock::new();
static GLOBAL_RUSTFS_RPC_SECRET: OnceLock<String> = OnceLock::new();
/// Public error returned when RPC authentication is not safely configured.
pub const RPC_SECRET_REQUIRED_MESSAGE: &str = "RPC authentication secret is not configured";
@@ -264,6 +264,10 @@ fn resolve_rpc_secret(env_secret: Option<&str>, global_access: Option<&str>, glo
}
}
pub fn set_global_rpc_secret(secret: String) -> Result<(), String> {
GLOBAL_RUSTFS_RPC_SECRET.set(secret)
}
pub fn try_get_rpc_token() -> std::io::Result<String> {
if let Some(secret) = GLOBAL_RUSTFS_RPC_SECRET.get() {
return normalize_rpc_secret(secret).ok_or_else(|| Error::other(RPC_SECRET_REQUIRED_MESSAGE));