proxmox-backup/src/client_helpers.rs
Wolfgang Bumiller 569324cb95 provide separate helpers for pub/priv auth keyring access
This used to be the case before the switch to the auth api
crate and is required for some helpers where we don't want
to have to setup the complete auth context.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-03-29 14:37:45 +02:00

25 lines
828 B
Rust

use anyhow::Error;
use pbs_api_types::{Authid, Userid};
use pbs_client::{HttpClient, HttpClientOptions};
use proxmox_auth_api::ticket::Ticket;
use crate::auth::private_auth_keyring;
/// Connect to localhost:8007 as root@pam
///
/// This automatically creates a ticket if run as 'root' user.
pub fn connect_to_localhost() -> Result<pbs_client::HttpClient, Error> {
let options = if nix::unistd::Uid::current().is_root() {
let ticket =
Ticket::new("PBS", Userid::root_userid())?.sign(private_auth_keyring(), None)?;
let fingerprint = crate::cert_info()?.fingerprint()?;
HttpClientOptions::new_non_interactive(ticket, Some(fingerprint))
} else {
HttpClientOptions::new_interactive(None, None)
};
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)
}