]> git.proxmox.com Git - proxmox-backup.git/blob - src/client.rs
depend on libjs-qrcodejs
[proxmox-backup.git] / src / client.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 crate::{
9 api2::types::{Userid, Authid},
10 tools::ticket::Ticket,
11 auth_helpers::private_auth_key,
12 };
13
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 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 mod pull;
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 mut options = HttpClientOptions::new()
53 .prefix(Some("proxmox-backup".to_string()))
54 .verify_cert(false); // not required for connection to localhost
55
56 let client = if uid.is_root() {
57 let ticket = Ticket::new("PBS", Userid::root_userid())?
58 .sign(private_auth_key(), None)?;
59 options = options.password(Some(ticket));
60 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
61 } else {
62 options = options.ticket_cache(true).interactive(true);
63 HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
64 };
65
66 Ok(client)
67 }