let auth_id = Authid::root_auth_id();
- let options = HttpClientOptions::new()
+ let options = HttpClientOptions::default()
.interactive(true)
.ticket_cache(true);
let auth_id = Authid::root_auth_id();
- let options = HttpClientOptions::new()
+ let options = HttpClientOptions::default()
.interactive(true)
.ticket_cache(true);
/// Helper to get client for remote.cfg entry
pub async fn remote_client(remote: remote::Remote) -> Result<HttpClient, Error> {
- let options = HttpClientOptions::new()
- .password(Some(remote.password.clone()))
- .fingerprint(remote.fingerprint.clone());
+ let options = HttpClientOptions::new_non_interactive(remote.password.clone(), remote.fingerprint.clone());
let client = HttpClient::new(
&remote.host,
}
}
+#[derive(Default)]
pub struct PruneOptions {
pub keep_last: Option<u64>,
pub keep_hourly: Option<u64>,
Err(NotPresent) => None,
};
- let options = HttpClientOptions::new()
- .prefix(Some("proxmox-backup".to_string()))
- .password(password)
- .interactive(true)
- .fingerprint(fingerprint)
- .fingerprint_cache(true)
- .ticket_cache(true);
+ let options = HttpClientOptions::new_interactive(password, fingerprint);
HttpClient::new(server, port, auth_id, options)
}
let fingerprint = std::env::var(ENV_VAR_PBS_FINGERPRINT).ok();
let password = std::env::var(ENV_VAR_PBS_PASSWORD).ok();
- let options = HttpClientOptions::new()
- .prefix(Some("proxmox-backup".to_string()))
- .password(password)
- .interactive(false)
- .fingerprint(fingerprint)
- .fingerprint_cache(true)
- .ticket_cache(true);
+ // ticket cache, but no questions asked
+ let options = HttpClientOptions::new_interactive(password, fingerprint)
+ .interactive(false);
let client = match HttpClient::new(repo.host(), repo.port(), repo.auth_id(), options) {
Ok(v) => v,
let uid = nix::unistd::Uid::current();
- let mut options = HttpClientOptions::new()
- .prefix(Some("proxmox-backup".to_string()))
- .verify_cert(false); // not required for connection to localhost
-
let client = if uid.is_root() {
let ticket = Ticket::new("PBS", Userid::root_userid())?
.sign(private_auth_key(), None)?;
- options = options.password(Some(ticket));
+ let fingerprint = crate::tools::cert::CertInfo::new()?.fingerprint()?;
+ let options = HttpClientOptions::new_non_interactive(ticket, Some(fingerprint));
+
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
} else {
- options = options.ticket_cache(true).interactive(true);
+ let options = HttpClientOptions::new_interactive(None, None);
+
HttpClient::new("localhost", 8007, Authid::root_auth_id(), options)?
};
impl HttpClientOptions {
- pub fn new() -> Self {
+ pub fn new_interactive(password: Option<String>, fingerprint: Option<String>) -> Self {
Self {
- prefix: None,
- password: None,
- fingerprint: None,
- interactive: false,
- ticket_cache: false,
- fingerprint_cache: false,
- verify_cert: true,
+ password,
+ fingerprint,
+ fingerprint_cache: true,
+ ticket_cache: true,
+ interactive: true,
+ prefix: Some("proxmox-backup".to_string()),
+ ..Self::default()
+ }
+ }
+
+ pub fn new_non_interactive(password: String, fingerprint: Option<String>) -> Self {
+ Self {
+ password: Some(password),
+ fingerprint,
+ ..Self::default()
}
}
}
}
+impl Default for HttpClientOptions {
+ fn default() -> Self {
+ Self {
+ prefix: None,
+ password: None,
+ fingerprint: None,
+ interactive: false,
+ ticket_cache: false,
+ fingerprint_cache: false,
+ verify_cert: true,
+ }
+ }
+}
+
/// HTTP(S) API client
pub struct HttpClient {
client: Client<HttpsConnector>,
// get updated auth_info (new tickets)
let auth_info = client.login().await?;
- let options = HttpClientOptions::new()
- .password(Some(auth_info.ticket.clone()))
- .fingerprint(fingerprint.clone());
+ let options = HttpClientOptions::new_non_interactive(auth_info.ticket.clone(), fingerprint.clone());
let new_client = HttpClient::new(
src_repo.host(),
}
/// Tree representing a parsed acl.cfg
+#[derive(Default)]
pub struct AclTree {
/// Root node of the tree.
///
}
/// Node representing ACLs for a certain ACL path.
+#[derive(Default)]
pub struct AclTreeNode {
/// [User](crate::config::user::User) or
/// [Token](crate::config::user::ApiToken) ACLs for this node.
}
fn insert_group_role(&mut self, group: String, role: String, propagate: bool) {
- let map = self.groups.entry(group).or_insert_with(HashMap::new);
+ let map = self.groups.entry(group).or_default();
if role == ROLE_NAME_NO_ACCESS {
map.clear();
map.insert(role, propagate);
}
fn insert_user_role(&mut self, auth_id: Authid, role: String, propagate: bool) {
- let map = self.users.entry(auth_id).or_insert_with(HashMap::new);
+ let map = self.users.entry(auth_id).or_default();
if role == ROLE_NAME_NO_ACCESS {
map.clear();
map.insert(role, propagate);
node = node
.children
.entry(String::from(*comp))
- .or_insert_with(AclTreeNode::new);
+ .or_default();
}
node
}
Option(String),
}
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct NetworkConfig {
pub interfaces: BTreeMap<String, Interface>,
order: Vec<NetworkOrderEntry>,