feat: add chrono dependency and enhance console configuration with documentation and version info

This commit is contained in:
DamonXue
2025-03-02 18:53:48 +08:00
parent 79eabe4e4c
commit 7e59bfa877
4 changed files with 61 additions and 14 deletions
+31 -6
View File
@@ -7,11 +7,13 @@ mod service;
mod storage;
mod utils;
use crate::auth::IAMAuth;
use crate::console::{init_console_cfg, CONSOLE_CONFIG};
use clap::Parser;
use common::{
error::{Error, Result},
globals::set_global_addr,
};
use config::{DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY};
use ecstore::heal::background_heal_ops::init_auto_heal;
use ecstore::utils::net::{self, get_available_port};
use ecstore::{
@@ -37,6 +39,7 @@ use tokio::net::TcpListener;
use tonic::{metadata::MetadataValue, Request, Status};
use tower_http::cors::CorsLayer;
use tracing::{debug, error, info, warn};
use chrono::Datelike;
use tracing_error::ErrorLayer;
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};
@@ -69,6 +72,16 @@ fn check_auth(req: Request<()>) -> Result<Request<()>, Status> {
}
}
fn print_server_info() {
let cfg = CONSOLE_CONFIG.get().unwrap();
let current_year = chrono::Utc::now().year();
info!("RustFS Object Storage Server");
info!("Copyright: 2024-{} RustFS, Inc", current_year);
info!("License: {}", cfg.license());
info!("Version: {}", cfg.version());
info!("Docs: {}", cfg.doc())
}
fn main() -> Result<()> {
//解析获得到的参数
let opt = config::Opt::parse();
@@ -133,8 +146,8 @@ async fn run(opt: config::Opt) -> Result<()> {
let api_endpoints = format!("http://{}:{}", local_ip, server_port);
let localhost_endpoint = format!("http://127.0.0.1:{}", server_port);
info!("API: {} {}", api_endpoints, localhost_endpoint);
info!(" RootUser: {}", opt.access_key);
info!(" RootPass: {}", opt.secret_key);
info!(" RootUser: {}", opt.access_key.clone());
info!(" RootPass: {}", opt.secret_key.clone());
for (i, eps) in endpoint_pools.as_ref().iter().enumerate() {
info!(
@@ -160,10 +173,12 @@ async fn run(opt: config::Opt) -> Result<()> {
// let mut b = S3ServiceBuilder::new(storage::ecfs::FS::new(server_address.clone(), endpoint_pools).await?);
let mut b = S3ServiceBuilder::new(store.clone());
let access_key = opt.access_key.clone();
let secret_key = opt.secret_key.clone();
//显示info信息
info!("authentication is enabled {}, {}", &opt.access_key, &opt.secret_key);
debug!("authentication is enabled {}, {}", &access_key, &secret_key);
b.set_auth(IAMAuth::new(opt.access_key, opt.secret_key));
b.set_auth(IAMAuth::new(access_key, secret_key));
b.set_access(store.clone());
@@ -251,7 +266,7 @@ async fn run(opt: config::Opt) -> Result<()> {
error!("ECStore init faild {:?}", &err);
Error::from_string(err.to_string())
})?;
warn!(" init store success!");
debug!("init store success!");
init_iam_sys(store.clone()).await.unwrap();
@@ -265,10 +280,20 @@ async fn run(opt: config::Opt) -> Result<()> {
// init auto heal
init_auto_heal().await;
let srv_addr = format!("http://{}:{}", local_ip, server_port);
init_console_cfg(&srv_addr);
print_server_info();
if DEFAULT_ACCESS_KEY.eq(&opt.access_key) && DEFAULT_SECRET_KEY.eq(&opt.secret_key) {
warn!("Detected default credentials '{}:{}', we recommend that you change these values with 'RUSTFS_ACCESS_KEY' and 'RUSTFS_SECRET_KEY' environment variables", DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY);
}
if opt.console_enable {
debug!("console is enabled");
let access_key = opt.access_key.clone();
let secret_key = opt.secret_key.clone();
let console_address = opt.console_address.clone();
tokio::spawn(async move {
console::start_static_file_server(&opt.console_address, local_ip, server_port).await;
console::start_static_file_server(&console_address, local_ip, &access_key, &secret_key).await;
});
}