cargo fmt

This commit is contained in:
Armaël Guéneau 2024-04-15 23:15:08 +02:00
parent 8bc9126264
commit c8854fcbd4

View file

@ -3,8 +3,8 @@ use eyre::{eyre, OptionExt, WrapErr};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::{fmt,env};
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use std::{env, fmt};
const RESTIC_ALARM_BUCKET: &str = "restic-alarm-state"; const RESTIC_ALARM_BUCKET: &str = "restic-alarm-state";
const RESTIC_ALARM_STATE_FILE: &str = "state.toml"; const RESTIC_ALARM_STATE_FILE: &str = "state.toml";
@ -18,8 +18,8 @@ struct SmtpConfig {
impl SmtpConfig { impl SmtpConfig {
fn mailer(&self) -> Result<lettre::SmtpTransport, lettre::transport::smtp::Error> { fn mailer(&self) -> Result<lettre::SmtpTransport, lettre::transport::smtp::Error> {
use lettre::SmtpTransport;
use lettre::transport::smtp::authentication::Credentials; use lettre::transport::smtp::authentication::Credentials;
use lettre::SmtpTransport;
Ok(SmtpTransport::relay(&self.address)? Ok(SmtpTransport::relay(&self.address)?
.credentials(Credentials::new( .credentials(Credentials::new(
self.username.to_owned(), self.username.to_owned(),
@ -32,9 +32,13 @@ impl SmtpConfig {
let address = env::var("SMTP_ADDRESS")?; let address = env::var("SMTP_ADDRESS")?;
let username = env::var("SMTP_USERNAME")?; let username = env::var("SMTP_USERNAME")?;
let password = env::var("SMTP_PASSWORD")?; let password = env::var("SMTP_PASSWORD")?;
let smtp = SmtpConfig { address, username, password }; let smtp = SmtpConfig {
address,
username,
password,
};
if !smtp.mailer()?.test_connection()? { if !smtp.mailer()?.test_connection()? {
return Err(eyre!("Unable to contact the SMTP relay")) return Err(eyre!("Unable to contact the SMTP relay"));
} }
Ok(smtp) Ok(smtp)
} }
@ -277,7 +281,12 @@ struct RepoInfo {
// (e.g. if it fails to parse). // (e.g. if it fails to parse).
// So the error must not be propagated to the toplevel, which would abort the // So the error must not be propagated to the toplevel, which would abort the
// alert for remaining repositories; it should instead just be reported/logged. // alert for remaining repositories; it should instead just be reported/logged.
async fn check_repo(smtp: &SmtpConfig, client: &s3::Client, state: &mut State, repo: &str) -> eyre::Result<RepoInfo> { async fn check_repo(
smtp: &SmtpConfig,
client: &s3::Client,
state: &mut State,
repo: &str,
) -> eyre::Result<RepoInfo> {
let config = read_repo_config(client, repo).await?; let config = read_repo_config(client, repo).await?;
let alert_status = if let Some(inactivity) = repo_last_snapshot(client, repo).await? { let alert_status = if let Some(inactivity) = repo_last_snapshot(client, repo).await? {
let last_alert = state.last_alert(repo); let last_alert = state.last_alert(repo);