feat: v1.2.1, update versions
This commit is contained in:
2067
Cargo.lock
generated
2067
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
34
Cargo.toml
34
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "oss-backupd"
|
name = "oss-backupd"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@@ -13,19 +13,19 @@ use_zip = []
|
|||||||
use_sequoia_openpgp = ["sequoia-openpgp"]
|
use_sequoia_openpgp = ["sequoia-openpgp"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dirs = "2.0.1"
|
dirs = "6.0"
|
||||||
argparse = "0.2.2"
|
argparse = "0.2"
|
||||||
json = "0.11.14"
|
json = "0.12"
|
||||||
hmac = "0.7.1"
|
hmac = "0.12"
|
||||||
sha-1 = "0.8.2"
|
sha-1 = "0.10"
|
||||||
indicatif = "0.13.0"
|
indicatif = "0.17"
|
||||||
urlencoding = "1.0.0"
|
urlencoding = "2.1"
|
||||||
base64 = "0.11.0"
|
base64 = "0.22"
|
||||||
reqwest = "0.9.22"
|
reqwest = { version = "0.12", features = ["blocking", "native-tls-vendored"] }
|
||||||
sequoia-openpgp = { version = "0.16.0", optional = true }
|
sequoia-openpgp = { version = "1.22", optional = true }
|
||||||
chrono = "0.4.10"
|
chrono = "0.4"
|
||||||
zip = "0.5.3"
|
zip = "2.2"
|
||||||
tar = "0.4.26"
|
tar = "0.4"
|
||||||
flate2 = "1.0.14"
|
flate2 = "1.0"
|
||||||
rust_util = "0.6.3"
|
rust_util = "0.6"
|
||||||
tiny-encrypt = { version = "1.8.3", default-features = false }
|
tiny-encrypt = { version = "1.8", default-features = false }
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use std::{
|
|||||||
fs::{ self, File },
|
fs::{ self, File },
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use rust_util::{XResult, util_time::*, util_msg::*};
|
use rust_util::{XResult, util_time::*};
|
||||||
use tiny_encrypt::CmdEncrypt;
|
use tiny_encrypt::CmdEncrypt;
|
||||||
use oss_util::*;
|
use oss_util::*;
|
||||||
use config_util::*;
|
use config_util::*;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use base64::Engine;
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
use hmac::{ Hmac, Mac };
|
use hmac::{ Hmac, Mac };
|
||||||
use reqwest::Response;
|
use reqwest::blocking::{Client, Response};
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
use rust_util::{ XResult, new_box_ioerror, util_time::get_current_secs };
|
use rust_util::{ XResult, new_box_ioerror, util_time::get_current_secs };
|
||||||
|
|
||||||
pub const DEFAULT_URL_VALID_IN_SECS: u64 = 1000;
|
pub const DEFAULT_URL_VALID_IN_SECS: u64 = 1000;
|
||||||
@@ -32,19 +34,20 @@ impl OSSClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult<Response> {
|
pub fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult<Response> {
|
||||||
let client = reqwest::Client::new();
|
let client = Client::new();
|
||||||
Ok(client.put(&self.generate_signed_put_url(bucket_name, key, expire_in_seconds)).body(file).send()?)
|
Ok(client.put(&self.generate_signed_put_url(bucket_name, key, expire_in_seconds)).body(file).send()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_file(&self, bucket_name: &str, key: &str) -> XResult<Response> {
|
pub fn delete_file(&self, bucket_name: &str, key: &str) -> XResult<Response> {
|
||||||
let delete_url = self.generate_signed_delete_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
let delete_url = self.generate_signed_delete_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
||||||
let client = reqwest::Client::new();
|
let client = Client::new();
|
||||||
Ok(client.delete(&delete_url).send()?)
|
Ok(client.delete(&delete_url).send()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_file_content(&self, bucket_name: &str, key: &str) -> XResult<Option<String>> {
|
pub fn get_file_content(&self, bucket_name: &str, key: &str) -> XResult<Option<String>> {
|
||||||
let get_url = self.generate_signed_get_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
let get_url = self.generate_signed_get_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
||||||
let mut response = reqwest::get(&get_url)?;
|
let client = Client::new();
|
||||||
|
let response = client.get(&get_url).send()?;
|
||||||
match response.status().as_u16() {
|
match response.status().as_u16() {
|
||||||
404_u16 => Ok(None),
|
404_u16 => Ok(None),
|
||||||
200_u16 => Ok(Some(response.text()?)),
|
200_u16 => Ok(Some(response.text()?)),
|
||||||
@@ -54,7 +57,7 @@ impl OSSClient {
|
|||||||
|
|
||||||
pub fn put_file_content(&self, bucket_name: &str, key: &str, content: &str) -> XResult<Response> {
|
pub fn put_file_content(&self, bucket_name: &str, key: &str, content: &str) -> XResult<Response> {
|
||||||
let put_url = self.generate_signed_put_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
let put_url = self.generate_signed_put_url(bucket_name, key, INTERNAL_DEFAULT_VALID_IN_SECS);
|
||||||
let client = reqwest::Client::new();
|
let client = Client::new();
|
||||||
Ok(client.put(&put_url).body(content.as_bytes().to_vec()).send()?)
|
Ok(client.put(&put_url).body(content.as_bytes().to_vec()).send()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,8 +116,8 @@ fn get_to_be_signed(verb: &str, expire_secs: u64, bucket_name: &str, key: &str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn calc_hmac_sha1_as_base64(key: &[u8], message: &[u8]) -> String {
|
fn calc_hmac_sha1_as_base64(key: &[u8], message: &[u8]) -> String {
|
||||||
Hmac::<Sha1>::new_varkey(key).map(|mut mac| {
|
Hmac::<Sha1>::new_from_slice(key).map(|mut mac| {
|
||||||
mac.input(message);
|
mac.update(message);
|
||||||
base64::encode(&mac.result().code())
|
STANDARD.encode(mac.finalize().into_bytes().as_slice())
|
||||||
}).unwrap_or_else(|e| format!("[ERROR]Hmac error: {}", e))
|
}).unwrap_or_else(|e| format!("[ERROR]Hmac error: {}", e))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,17 +51,17 @@ impl OpenPGPTool {
|
|||||||
|
|
||||||
// https://gitlab.com/sequoia-pgp/sequoia/-/blob/master/openpgp/examples/encrypt-for.rs
|
// https://gitlab.com/sequoia-pgp/sequoia/-/blob/master/openpgp/examples/encrypt-for.rs
|
||||||
let p = &P::new();
|
let p = &P::new();
|
||||||
let mode = KeyFlags::default().set_storage_encryption(true);
|
let mode = KeyFlags::empty().set_storage_encryption();
|
||||||
let recipients = self.cert.keys()
|
let recipients = self.cert.keys()
|
||||||
.with_policy(p, None).alive().revoked(false).key_flags(&mode)
|
.with_policy(p, None).alive().revoked(false).key_flags(&mode)
|
||||||
.map(|ka| ka.key().into())
|
.map(|ka| ka.key())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if recipients.is_empty() {
|
if recipients.is_empty() {
|
||||||
return Err(new_box_error("Cannot find any encrypt key in pgp key file."));
|
return Err(new_box_error("Cannot find any encrypt key in pgp key file."));
|
||||||
}
|
}
|
||||||
let bw = BufWriter::new(File::create(to_file)?);
|
let bw = BufWriter::new(File::create(to_file)?);
|
||||||
let message = if armor {
|
let message = if armor {
|
||||||
Message::new(armor::Writer::new(bw, armor::Kind::Message, &[])?)
|
Message::new(armor::Writer::new(bw, armor::Kind::Message)?)
|
||||||
} else {
|
} else {
|
||||||
Message::new(bw)
|
Message::new(bw)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
use zip::{
|
use zip::{
|
||||||
CompressionMethod,
|
CompressionMethod,
|
||||||
write::{ ZipWriter, FileOptions },
|
write::{ SimpleFileOptions, ZipWriter },
|
||||||
};
|
};
|
||||||
use flate2::{ Compression, write::GzEncoder };
|
use flate2::{ Compression, write::GzEncoder };
|
||||||
use rust_util::{
|
use rust_util::{
|
||||||
@@ -49,7 +49,7 @@ pub fn zip_file(target: &str, zip_file: &str) -> XResult<()> {
|
|||||||
let bw = BufWriter::new(File::create(zip_file)?);
|
let bw = BufWriter::new(File::create(zip_file)?);
|
||||||
let mut zip = ZipWriter::new(bw);
|
let mut zip = ZipWriter::new(bw);
|
||||||
if target_path.is_file() {
|
if target_path.is_file() {
|
||||||
let options = FileOptions::default().compression_method(CompressionMethod::Stored);
|
let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored);
|
||||||
let zip_fn = get_file_name(target_path);
|
let zip_fn = get_file_name(target_path);
|
||||||
zip.start_file(zip_fn, options)?;
|
zip.start_file(zip_fn, options)?;
|
||||||
let mut print_status_context = PrintStatusContext::default();
|
let mut print_status_context = PrintStatusContext::default();
|
||||||
@@ -61,7 +61,7 @@ pub fn zip_file(target: &str, zip_file: &str) -> XResult<()> {
|
|||||||
walk_dir(target_path, &|p, e| {
|
walk_dir(target_path, &|p, e| {
|
||||||
warning!("Compress {} failed: {}", &p.display(), &e);
|
warning!("Compress {} failed: {}", &p.display(), &e);
|
||||||
}, &|f| {
|
}, &|f| {
|
||||||
let options = FileOptions::default().compression_method(CompressionMethod::Stored);
|
let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored);
|
||||||
let mut m_zip = mut_zip.borrow_mut();
|
let mut m_zip = mut_zip.borrow_mut();
|
||||||
let file_name = get_file_name(f); // TODO file name! add path
|
let file_name = get_file_name(f); // TODO file name! add path
|
||||||
match m_zip.start_file(&file_name, options) {
|
match m_zip.start_file(&file_name, options) {
|
||||||
@@ -78,7 +78,7 @@ pub fn zip_file(target: &str, zip_file: &str) -> XResult<()> {
|
|||||||
};
|
};
|
||||||
}, &|_| { true })?;
|
}, &|_| { true })?;
|
||||||
|
|
||||||
mut_zip.borrow_mut().finish()?;
|
mut_zip.into_inner().finish()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user