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]
|
||||
name = "oss-backupd"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -13,19 +13,19 @@ use_zip = []
|
||||
use_sequoia_openpgp = ["sequoia-openpgp"]
|
||||
|
||||
[dependencies]
|
||||
dirs = "2.0.1"
|
||||
argparse = "0.2.2"
|
||||
json = "0.11.14"
|
||||
hmac = "0.7.1"
|
||||
sha-1 = "0.8.2"
|
||||
indicatif = "0.13.0"
|
||||
urlencoding = "1.0.0"
|
||||
base64 = "0.11.0"
|
||||
reqwest = "0.9.22"
|
||||
sequoia-openpgp = { version = "0.16.0", optional = true }
|
||||
chrono = "0.4.10"
|
||||
zip = "0.5.3"
|
||||
tar = "0.4.26"
|
||||
flate2 = "1.0.14"
|
||||
rust_util = "0.6.3"
|
||||
tiny-encrypt = { version = "1.8.3", default-features = false }
|
||||
dirs = "6.0"
|
||||
argparse = "0.2"
|
||||
json = "0.12"
|
||||
hmac = "0.12"
|
||||
sha-1 = "0.10"
|
||||
indicatif = "0.17"
|
||||
urlencoding = "2.1"
|
||||
base64 = "0.22"
|
||||
reqwest = { version = "0.12", features = ["blocking", "native-tls-vendored"] }
|
||||
sequoia-openpgp = { version = "1.22", optional = true }
|
||||
chrono = "0.4"
|
||||
zip = "2.2"
|
||||
tar = "0.4"
|
||||
flate2 = "1.0"
|
||||
rust_util = "0.6"
|
||||
tiny-encrypt = { version = "1.8", default-features = false }
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::{
|
||||
fs::{ self, File },
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use rust_util::{XResult, util_time::*, util_msg::*};
|
||||
use rust_util::{XResult, util_time::*};
|
||||
use tiny_encrypt::CmdEncrypt;
|
||||
use oss_util::*;
|
||||
use config_util::*;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use std::fs::File;
|
||||
use base64::Engine;
|
||||
use sha1::Sha1;
|
||||
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 };
|
||||
|
||||
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> {
|
||||
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()?)
|
||||
}
|
||||
|
||||
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 client = reqwest::Client::new();
|
||||
let client = Client::new();
|
||||
Ok(client.delete(&delete_url).send()?)
|
||||
}
|
||||
|
||||
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 mut response = reqwest::get(&get_url)?;
|
||||
let client = Client::new();
|
||||
let response = client.get(&get_url).send()?;
|
||||
match response.status().as_u16() {
|
||||
404_u16 => Ok(None),
|
||||
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> {
|
||||
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()?)
|
||||
}
|
||||
|
||||
@@ -76,17 +79,17 @@ impl OSSClient {
|
||||
|
||||
let endpoint = &remove_endpoint_http_or_s(&self.endpoint);
|
||||
signed_url.push_str(&format!("{}.{}/{}", bucket_name, endpoint, key));
|
||||
|
||||
|
||||
let current_secs = get_current_secs();
|
||||
let expire_secs = current_secs + expire_in_seconds;
|
||||
|
||||
|
||||
signed_url.push_str(&format!("?Expires={}", &expire_secs.to_string()));
|
||||
signed_url.push_str(&format!("&OSSAccessKeyId={}", &urlencoding::encode(&self.access_key_id)));
|
||||
|
||||
|
||||
let to_be_signed = get_to_be_signed(verb, expire_secs, bucket_name, key);
|
||||
let signature = calc_hmac_sha1_as_base64(self.access_key_secret.as_bytes(), to_be_signed.as_bytes());
|
||||
signed_url.push_str(&format!("&Signature={}", &urlencoding::encode(&signature)));
|
||||
|
||||
|
||||
signed_url
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
Hmac::<Sha1>::new_varkey(key).map(|mut mac| {
|
||||
mac.input(message);
|
||||
base64::encode(&mac.result().code())
|
||||
Hmac::<Sha1>::new_from_slice(key).map(|mut mac| {
|
||||
mac.update(message);
|
||||
STANDARD.encode(mac.finalize().into_bytes().as_slice())
|
||||
}).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
|
||||
let p = &P::new();
|
||||
let mode = KeyFlags::default().set_storage_encryption(true);
|
||||
let mode = KeyFlags::empty().set_storage_encryption();
|
||||
let recipients = self.cert.keys()
|
||||
.with_policy(p, None).alive().revoked(false).key_flags(&mode)
|
||||
.map(|ka| ka.key().into())
|
||||
.map(|ka| ka.key())
|
||||
.collect::<Vec<_>>();
|
||||
if recipients.is_empty() {
|
||||
return Err(new_box_error("Cannot find any encrypt key in pgp key file."));
|
||||
}
|
||||
let bw = BufWriter::new(File::create(to_file)?);
|
||||
let message = if armor {
|
||||
Message::new(armor::Writer::new(bw, armor::Kind::Message, &[])?)
|
||||
Message::new(armor::Writer::new(bw, armor::Kind::Message)?)
|
||||
} else {
|
||||
Message::new(bw)
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::{
|
||||
};
|
||||
use zip::{
|
||||
CompressionMethod,
|
||||
write::{ ZipWriter, FileOptions },
|
||||
write::{ SimpleFileOptions, ZipWriter },
|
||||
};
|
||||
use flate2::{ Compression, write::GzEncoder };
|
||||
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 mut zip = ZipWriter::new(bw);
|
||||
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);
|
||||
zip.start_file(zip_fn, options)?;
|
||||
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| {
|
||||
warning!("Compress {} failed: {}", &p.display(), &e);
|
||||
}, &|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 file_name = get_file_name(f); // TODO file name! add path
|
||||
match m_zip.start_file(&file_name, options) {
|
||||
@@ -78,7 +78,7 @@ pub fn zip_file(target: &str, zip_file: &str) -> XResult<()> {
|
||||
};
|
||||
}, &|_| { true })?;
|
||||
|
||||
mut_zip.borrow_mut().finish()?;
|
||||
mut_zip.into_inner().finish()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user