]>
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 WB |
5 | use pbs_tools::ticket::Ticket; |
6 | ||
01a08021 WB |
7 | use crate::auth_helpers::private_auth_key; |
8 | ||
b62edce9 WB |
9 | /// Connect to localhost:8007 as root@pam |
10 | /// | |
11 | /// This automatically creates a ticket if run as 'root' user. | |
01a08021 | 12 | pub fn connect_to_localhost() -> Result<pbs_client::HttpClient, Error> { |
b62edce9 WB |
13 | let options = if nix::unistd::Uid::current().is_root() { |
14 | let auth_key = private_auth_key(); | |
15 | let ticket = Ticket::new("PBS", Userid::root_userid())?.sign(auth_key, None)?; | |
450105b0 | 16 | let fingerprint = crate::cert_info()?.fingerprint()?; |
b62edce9 | 17 | HttpClientOptions::new_non_interactive(ticket, Some(fingerprint)) |
01a08021 | 18 | } else { |
b62edce9 WB |
19 | HttpClientOptions::new_interactive(None, None) |
20 | }; | |
21 | ||
22 | HttpClient::new("localhost", 8007, Authid::root_auth_id(), options) | |
01a08021 | 23 | } |