feat: add osssendfile-rs
This commit is contained in:
1725
osssendfile-rs/Cargo.lock
generated
Normal file
1725
osssendfile-rs/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
osssendfile-rs/Cargo.toml
Normal file
13
osssendfile-rs/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "osssendfile-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
aes-gcm-stream = "0.2"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
reqwest = "0.12"
|
||||
rust_util = "0.6.47"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.39", features = ["full"] }
|
||||
74
osssendfile-rs/src/main.rs
Normal file
74
osssendfile-rs/src/main.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use clap::Parser;
|
||||
use rust_util::{opt_result, opt_value_result, util_file, XResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct OssSendFileConfig {
|
||||
endpoint: String,
|
||||
bucket: String,
|
||||
token: String,
|
||||
oidc: OidcConfig,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct OidcConfig {
|
||||
sub: String,
|
||||
client_id: String,
|
||||
client_secret: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "osssendfile-rs")]
|
||||
#[command(about = "OSS send file Rust edition", long_about = None)]
|
||||
struct OssSendFileArgs {
|
||||
/// Config file, default location: ~/.jssp/config/osssendfile.json
|
||||
#[arg(long)]
|
||||
config: Option<String>,
|
||||
/// Do not encrypt
|
||||
#[arg(long)]
|
||||
noenc: bool,
|
||||
/// Do remove source file
|
||||
#[arg(long)]
|
||||
removesourcefile: bool,
|
||||
/// JWK
|
||||
#[arg(long)]
|
||||
jwk: Option<String>,
|
||||
/// Upload file path
|
||||
#[arg(long)]
|
||||
file: PathBuf,
|
||||
/// File name, default use local file name
|
||||
#[arg(long)]
|
||||
filename: Option<String>,
|
||||
/// Keywords
|
||||
#[arg(long)]
|
||||
keywords: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> XResult<()> {
|
||||
let args = OssSendFileArgs::parse();
|
||||
let oss_send_file_config = load_config(&args.config)?;
|
||||
|
||||
println!("{:?}", args);
|
||||
println!("{:?}", oss_send_file_config);
|
||||
|
||||
// TODO ...
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_config(config: &Option<String>) -> XResult<OssSendFileConfig> {
|
||||
let config_file_opt = util_file::read_config(
|
||||
config.clone(),
|
||||
&["~/.jssp/config/osssendfile.json".to_string()],
|
||||
);
|
||||
let config_file = opt_value_result!(config_file_opt, "Config file not found.");
|
||||
let config = opt_result!(
|
||||
fs::read_to_string(&config_file), "Read file: {:?} failed: {}", config_file);
|
||||
let oss_send_config: OssSendFileConfig = opt_result!(
|
||||
serde_json::from_str(&config), "Parse file: {:?} failed: {}", config_file);
|
||||
Ok(oss_send_config)
|
||||
}
|
||||
Reference in New Issue
Block a user