From e2329d96a605dd607aebfe7e027745e0730449f5 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 22 Aug 2024 00:15:55 +0800 Subject: [PATCH] feat: update osssendfile-rs --- osssendfile-rs/src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/osssendfile-rs/src/main.rs b/osssendfile-rs/src/main.rs index 98caba3..ff5730d 100644 --- a/osssendfile-rs/src/main.rs +++ b/osssendfile-rs/src/main.rs @@ -1,9 +1,13 @@ use clap::Parser; use rust_util::{opt_result, opt_value_result, util_file, XResult}; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::fs; use std::path::PathBuf; +const OSS_SEND_FILE_CONFIG_FILE: &str = "~/.jssp/config/osssendfile.json"; +const CREATE_STS_URL: &str = "https://hatter.ink/oidc/create_sts.json"; + #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct OssSendFileConfig { @@ -48,13 +52,25 @@ struct OssSendFileArgs { keywords: Option, } -fn main() -> XResult<()> { +#[tokio::main] +async fn main() -> XResult<()> { let args = OssSendFileArgs::parse(); let oss_send_file_config = load_config(&args.config)?; println!("{:?}", args); println!("{:?}", oss_send_file_config); + let client = reqwest::Client::new(); + + let mut params = HashMap::new(); + params.insert("client_id", &oss_send_file_config.oidc.client_id); + params.insert("client_secret", &oss_send_file_config.oidc.client_secret); + params.insert("sub", &oss_send_file_config.oidc.sub); + let response = client.post(CREATE_STS_URL) + .form(¶ms) + .send() + .await?; + // TODO ... Ok(()) @@ -63,7 +79,7 @@ fn main() -> XResult<()> { fn load_config(config: &Option) -> XResult { let config_file_opt = util_file::read_config( config.clone(), - &["~/.jssp/config/osssendfile.json".to_string()], + &[OSS_SEND_FILE_CONFIG_FILE.to_string()], ); let config_file = opt_value_result!(config_file_opt, "Config file not found."); let config = opt_result!(