]> git.proxmox.com Git - proxmox-backup.git/blame - src/client/mod.rs
move more helpers to pbs-tools
[proxmox-backup.git] / src / client / mod.rs
CommitLineData
151c6ce2
DM
1//! Client side interface to the proxmox backup server
2//!
3//! This library implements the client side to access the backups
4//! server using https.
5
6b68e5d5
DM
6use anyhow::Error;
7
9eb78407
WB
8use pbs_api_types::{Authid, Userid};
9use pbs_tools::ticket::Ticket;
10
6b68e5d5 11use crate::{
9eb78407 12 tools::cert::CertInfo,
6b68e5d5
DM
13 auth_helpers::private_auth_key,
14};
15
aa1b2e04 16mod merge_known_chunks;
c443f58b 17pub mod pipe_to_stream;
e3dbd41b 18
151c6ce2 19mod http_client;
c443f58b 20pub use http_client::*;
151c6ce2 21
89d25b19
SR
22mod vsock_client;
23pub use vsock_client::*;
24
5a0b484b
DM
25mod task_log;
26pub use task_log::*;
27
9e490a74
DM
28mod backup_reader;
29pub use backup_reader::*;
30
cf9271e2
DM
31mod backup_writer;
32pub use backup_writer::*;
33
7f99bf69
DM
34mod remote_chunk_reader;
35pub use remote_chunk_reader::*;
36
8968258b
DM
37mod pxar_backup_stream;
38pub use pxar_backup_stream::*;
151c6ce2
DM
39
40mod backup_repo;
41pub use backup_repo::*;
07ad6470 42
7cc3473a
DM
43mod backup_specification;
44pub use backup_specification::*;
45
6b68e5d5
DM
46/// Connect to localhost:8007 as root@pam
47///
48/// This automatically creates a ticket if run as 'root' user.
49pub fn connect_to_localhost() -> Result<HttpClient, Error> {
50
51 let uid = nix::unistd::Uid::current();
52
6b68e5d5
DM
53 let client = if uid.is_root() {
54 let ticket = Ticket::new("PBS", Userid::root_userid())?
55 .sign(private_auth_key(), None)?;
9eb78407 56 let fingerprint = CertInfo::new()?.fingerprint()?;
93e3581c
FG
57 let options = HttpClientOptions::new_non_interactive(ticket, Some(fingerprint));
58
6b68e5d5
DM
59 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
60 } else {
93e3581c
FG
61 let options = HttpClientOptions::new_interactive(None, None);
62
6b68e5d5
DM
63 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
64 };
65
66 Ok(client)
67}