]> git.proxmox.com Git - proxmox-backup.git/blob - src/client/mod.rs
move more tools for the client into subcrates
[proxmox-backup.git] / src / client / mod.rs
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
6 use anyhow::Error;
7
8 use pbs_api_types::{Authid, Userid};
9 use pbs_tools::ticket::Ticket;
10 use pbs_tools::cert::CertInfo;
11 use pbs_tools::auth::private_auth_key;
12
13 mod merge_known_chunks;
14 pub mod pipe_to_stream;
15
16 mod http_client;
17 pub use http_client::*;
18
19 mod vsock_client;
20 pub use vsock_client::*;
21
22 mod task_log;
23 pub use task_log::*;
24
25 mod backup_reader;
26 pub use backup_reader::*;
27
28 mod backup_writer;
29 pub use backup_writer::*;
30
31 mod remote_chunk_reader;
32 pub use remote_chunk_reader::*;
33
34 mod pxar_backup_stream;
35 pub use pxar_backup_stream::*;
36
37 mod backup_repo;
38 pub use backup_repo::*;
39
40 mod backup_specification;
41 pub use backup_specification::*;
42
43 pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
44
45 /// Connect to localhost:8007 as root@pam
46 ///
47 /// This automatically creates a ticket if run as 'root' user.
48 pub fn connect_to_localhost() -> Result<HttpClient, Error> {
49
50 let uid = nix::unistd::Uid::current();
51
52 let client = if uid.is_root() {
53 let ticket = Ticket::new("PBS", Userid::root_userid())?
54 .sign(private_auth_key(), None)?;
55 let fingerprint = CertInfo::new()?.fingerprint()?;
56 let options = HttpClientOptions::new_non_interactive(ticket, Some(fingerprint));
57
58 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
59 } else {
60 let options = HttpClientOptions::new_interactive(None, None);
61
62 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
63 };
64
65 Ok(client)
66 }