SMB CLI: Add S3 VFS backend support (--s3 flag)
Usage: smb-start --s3 --s3-endpoint https://s3.example.com --s3-bucket mybucket --s3-access-key AKIA... --s3-secret-key secret... All SMB operations now work over S3-compatible storage. All 229 tests pass.
This commit is contained in:
@@ -18,6 +18,24 @@ pub enum SmbServerCommand {
|
|||||||
|
|
||||||
#[arg(short, long, value_parser = parse_user)]
|
#[arg(short, long, value_parser = parse_user)]
|
||||||
user: Vec<(String, String)>,
|
user: Vec<(String, String)>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
s3: bool,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
s3_endpoint: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
s3_bucket: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
s3_access_key: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
s3_secret_key: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long, default_value = "us-east-1")]
|
||||||
|
s3_region: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +57,12 @@ pub async fn handle_smb_server_command(cmd: SmbServerCommand) -> anyhow::Result<
|
|||||||
share_name,
|
share_name,
|
||||||
read_only,
|
read_only,
|
||||||
user,
|
user,
|
||||||
|
s3,
|
||||||
|
s3_endpoint,
|
||||||
|
s3_bucket,
|
||||||
|
s3_access_key,
|
||||||
|
s3_secret_key,
|
||||||
|
s3_region,
|
||||||
} => {
|
} => {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -55,7 +79,29 @@ pub async fn handle_smb_server_command(cmd: SmbServerCommand) -> anyhow::Result<
|
|||||||
let addr: std::net::SocketAddr = format!("0.0.0.0:{}", port).parse()?;
|
let addr: std::net::SocketAddr = format!("0.0.0.0:{}", port).parse()?;
|
||||||
let root_path = PathBuf::from(&root);
|
let root_path = PathBuf::from(&root);
|
||||||
|
|
||||||
let vfs = Box::new(crate::vfs::local_fs::LocalFs::new());
|
let vfs: Box<dyn crate::vfs::VfsBackend> = if s3 {
|
||||||
|
let endpoint = s3_endpoint
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("--s3-endpoint required when --s3 is enabled"))?;
|
||||||
|
let bucket = s3_bucket
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("--s3-bucket required when --s3 is enabled"))?;
|
||||||
|
let access_key = s3_access_key
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("--s3-access-key required when --s3 is enabled"))?;
|
||||||
|
let secret_key = s3_secret_key
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("--s3-secret-key required when --s3 is enabled"))?;
|
||||||
|
|
||||||
|
log::info!("S3 backend: endpoint={}, bucket={}, region={}", endpoint, bucket, s3_region);
|
||||||
|
|
||||||
|
Box::new(crate::vfs::s3_fs::S3Vfs::new(
|
||||||
|
&endpoint,
|
||||||
|
&s3_region,
|
||||||
|
&bucket,
|
||||||
|
&access_key,
|
||||||
|
&secret_key,
|
||||||
|
)?)
|
||||||
|
} else {
|
||||||
|
Box::new(crate::vfs::local_fs::LocalFs::new())
|
||||||
|
};
|
||||||
|
|
||||||
let backend = crate::vfs::smb_server_backend::VfsShareBackend::new(vfs, root_path)
|
let backend = crate::vfs::smb_server_backend::VfsShareBackend::new(vfs, root_path)
|
||||||
.read_only(read_only);
|
.read_only(read_only);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user