mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(bin) : refactor auth_jwt_secret function (#5451)
This commit is contained in:
committed by
GitHub
parent
187f6faa09
commit
8207401359
@ -10,6 +10,7 @@ use crate::{
|
||||
config::RethRpcConfig,
|
||||
ext::RethNodeCommandConfig,
|
||||
},
|
||||
utils::get_or_create_jwt_secret_from_path,
|
||||
};
|
||||
use clap::{
|
||||
builder::{PossibleValue, RangedU64ValueParser, TypedValueParser},
|
||||
@ -449,15 +450,7 @@ impl RethRpcConfig for RpcServerArgs {
|
||||
debug!(target: "reth::cli", user_path=?fpath, "Reading JWT auth secret file");
|
||||
JwtSecret::from_file(fpath)
|
||||
}
|
||||
None => {
|
||||
if default_jwt_path.exists() {
|
||||
debug!(target: "reth::cli", ?default_jwt_path, "Reading JWT auth secret file");
|
||||
JwtSecret::from_file(&default_jwt_path)
|
||||
} else {
|
||||
info!(target: "reth::cli", ?default_jwt_path, "Creating JWT auth secret file");
|
||||
JwtSecret::try_create(&default_jwt_path)
|
||||
}
|
||||
}
|
||||
None => get_or_create_jwt_secret_from_path(&default_jwt_path),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,13 +18,14 @@ use reth_interfaces::p2p::{
|
||||
use reth_primitives::{
|
||||
fs, BlockHashOrNumber, ChainSpec, HeadersDirection, SealedBlock, SealedHeader,
|
||||
};
|
||||
use reth_rpc::{JwtError, JwtSecret};
|
||||
use std::{
|
||||
env::VarError,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
use tracing::info;
|
||||
use tracing::{debug, info};
|
||||
|
||||
/// Exposing `open_db_read_only` function
|
||||
pub mod db {
|
||||
@ -247,3 +248,14 @@ impl ListFilter {
|
||||
self.len = len;
|
||||
}
|
||||
}
|
||||
/// Attempts to retrieve or create a JWT secret from the specified path.
|
||||
|
||||
pub fn get_or_create_jwt_secret_from_path(path: &Path) -> Result<JwtSecret, JwtError> {
|
||||
if path.exists() {
|
||||
debug!(target: "reth::cli", ?path, "Reading JWT auth secret file");
|
||||
JwtSecret::from_file(path)
|
||||
} else {
|
||||
info!(target: "reth::cli", ?path, "Creating JWT auth secret file");
|
||||
JwtSecret::try_create(path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user