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