update config_util.rs
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
{
|
{
|
||||||
"oss_config": {
|
"oss_config": {
|
||||||
"endpoint": "",
|
"endpoint": "_endpoint",
|
||||||
"access_key_id": "",
|
"access_key_id": "_keyid",
|
||||||
"access_key_secret": "",
|
"access_key_secret": "_keysecret",
|
||||||
"bucket": "",
|
"bucket": "_bucket",
|
||||||
"path": ""
|
"path": "_path"
|
||||||
},
|
},
|
||||||
"host": "sample_host",
|
"host": "sample_host",
|
||||||
"encrypt_pubkey_file": "",
|
"encrypt_pubkey_file": "_enc",
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"oss_config": null,
|
|
||||||
"target": "",
|
"target": "",
|
||||||
"file_name": "sample_file",
|
"file_name": "sample_file"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ use rust_util::{
|
|||||||
util_msg::*,
|
util_msg::*,
|
||||||
};
|
};
|
||||||
use chrono::{
|
use chrono::{
|
||||||
prelude::*,
|
|
||||||
Utc,
|
Utc,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,6 +37,7 @@ pub const DOT_OSS_BACKUPD_CONFIG: &str = ".oss-backupd-config.json";
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct OSSConfig {
|
pub struct OSSConfig {
|
||||||
pub endpoint: Option<String>,
|
pub endpoint: Option<String>,
|
||||||
pub access_key_id: Option<String>,
|
pub access_key_id: Option<String>,
|
||||||
@@ -46,6 +46,7 @@ pub struct OSSConfig {
|
|||||||
pub path: Option<String>,
|
pub path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct OSSBackupdConfigItem {
|
pub struct OSSBackupdConfigItem {
|
||||||
pub target: Option<String>,
|
pub target: Option<String>,
|
||||||
pub file_name: Option<String>,
|
pub file_name: Option<String>,
|
||||||
@@ -53,6 +54,7 @@ pub struct OSSBackupdConfigItem {
|
|||||||
pub encrypt_pubkey_file: Option<String>,
|
pub encrypt_pubkey_file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct OSSBackupdConfig {
|
pub struct OSSBackupdConfig {
|
||||||
pub oss_config: Option<OSSConfig>,
|
pub oss_config: Option<OSSConfig>,
|
||||||
pub prefix: Option<String>,
|
pub prefix: Option<String>,
|
||||||
@@ -127,7 +129,8 @@ pub fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_obj
|
|||||||
let file_name = get_string_value(item, "file_name");
|
let file_name = get_string_value(item, "file_name");
|
||||||
let mut encrypt_pubkey_file = get_string_value(item, "encrypt_pubkey_file");
|
let mut encrypt_pubkey_file = get_string_value(item, "encrypt_pubkey_file");
|
||||||
let mut oss_config = parse_sub_oss_config(item);
|
let mut oss_config = parse_sub_oss_config(item);
|
||||||
if oss_config.is_some() && root_oss_config_object.is_some() {
|
if root_oss_config_object.is_some() {
|
||||||
|
if oss_config.is_some() {
|
||||||
let mut oc = oss_config.unwrap();
|
let mut oc = oss_config.unwrap();
|
||||||
let root_oc = root_oss_config_object.as_ref().unwrap();
|
let root_oc = root_oss_config_object.as_ref().unwrap();
|
||||||
|
|
||||||
@@ -147,7 +150,11 @@ pub fn parse_oss_backupd_config_item(item: &json::JsonValue, root_oss_config_obj
|
|||||||
oc.path = root_oc.path.clone();
|
oc.path = root_oc.path.clone();
|
||||||
}
|
}
|
||||||
oss_config = Some(oc);
|
oss_config = Some(oc);
|
||||||
|
} else {
|
||||||
|
oss_config = root_oss_config_object.clone();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if encrypt_pubkey_file.is_none() && root_encrypt_pubkey_file.is_some() {
|
if encrypt_pubkey_file.is_none() && root_encrypt_pubkey_file.is_some() {
|
||||||
encrypt_pubkey_file = root_encrypt_pubkey_file.clone();
|
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::{
|
use rust_util::{
|
||||||
XResult,
|
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://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
|
// 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());
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user