fix service account action, add console config api

This commit is contained in:
weisd
2025-02-23 15:06:13 +08:00
parent e87cc87cbf
commit 19d897a40b
10 changed files with 61 additions and 30 deletions
+2 -1
View File
@@ -42,6 +42,7 @@ impl Operation for AddServiceAccount {
let mut create_req: AddServiceAccountReq =
serde_json::from_slice(&body[..]).map_err(|e| s3_error!(InvalidRequest, "unmarshal body failed, e: {:?}", e))?;
create_req.expiration = create_req.expiration.and_then(|expire| expire.replace_millisecond(0).ok());
if has_space_be(&create_req.access_key) {
@@ -128,7 +129,7 @@ impl Operation for AddServiceAccount {
.await
.map_err(|e| {
debug!("create service account failed, e: {:?}", e);
s3_error!(InternalError, "create service account failed")
s3_error!(InternalError, "create service account failed, e: {:?}", e)
})?;
let resp = AddServiceAccountResp {
+1 -1
View File
@@ -35,7 +35,7 @@ const LONG_VERSION: &str = concat!(
#[command(version = SHORT_VERSION, long_version = LONG_VERSION)]
pub struct Opt {
/// DIR points to a directory on a filesystem.
#[arg(required = true)]
#[arg(required = true, env = "RUSTFS_VOLUMES")]
pub volumes: Vec<String>,
/// bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname
+20 -2
View File
@@ -7,6 +7,7 @@ use axum::{
};
use include_dir::{include_dir, Dir};
use serde::Serialize;
static STATIC_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/static");
@@ -25,9 +26,26 @@ async fn static_handler(uri: axum::http::Uri) -> impl IntoResponse {
}
}
pub async fn start_static_file_server(addrs: &str) {
#[derive(Debug, Clone, Serialize)]
struct Config {
fs_addr: String,
}
async fn config_handler(axum::extract::Extension(fs_addr): axum::extract::Extension<String>) -> impl IntoResponse {
let cfg = serde_json::to_string(&Config { fs_addr }).unwrap_or_default();
Response::builder()
.header("content-type", "application/json")
.status(StatusCode::OK)
.body(Body::from(cfg))
.unwrap()
}
pub async fn start_static_file_server(addrs: &str, fs_addr: &str) {
// 创建路由
let app = Router::new().route("/*file", get(static_handler));
let app = Router::new()
.route("/config.json", get(config_handler).layer(axum::extract::Extension(fs_addr.to_string())))
.route("/*file", get(static_handler));
let listener = tokio::net::TcpListener::bind(addrs).await.unwrap();
+1 -1
View File
@@ -234,7 +234,7 @@ async fn run(opt: config::Opt) -> Result<()> {
if opt.console_enable {
info!("console is enabled");
tokio::spawn(async move {
console::start_static_file_server(&opt.console_address).await;
console::start_static_file_server(&opt.console_address, &opt.address).await;
});
}