]>
Commit | Line | Data |
---|---|---|
01a08021 WB |
1 | use anyhow::Error; |
2 | ||
b62edce9 WB |
3 | use pbs_api_types::{Authid, Userid}; |
4 | use pbs_client::{HttpClient, HttpClientOptions}; | |
b62edce9 | 5 | |
d97ff8ae WB |
6 | use proxmox_auth_api::ticket::Ticket; |
7 | ||
569324cb | 8 | use crate::auth::private_auth_keyring; |
01a08021 | 9 | |
b62edce9 WB |
10 | /// Connect to localhost:8007 as root@pam |
11 | /// | |
12 | /// This automatically creates a ticket if run as 'root' user. | |
01a08021 | 13 | pub fn connect_to_localhost() -> Result<pbs_client::HttpClient, Error> { |
b62edce9 | 14 | let options = if nix::unistd::Uid::current().is_root() { |
569324cb WB |
15 | let ticket = |
16 | Ticket::new("PBS", Userid::root_userid())?.sign(private_auth_keyring(), None)?; | |
450105b0 | 17 | let fingerprint = crate::cert_info()?.fingerprint()?; |
b62edce9 | 18 | HttpClientOptions::new_non_interactive(ticket, Some(fingerprint)) |
01a08021 | 19 | } else { |
b62edce9 WB |
20 | HttpClientOptions::new_interactive(None, None) |
21 | }; | |
22 | ||
23 | HttpClient::new("localhost", 8007, Authid::root_auth_id(), options) | |
01a08021 | 24 | } |