update config_util.rs
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
{
|
||||
"oss_config": {
|
||||
"endpoint": "",
|
||||
"access_key_id": "",
|
||||
"access_key_secret": "",
|
||||
"bucket": "",
|
||||
"path": ""
|
||||
"endpoint": "_endpoint",
|
||||
"access_key_id": "_keyid",
|
||||
"access_key_secret": "_keysecret",
|
||||
"bucket": "_bucket",
|
||||
"path": "_path"
|
||||
},
|
||||
"host": "sample_host",
|
||||
"encrypt_pubkey_file": "",
|
||||
"encrypt_pubkey_file": "_enc",
|
||||
"items": [
|
||||
{
|
||||
"oss_config": null,
|
||||
"target": "",
|
||||
"file_name": "sample_file",
|
||||
"file_name": "sample_file"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,6 @@ use rust_util::{
|
||||
util_msg::*,
|
||||
};
|
||||
use chrono::{
|
||||
prelude::*,
|
||||
Utc,
|
||||
};
|
||||
|
||||
@@ -38,6 +37,7 @@ pub const DOT_OSS_BACKUPD_CONFIG: &str = ".oss-backupd-config.json";
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OSSConfig {
|
||||
pub endpoint: Option<String>,
|
||||
pub access_key_id: Option<String>,
|
||||
@@ -46,6 +46,7 @@ pub struct OSSConfig {
|
||||
pub path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OSSBackupdConfigItem {
|
||||
pub target: Option<String>,
|
||||
pub file_name: Option<String>,
|
||||
@@ -53,6 +54,7 @@ pub struct OSSBackupdConfigItem {
|
||||
pub encrypt_pubkey_file: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OSSBackupdConfig {
|
||||
pub oss_config: Option<OSSConfig>,
|
||||
pub prefix: Option<String>,
|
||||
@@ -127,28 +129,33 @@ pub fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_obj
|
||||
let file_name = get_string_value(item, "file_name");
|
||||
let mut encrypt_pubkey_file = get_string_value(item, "encrypt_pubkey_file");
|
||||
let mut oss_config = parse_sub_oss_config(item);
|
||||
if oss_config.is_some() && root_oss_config_object.is_some() {
|
||||
let mut oc = oss_config.unwrap();
|
||||
let root_oc = root_oss_config_object.as_ref().unwrap();
|
||||
if root_oss_config_object.is_some() {
|
||||
if oss_config.is_some() {
|
||||
let mut oc = oss_config.unwrap();
|
||||
let root_oc = root_oss_config_object.as_ref().unwrap();
|
||||
|
||||
if oc.endpoint.is_none() && root_oc.endpoint.is_some() {
|
||||
oc.endpoint = root_oc.endpoint.clone()
|
||||
if oc.endpoint.is_none() && root_oc.endpoint.is_some() {
|
||||
oc.endpoint = root_oc.endpoint.clone()
|
||||
}
|
||||
if oc.access_key_id.is_none() && root_oc.access_key_id.is_some() {
|
||||
oc.access_key_id = root_oc.access_key_id.clone()
|
||||
}
|
||||
if oc.access_key_secret.is_none() && root_oc.access_key_secret.is_some() {
|
||||
oc.access_key_secret = root_oc.access_key_secret.clone();
|
||||
}
|
||||
if oc.bucket.is_none() && root_oc.bucket.is_some() {
|
||||
oc.bucket = root_oc.bucket.clone();
|
||||
}
|
||||
if oc.path.is_none() && root_oc.path.is_some() {
|
||||
oc.path = root_oc.path.clone();
|
||||
}
|
||||
oss_config = Some(oc);
|
||||
} else {
|
||||
oss_config = root_oss_config_object.clone();
|
||||
}
|
||||
if oc.access_key_id.is_none() && root_oc.access_key_id.is_some() {
|
||||
oc.access_key_id = root_oc.access_key_id.clone()
|
||||
}
|
||||
if oc.access_key_secret.is_none() && root_oc.access_key_secret.is_some() {
|
||||
oc.access_key_secret = root_oc.access_key_secret.clone();
|
||||
}
|
||||
if oc.bucket.is_none() && root_oc.bucket.is_some() {
|
||||
oc.bucket = root_oc.bucket.clone();
|
||||
}
|
||||
if oc.path.is_none() && root_oc.path.is_some() {
|
||||
oc.path = root_oc.path.clone();
|
||||
}
|
||||
oss_config = Some(oc);
|
||||
}
|
||||
|
||||
|
||||
if encrypt_pubkey_file.is_none() && root_encrypt_pubkey_file.is_some() {
|
||||
encrypt_pubkey_file = root_encrypt_pubkey_file.clone();
|
||||
}
|
||||
|
||||
23
src/main.rs
23
src/main.rs
@@ -9,7 +9,8 @@ use std::{
|
||||
use rust_util::{
|
||||
XResult,
|
||||
};
|
||||
use pgp_util::OpenPGPTool;
|
||||
use config_util::*;
|
||||
// use pgp_util::OpenPGPTool;
|
||||
|
||||
// https://docs.sequoia-pgp.org/sequoia_openpgp/serialize/stream/struct.Encryptor.html
|
||||
// https://gitlab.com/sequoia-pgp/sequoia/blob/master/openpgp/examples/generate-encrypt-decrypt.rs
|
||||
@@ -18,9 +19,25 @@ fn main() -> XResult<()> {
|
||||
|
||||
println!("{}", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
|
||||
|
||||
let openpgp_client = OpenPGPTool::from_file("sample.gpg")?;
|
||||
// let openpgp_client = OpenPGPTool::from_file("sample.gpg")?;
|
||||
|
||||
openpgp_client.encrypt_file("a", "b.gpg", false)?;
|
||||
// openpgp_client.encrypt_file("a", "b.gpg", false)?;
|
||||
|
||||
let config_json = get_config_json();
|
||||
|
||||
let j = config_json.unwrap();
|
||||
|
||||
println!("{}", j);
|
||||
|
||||
let c = parse_config(&j);
|
||||
|
||||
println!("{:?}", c);
|
||||
|
||||
println!("");
|
||||
|
||||
for i in c.items {
|
||||
println!("{:?}", i);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user