Skip to content

Commit

Permalink
edition 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 29, 2023
1 parent 50ab693 commit 1f655a3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ff-node-monitor"
version = "0.1.0"
authors = ["Ralf Jung <[email protected]>"]
edition = "2018"
edition = "2021"

[profile.release]
overflow-checks = true
Expand All @@ -13,7 +13,7 @@ rocket_dyn_templates = { version = "0.1.0", features = ["handlebars"] }
rocket_sync_db_pools = { version = "0.1.0", features = ["diesel_postgres_pool"] }
diesel = { version = "2.0", features = ["postgres"] }
diesel_migrations = "2.0"
ring = "0.13" # tied to 0,13 due to Rocket
ring = "0.13" # tied to 0.13 due to Rocket
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
Expand Down
Empty file removed migrations/.gitkeep
Empty file.
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::borrow::Cow;

use rocket::fairing::{AdHoc, Fairing};
use rocket::request::{self, FromRequest, Request};
use rocket::{self, http::uri, request::Outcome, State};
Expand All @@ -27,8 +29,6 @@ use serde_json::{self, json};
use url::Url;
use uuid::Uuid;

use std::borrow::Cow;

use crate::util;

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn fairing(section: &'static str) -> impl Fairing {
panic!("[{}] table in Rocket.toml missing or not a table", section)
});
let mail_ctx = {
let from = Email::try_from(config.ui.email_from.as_str())
let from = <Email as HeaderTryFrom<_>>::try_from(config.ui.email_from.as_str())
.expect("`email_from` is not a valid email address");
let unique_part = Uuid::new_v4().to_string().parse().unwrap();
simple_context::new(from.domain, unique_part).unwrap()
Expand Down
9 changes: 6 additions & 3 deletions src/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::collections::HashMap;

use anyhow::{bail, Result};
use diesel::prelude::*;
use rocket::uri;
use serde_json::{self, json};
use thiserror::Error;

use std::collections::HashMap;

use crate::config;
use crate::models;
use crate::routes;
Expand Down Expand Up @@ -123,7 +123,10 @@ pub async fn update_nodes(
config: &config::Config,
email_sender: EmailSender<'_>,
) -> Result<UpdateResult> {
let cur_nodes: json::Nodes = reqwest::get(config.urls.nodes.clone()).await?.json().await?;
let cur_nodes: json::Nodes = reqwest::get(config.urls.nodes.clone())
.await?
.json()
.await?;

if cur_nodes.version != 2 {
bail!(NodeListError::UnsupportedVersion {
Expand Down
6 changes: 0 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// FIXME: Get rid of the remaining `extern crate` once we can
#[macro_use]
extern crate diesel as diesel_macros;

// FIXME: Get rid of the remaining `macro_use` once we can
#[macro_use]
mod util;
mod action;
mod config;
Expand Down
1 change: 1 addition & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use serde::Serialize;
use diesel::prelude::*;

use crate::schema::*;

Expand Down
5 changes: 2 additions & 3 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::collections::HashSet;

use rocket::{form::Form, response::Debug, State};
use rocket::{get, post, routes, uri};
use rocket_dyn_templates::Template;

use base64;
use diesel::prelude::*;
use rmp_serde::from_slice as deserialize_from_slice;
use rmp_serde::to_vec as serialize_to_vec;
use serde_json::json;

use std::collections::HashSet;

use crate::action::*;
use crate::config::{Config, Renderer};
use crate::cron;
Expand Down
11 changes: 8 additions & 3 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
table! {
// @generated automatically by Diesel CLI.

diesel::table! {
monitors (id, email) {
id -> Varchar,
email -> Varchar,
}
}

table! {
diesel::table! {
nodes (id) {
id -> Varchar,
name -> Varchar,
online -> Bool,
}
}

allow_tables_to_appear_in_same_query!(monitors, nodes,);
diesel::allow_tables_to_appear_in_same_query!(
monitors,
nodes,
);
13 changes: 5 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::ops::Deref;

use rocket::{
form::{self, FromFormField},
request::{self, FromRequest, Outcome},
Expand All @@ -29,8 +31,6 @@ use thiserror::Error;

use crate::config::Config;

use std::ops::Deref;

/// Module for serde "with" to use hex encoding to byte arrays
pub mod hex_signing_key {
use hex;
Expand Down Expand Up @@ -134,14 +134,11 @@ impl<'r> EmailSender<'r> {
.unwrap();
//let email_text = self.responder_body(email_template).await?;
let email_parts: Vec<&str> = email_text.splitn(3, '\n').collect();
let (email_from, email_subject, email_body) = (
email_parts[0],
email_parts[1],
email_parts[2],
);
let (email_from, email_subject, email_body) =
(email_parts[0], email_parts[1], email_parts[2]);

// Build email
let from = Email::try_from(self.config.ui.email_from.as_str())
let from = <Email as HeaderTryFrom<_>>::try_from(self.config.ui.email_from.as_str())
.map_err(EmailError::ComponentCreation)?;
let mut mail = Mail::plain_text(email_body, self.mail_ctx);
mail.insert_headers(
Expand Down

0 comments on commit 1f655a3

Please sign in to comment.