remove pbs_client::connect_to_localhost

It also used `CertInfo` from pbs-tools which is also server
specific.

The original helper is now in the main crate's
client_helpers instead.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-09-29 13:58:07 +02:00
parent 67678ec39c
commit b62edce929
2 changed files with 17 additions and 29 deletions

View File

@ -3,13 +3,6 @@
//! This library implements the client side to access the backups
//! server using https.
use anyhow::Error;
use openssl::pkey::{PKey, Private};
use pbs_api_types::{Authid, Userid};
use pbs_tools::ticket::Ticket;
use pbs_tools::cert::CertInfo;
pub mod catalog_shell;
pub mod dynamic_index;
pub mod pxar;
@ -49,19 +42,3 @@ mod chunk_stream;
pub use chunk_stream::{ChunkStream, FixedChunkStream};
pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
/// Connect to localhost:8007 as root@pam
///
/// This automatically creates a ticket if run as 'root' user.
pub fn connect_to_localhost(auth_key: Option<&PKey<Private>>) -> Result<HttpClient, Error> {
let options = if let Some(auth_key) = auth_key {
let ticket = Ticket::new("PBS", Userid::root_userid())?
.sign(auth_key, None)?;
let fingerprint = CertInfo::new()?.fingerprint()?;
HttpClientOptions::new_non_interactive(ticket, Some(fingerprint))
} else {
HttpClientOptions::new_interactive(None, None)
};
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)
}

View File

@ -1,13 +1,24 @@
use anyhow::Error;
use pbs_api_types::{Authid, Userid};
use pbs_client::{HttpClient, HttpClientOptions};
use pbs_tools::cert::CertInfo;
use pbs_tools::ticket::Ticket;
use crate::auth_helpers::private_auth_key;
/// As root we have access to the private key file and can use it directly. Otherwise the connect
/// call will interactively query the password.
/// 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> {
pbs_client::connect_to_localhost(if nix::unistd::Uid::current().is_root() {
Some(private_auth_key())
let options = if nix::unistd::Uid::current().is_root() {
let auth_key = private_auth_key();
let ticket = Ticket::new("PBS", Userid::root_userid())?.sign(auth_key, None)?;
let fingerprint = CertInfo::new()?.fingerprint()?;
HttpClientOptions::new_non_interactive(ticket, Some(fingerprint))
} else {
None
})
HttpClientOptions::new_interactive(None, None)
};
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)
}