add verbose
This commit is contained in:
@@ -124,7 +124,7 @@ pub fn parse_config(config_json: &json::JsonValue) -> OSSBackupdConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_object: &Option<OSSConfig>, root_encrypt_pubkey_file: &Option<String>) -> OSSBackupdConfigItem {
|
||||
fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_object: &Option<OSSConfig>, root_encrypt_pubkey_file: &Option<String>) -> OSSBackupdConfigItem {
|
||||
let target = get_string_value(item, "target");
|
||||
let file_name = get_string_value(item, "file_name");
|
||||
let mut encrypt_pubkey_file = get_string_value(item, "encrypt_pubkey_file");
|
||||
@@ -168,7 +168,7 @@ pub fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_obj
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_sub_oss_config(json: &json::JsonValue) -> Option<OSSConfig> {
|
||||
fn parse_sub_oss_config(json: &json::JsonValue) -> Option<OSSConfig> {
|
||||
let root_oss_config = &json["oss_config"];
|
||||
let root_oss_config_object: Option<OSSConfig> = match root_oss_config.is_null() {
|
||||
true => None,
|
||||
@@ -177,7 +177,7 @@ pub fn parse_sub_oss_config(json: &json::JsonValue) -> Option<OSSConfig> {
|
||||
root_oss_config_object
|
||||
}
|
||||
|
||||
pub fn parse_oss_config(oss_config: &json::JsonValue) -> OSSConfig {
|
||||
fn parse_oss_config(oss_config: &json::JsonValue) -> OSSConfig {
|
||||
OSSConfig {
|
||||
endpoint: get_string_value(oss_config, "endpoint"),
|
||||
access_key_id: get_string_value(oss_config, "access_key_id"),
|
||||
@@ -195,8 +195,8 @@ pub fn get_string_value(json: &json::JsonValue, key: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_json(custom_oss_backupd_config: Option<&str>) -> Option<json::JsonValue> {
|
||||
let config_content = get_config_content(custom_oss_backupd_config)?;
|
||||
pub fn get_config_json(custom_oss_backupd_config: Option<&str>, verbose: bool) -> Option<json::JsonValue> {
|
||||
let config_content = get_config_content(custom_oss_backupd_config, verbose)?;
|
||||
match json::parse(&config_content) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Parse config json failed: {}", e));
|
||||
@@ -206,9 +206,12 @@ pub fn get_config_json(custom_oss_backupd_config: Option<&str>) -> Option<json::
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<String> {
|
||||
fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) -> Option<String> {
|
||||
if custom_oss_backupd_config.is_some() {
|
||||
let custom_oss_backupd_config_unrwaped = custom_oss_backupd_config.unwrap();
|
||||
if verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Read config from: {}", custom_oss_backupd_config_unrwaped));
|
||||
}
|
||||
let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_unrwaped);
|
||||
if custom_oss_backupd_config_path.exists() {
|
||||
match fs::read_to_string(custom_oss_backupd_config_path) {
|
||||
@@ -226,6 +229,9 @@ pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<Str
|
||||
// is not assigned by -c or --conifg FILE
|
||||
let oss_backupd_config_path = Path::new(OSS_BACKUPD_CONFIG);
|
||||
if oss_backupd_config_path.exists() {
|
||||
if verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Read config from: {}", OSS_BACKUPD_CONFIG));
|
||||
}
|
||||
match fs::read_to_string(oss_backupd_config_path) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", OSS_BACKUPD_CONFIG, e));
|
||||
@@ -244,6 +250,9 @@ pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<Str
|
||||
if home_dot_oss_backupd_config != "" {
|
||||
let home_dot_oss_backupd_config_path = Path::new(home_dot_oss_backupd_config);
|
||||
if home_dot_oss_backupd_config_path.exists() {
|
||||
if verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Read config from: {}", home_dot_oss_backupd_config));
|
||||
}
|
||||
match fs::read_to_string(home_dot_oss_backupd_config_path) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", home_dot_oss_backupd_config, e));
|
||||
@@ -255,6 +264,9 @@ pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<Str
|
||||
}
|
||||
let etc_oss_backupd_config_path = Path::new(ETC_OSS_BACKUPD_CONFIG);
|
||||
if etc_oss_backupd_config_path.exists() {
|
||||
if verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Read config from: {}", ETC_OSS_BACKUPD_CONFIG));
|
||||
}
|
||||
match fs::read_to_string(etc_oss_backupd_config_path) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", ETC_OSS_BACKUPD_CONFIG, e));
|
||||
|
||||
20
src/main.rs
20
src/main.rs
@@ -36,11 +36,9 @@ fn main() -> XResult<()> {
|
||||
println!("Hello, world!");
|
||||
println!("{}", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
|
||||
|
||||
let oss_client = OSSClient::new("oss-cn-shanghai.aliyuncs.com", "", "");
|
||||
|
||||
let c = oss_client.get_file_content("hatterbucket", "Check.java")?;
|
||||
|
||||
println!("XXXXX: {:?}", c);
|
||||
// let oss_client = OSSClient::new("oss-cn-shanghai.aliyuncs.com", "", "");
|
||||
// let c = oss_client.get_file_content("hatterbucket", "Check.java")?;
|
||||
// println!("XXXXX: {:?}", c);
|
||||
// println!("XXXXX: {}", );
|
||||
|
||||
// zip_util::zip_file("hello.txt", "aa.zip")?;
|
||||
@@ -48,10 +46,14 @@ fn main() -> XResult<()> {
|
||||
// let openpgp_client = OpenPGPTool::from_file("sample.gpg")?;
|
||||
// openpgp_client.encrypt_file("a", "b.asc", true)?;
|
||||
|
||||
let config_json = get_config_json(if options.config == "" { None } else { Some(&options.config) });
|
||||
if config_json.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
let config_json = match get_config_json(if options.config == "" { None } else { Some(&options.config) }, options.verbose) {
|
||||
None => return Ok(()),
|
||||
Some(c) => c,
|
||||
};
|
||||
|
||||
let oss_backupd_config = parse_config(&config_json);
|
||||
|
||||
println!("{:?}", &oss_backupd_config);
|
||||
|
||||
// TODO ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user