From 5b418c5b5e432bdb3302c543f6eeb9b8be65440c Mon Sep 17 00:00:00 2001 From: Kidan Nelson Date: Thu, 7 Nov 2024 15:59:39 -0500 Subject: [PATCH] Pull request #99: [READY] bugfix: vpn config email attachment Merge in OST/laas-reflab from bugfix/vpn-config-email-attachment to iol-dev Squashed commit of the following: commit 06d6f9ad7342a32a7af8f303e4a07a5ca5ebbb9a Author: Kidan Nelson Date: Wed Nov 6 14:07:44 2024 -0500 chore: update config file commit eddf93ab1f36a3876f12419885cd13ced024c360 Author: Kidan Nelson Date: Wed Nov 6 13:05:37 2024 -0500 fix: vpn config file path in config --- Cargo.lock | 16 +++---- crates/config/src/lib.rs | 1 + crates/notifications/src/lib.rs | 79 ++++++++++++++++++++++----------- sample_config.yaml | 3 +- 4 files changed, 65 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bc0a04..35c4870 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -327,9 +327,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -1351,9 +1351,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "globset" @@ -2316,9 +2316,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 5c32e1c..3bebb71 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -140,6 +140,7 @@ pub struct NotificationConfig { pub admin_send_to_email: Option, pub templates_directory: String, + pub vpn_config_path: PathBuf, } #[derive(Debug, Deserialize, Clone)] pub struct CobblerConfig { diff --git a/crates/notifications/src/lib.rs b/crates/notifications/src/lib.rs index b864458..ccbd439 100644 --- a/crates/notifications/src/lib.rs +++ b/crates/notifications/src/lib.rs @@ -16,7 +16,14 @@ use std::{ use tera::Tera; pub mod email; -use common::prelude::{anyhow, chrono::{self, Utc}, futures, itertools::Itertools, serde_json::json, tracing}; +use common::prelude::{ + anyhow, + chrono::{self, Utc}, + futures, + itertools::Itertools, + serde_json::json, + tracing, +}; use config::{settings, RenderTarget, Situation}; pub type Username = String; @@ -101,7 +108,7 @@ pub async fn send_booking_notification( situation: Situation, owner_title: String, collab_title: String, - extra: Option + extra: Option, ) -> Result<(), Vec> { let users = info .collaborators @@ -230,14 +237,18 @@ pub async fn send_test_email( } } -pub async fn booking_started(env: &Env, info: &BookingInfo, extra: Option) -> Result<(), Vec> { +pub async fn booking_started( + env: &Env, + info: &BookingInfo, + extra: Option, +) -> Result<(), Vec> { send_booking_notification( env, info, Situation::BookingCreated, "You Have Created a New Booking.".to_owned(), "You Have Been Added To a New Booking.".to_owned(), - extra + extra, ) .await } @@ -251,7 +262,7 @@ pub async fn booking_ending(env: &Env, info: &BookingInfo) -> Result<(), Vec Result<(), Vec Result<(), Vec> { - let styles = read_styles( settings() .projects @@ -393,10 +403,21 @@ pub async fn request_booking_extension( context.insert("extension_reason", extension_reason); context.insert("extension_date", extension_date); - tracing::error!("it needs to get send to {}", config::settings().notifications.admin_send_to_email.clone().expect("expected admin email address").as_address_string()); + tracing::error!( + "it needs to get send to {}", + config::settings() + .notifications + .admin_send_to_email + .clone() + .expect("expected admin email address") + .as_address_string() + ); let notification = Notification { - title: format!("Booking Extension Request ({} - {})", info.project, info.purpose), + title: format!( + "Booking Extension Request ({} - {})", + info.project, info.purpose + ), send_to: format!("N/A"), // Ignored by the send_to_admins_email_template() function. by_methods: vec![Method::Email()], situation: Situation::RequestBookingExtension, @@ -405,16 +426,14 @@ pub async fn request_booking_extension( attachment: None, }; -match send_to_admins_email_template(env, notification).await { - Ok(_) => { - Ok(()) - } - Err(e) => { - tracing::error!("Failed to send email with error {e:#?}"); - Err(vec![e]) + match send_to_admins_email_template(env, notification).await { + Ok(_) => Ok(()), + Err(e) => { + tracing::error!("Failed to send email with error {e:#?}"); + Err(vec![e]) + } } } -} /// Send email containing ipa username, temp password, openvpn config, and instructions pub async fn send_new_account_notification( @@ -433,8 +452,16 @@ pub async fn send_new_account_notification( })) .expect("Expected to create context for notification"), attachment: Some(AttachmentInfo { - name: "os-vpn-client.ovpn".to_owned(), - path: PathBuf::from("./config_data/os-vpn-client.ovpn"), + name: settings() + .notifications + .vpn_config_path + .file_name() + .expect("expected a file name") + .to_str() + .expect("expected a string") + .to_owned(), + + path: settings().notifications.vpn_config_path.clone(), }), }; @@ -479,12 +506,14 @@ pub struct AccessInfo { // } static TERA: once_cell::sync::Lazy = - once_cell::sync::Lazy::new(|| match Tera::new(&settings().notifications.templates_directory) { - Ok(t) => t, - Err(e) => { - panic!("Couldn't create templating instance, failure: {e}") - } - }); + once_cell::sync::Lazy::new( + || match Tera::new(&settings().notifications.templates_directory) { + Ok(t) => t, + Err(e) => { + panic!("Couldn't create templating instance, failure: {e}") + } + }, + ); pub mod templates { pub fn retrieve( diff --git a/sample_config.yaml b/sample_config.yaml index 8e35c00..08c79c0 100644 --- a/sample_config.yaml +++ b/sample_config.yaml @@ -38,6 +38,7 @@ notifications: username: example domain: mail.com templates_directory: templates/**/*.html + vpn_config_path: /etc/laas-reflab/os-vpn-client.ovpn cobbler: url: http://cobbler.example.com/cobbler_api @@ -99,4 +100,4 @@ projects: email: "" phone: "" is_dynamic: false - dashboard_url: https://example.iol.unh.edu/ \ No newline at end of file + dashboard_url: https://example.iol.unh.edu/