68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
//! Client side interface to the proxmox backup server
|
|
//!
|
|
//! This library implements the client side to access the backups
|
|
//! server using https.
|
|
|
|
use anyhow::Error;
|
|
|
|
use crate::{
|
|
api2::types::{Userid, Authid},
|
|
tools::ticket::Ticket,
|
|
auth_helpers::private_auth_key,
|
|
};
|
|
|
|
|
|
|
|
mod merge_known_chunks;
|
|
pub mod pipe_to_stream;
|
|
|
|
mod http_client;
|
|
pub use http_client::*;
|
|
|
|
mod task_log;
|
|
pub use task_log::*;
|
|
|
|
mod backup_reader;
|
|
pub use backup_reader::*;
|
|
|
|
mod backup_writer;
|
|
pub use backup_writer::*;
|
|
|
|
mod remote_chunk_reader;
|
|
pub use remote_chunk_reader::*;
|
|
|
|
mod pxar_backup_stream;
|
|
pub use pxar_backup_stream::*;
|
|
|
|
mod backup_repo;
|
|
pub use backup_repo::*;
|
|
|
|
mod backup_specification;
|
|
pub use backup_specification::*;
|
|
|
|
pub mod pull;
|
|
|
|
/// Connect to localhost:8007 as root@pam
|
|
///
|
|
/// This automatically creates a ticket if run as 'root' user.
|
|
pub fn connect_to_localhost() -> Result<HttpClient, Error> {
|
|
|
|
let uid = nix::unistd::Uid::current();
|
|
|
|
let mut options = HttpClientOptions::new()
|
|
.prefix(Some("proxmox-backup".to_string()))
|
|
.verify_cert(false); // not required for connection to localhost
|
|
|
|
let client = if uid.is_root() {
|
|
let ticket = Ticket::new("PBS", Userid::root_userid())?
|
|
.sign(private_auth_key(), None)?;
|
|
options = options.password(Some(ticket));
|
|
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
|
|
} else {
|
|
options = options.ticket_cache(true).interactive(true);
|
|
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
|
|
};
|
|
|
|
Ok(client)
|
|
}
|