src/client.rs: improve library structure and docu
This commit is contained in:
parent
18a1aa4858
commit
151c6ce27d
|
@ -7,8 +7,7 @@ use proxmox_backup::tools;
|
|||
use proxmox_backup::cli::command::*;
|
||||
use proxmox_backup::api::schema::*;
|
||||
use proxmox_backup::api::router::*;
|
||||
use proxmox_backup::client::http_client::*;
|
||||
use proxmox_backup::client::catar_backup_stream::*;
|
||||
use proxmox_backup::client::*;
|
||||
//use proxmox_backup::backup::chunk_store::*;
|
||||
//use proxmox_backup::backup::image_index::*;
|
||||
//use proxmox_backup::config::datastore;
|
||||
|
@ -18,38 +17,6 @@ use proxmox_backup::client::catar_backup_stream::*;
|
|||
use serde_json::{Value};
|
||||
use hyper::Body;
|
||||
use std::sync::Arc;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
lazy_static! {
|
||||
// user@host:datastore
|
||||
pub static ref BACKUP_REPO_URL_REGEX: Regex = Regex::new(r"^(?:(?:([\w@]+)@)?(\w+):)?(\w+)$").unwrap();
|
||||
|
||||
pub static ref BACKUP_REPO_URL: Arc<ApiStringFormat> =
|
||||
ApiStringFormat::Pattern(&BACKUP_REPO_URL_REGEX).into();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BackupRepository {
|
||||
pub user: String,
|
||||
pub host: String,
|
||||
pub store: String,
|
||||
}
|
||||
|
||||
impl BackupRepository {
|
||||
|
||||
pub fn parse(url: &str) -> Result<Self, Error> {
|
||||
|
||||
let cap = BACKUP_REPO_URL_REGEX.captures(url)
|
||||
.ok_or_else(|| format_err!("unable to parse reepository url '{}'", url))?;
|
||||
|
||||
Ok(BackupRepository {
|
||||
user: cap.get(1).map_or("root@pam", |m| m.as_str()).to_owned(),
|
||||
host: cap.get(2).map_or("localhost", |m| m.as_str()).to_owned(),
|
||||
store: cap[3].to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn backup_directory(repo: &BackupRepository, body: Body, archive_name: &str) -> Result<(), Error> {
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
//! Client side interface to the proxmox backup server
|
||||
//!
|
||||
//! This library implements the client side to access the backups
|
||||
//! server using https.
|
||||
|
||||
mod http_client;
|
||||
pub use http_client::*;
|
||||
|
||||
mod catar_backup_stream;
|
||||
pub use catar_backup_stream::*;
|
||||
|
||||
mod backup_repo;
|
||||
pub use backup_repo::*;
|
|
@ -0,0 +1,48 @@
|
|||
use failure::*;
|
||||
|
||||
use crate::api::schema::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
lazy_static! {
|
||||
// user@host:datastore
|
||||
pub static ref BACKUP_REPO_URL_REGEX: Regex = Regex::new(r"^(?:(?:([\w@]+)@)?(\w+):)?(\w+)$").unwrap();
|
||||
|
||||
pub static ref BACKUP_REPO_URL: Arc<ApiStringFormat> =
|
||||
ApiStringFormat::Pattern(&BACKUP_REPO_URL_REGEX).into();
|
||||
}
|
||||
|
||||
/// Reference remote backup locations
|
||||
///
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BackupRepository {
|
||||
/// The user name used for Authentication
|
||||
pub user: String,
|
||||
/// The host name or IP address
|
||||
pub host: String,
|
||||
/// The name of the datastore
|
||||
pub store: String,
|
||||
}
|
||||
|
||||
impl BackupRepository {
|
||||
|
||||
/// Parse a repository string.
|
||||
///
|
||||
/// This parses strings like `user@host:datastore`. The `user` and
|
||||
/// `host` parts are optional, where `host` defaults to the local
|
||||
/// host, and `user` defaults to `root@pam`.
|
||||
pub fn parse(url: &str) -> Result<Self, Error> {
|
||||
|
||||
let cap = BACKUP_REPO_URL_REGEX.captures(url)
|
||||
.ok_or_else(|| format_err!("unable to parse reepository url '{}'", url))?;
|
||||
|
||||
Ok(BackupRepository {
|
||||
user: cap.get(1).map_or("root@pam", |m| m.as_str()).to_owned(),
|
||||
host: cap.get(2).map_or("localhost", |m| m.as_str()).to_owned(),
|
||||
store: cap[3].to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
|
@ -13,6 +13,13 @@ use nix::dir::Dir;
|
|||
|
||||
use crate::catar::encoder::*;
|
||||
|
||||
/// Stream implementation to encode and upload .catar archives.
|
||||
///
|
||||
/// The hyper client needs an async Stream for file upload, so we
|
||||
/// spawn an extra thread to encode the .catar data and pipe it to the
|
||||
/// consumer.
|
||||
///
|
||||
/// Note: The currect implementation is not fully ansync and can block.
|
||||
pub struct CaTarBackupStream {
|
||||
pipe: Option<std::fs::File>,
|
||||
buffer: Vec<u8>,
|
||||
|
|
|
@ -11,6 +11,7 @@ use futures::stream::Stream;
|
|||
use serde_json::{Value};
|
||||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||||
|
||||
/// HTTP(S) API client
|
||||
pub struct HttpClient {
|
||||
username: String,
|
||||
server: String,
|
||||
|
|
|
@ -61,11 +61,7 @@ pub mod cli {
|
|||
|
||||
pub mod api2;
|
||||
|
||||
pub mod client {
|
||||
|
||||
pub mod http_client;
|
||||
pub mod catar_backup_stream;
|
||||
}
|
||||
pub mod client;
|
||||
|
||||
pub mod getopts;
|
||||
pub mod auth_helpers;
|
||||
|
|
Loading…
Reference in New Issue