-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure app works without notifications, or gitops configured. Fix def…
…aults so helm values.yaml with minimal config functions.
- Loading branch information
1 parent
8270a39
commit 7538cd1
Showing
4 changed files
with
169 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,34 +31,3 @@ config: | |
#default schedule is every 2 hours | ||
schedule: "0 0 */2 * *" | ||
data_dir: "/app/slackwatch/data" | ||
|
||
notifications: | ||
ntfy: | ||
url: "http://ntfy-server.default:80" # Assumes an 'ntfy-server' available in the 'default' namespace | ||
topic: "slackwatch-test" | ||
token: "slackwatch-ntfy-token" | ||
priority: 1 | ||
reminder: "24h" | ||
# ... other notification provider settings | ||
|
||
gitops: | ||
- name: "test-repo" # Placeholder name | ||
repository_url: "https://github.com/your-org/test-repo.git" | ||
branch: "main" | ||
access_token_env_name: "TEST_REPO_ACCESS_TOKEN" | ||
commit_message: "Automated commit by slackwatch" | ||
commit_email: "[email protected]" | ||
# ... other GitOps settings | ||
|
||
# Custom environment variables for the Slackwatch application | ||
#customEnv: | ||
# # Example of a direct value environment variable | ||
# # EXAMPLE_ENV_VAR: "example_value" | ||
# | ||
# # Environment variables that should be populated from secrets | ||
# # Users can comment out or remove if not needed | ||
# TEST_REPO_ACCESS_TOKEN: | ||
# fromSecret: | ||
# enabled: true | ||
# secretName: "TEST_REPO_ACCESS_TOKEN" | ||
# key: "tokensupersecret" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,133 @@ | ||
use crate::config::Settings; | ||
use dioxus::html::set; | ||
use dioxus::prelude::client; | ||
use dioxus::prelude::server_fn::response::Res; | ||
use crate::config::{Ntfy, Settings}; | ||
use crate::models::models::Workload; | ||
use ntfy::payload::{Action, ActionType}; | ||
use ntfy::{Auth, Dispatcher, NtfyError, Payload, Priority}; | ||
use wasm_bindgen_futures::js_sys::Atomics::load; | ||
use wasm_bindgen_futures::js_sys::Set; | ||
|
||
|
||
pub async fn notify_commit(workload: &Workload) -> Result<(), NtfyError> { | ||
//get settings | ||
let settings = Settings::new().unwrap(); | ||
let token = settings.notifications.ntfy.token; | ||
let topic = settings.notifications.ntfy.topic; | ||
let url = settings.notifications.ntfy.url; | ||
|
||
let dispatcher = Dispatcher::builder(&url) | ||
.credentials(Auth::new("", &token)) // Add optional credentials | ||
.build()?; // Build dispatcher | ||
|
||
//let action = Action::new( | ||
// ActionType::Http, | ||
// "Acknowledge", | ||
// Url::parse(&url)?, | ||
//); | ||
|
||
//make message for payload about new container update | ||
let message = format!( | ||
"Deployment {} has been updated to version {}", | ||
workload.name, workload.latest_version | ||
); | ||
|
||
let payload = Payload::new(&topic) | ||
.message(message) // Add optional message | ||
.title(&workload.name) // Add optiona title | ||
.tags(["Update"]) // Add optional tags | ||
.priority(Priority::Default) // Edit priority | ||
//.actions([action]) // Add optional actions | ||
//.click(Url::parse("https://example.com")?) // Add optional clickable url | ||
//.attach(Url::parse("https://example.com/file.jpg")?) // Add optional url attachment | ||
//.delay(Local::now() + Duration::minutes(1)) // Add optional delay | ||
.markdown(true); // Use markdown | ||
|
||
match dispatcher.send(&payload).await { | ||
Ok(_) => log::info!("Payload sent successfully."), | ||
Err(e) => log::error!("Failed to send payload: {}", e), | ||
match load_settings() { | ||
Ok(settings) => { | ||
let url = settings.url; | ||
let topic = settings.topic; | ||
let token = settings.token; | ||
|
||
|
||
let dispatcher = Dispatcher::builder(&url) | ||
.credentials(Auth::new("", &token)) // Add optional credentials | ||
.build()?; // Build dispatcher | ||
|
||
//let action = Action::new( | ||
// ActionType::Http, | ||
// "Acknowledge", | ||
// Url::parse(&url)?, | ||
//); | ||
|
||
//make message for payload about new container update | ||
let message = format!( | ||
"Deployment {} has been updated to version {}", | ||
workload.name, workload.latest_version | ||
); | ||
|
||
let payload = Payload::new(&topic) | ||
.message(message) // Add optional message | ||
.title(&workload.name) // Add optiona title | ||
.tags(["Update"]) // Add optional tags | ||
.priority(Priority::Default) // Edit priority | ||
//.actions([action]) // Add optional actions | ||
//.click(Url::parse("https://example.com")?) // Add optional clickable url | ||
//.attach(Url::parse("https://example.com/file.jpg")?) // Add optional url attachment | ||
//.delay(Local::now() + Duration::minutes(1)) // Add optional delay | ||
.markdown(true); // Use markdown | ||
|
||
match dispatcher.send(&payload).await { | ||
Ok(_) => log::info!("Payload sent successfully."), | ||
Err(e) => log::error!("Failed to send payload: {}", e), | ||
} | ||
log::info!("Notification sent"); | ||
Ok(())// Proceed with using settings | ||
}, | ||
Err(e) => { | ||
log::info!("Failed to load settings: {}", e); | ||
Ok(()) | ||
// Handle the error, e.g., by returning or panicking | ||
} | ||
} | ||
log::info!("Notification sent"); | ||
Ok(()) | ||
|
||
|
||
} | ||
|
||
fn load_settings() ->Result<Ntfy, String> { | ||
//get settings | ||
let settings = Settings::new().unwrap_or_else(|err| { | ||
log::error!("Failed to load settings: {}", err); | ||
panic!("Failed to load settings: {}", err); | ||
}); | ||
if let Some(notifications) = settings.notifications { | ||
if let Some(ntfy_config) = notifications.ntfy { | ||
return Ok(ntfy_config.clone()); | ||
} else { | ||
return Err("No Ntfy Config Found".to_string()); | ||
} | ||
} else { | ||
return Err("No Notifications Config Found".to_string()); | ||
} | ||
|
||
} | ||
|
||
pub async fn send_notification(workload: &Workload) -> Result<(), NtfyError> { | ||
//get settings | ||
let settings = Settings::new().unwrap(); | ||
let token = settings.notifications.ntfy.token; | ||
let topic = settings.notifications.ntfy.topic; | ||
let url = settings.notifications.ntfy.url; | ||
|
||
let dispatcher = Dispatcher::builder(&url) | ||
.credentials(Auth::new("", &token)) // Add optional credentials | ||
.build()?; // Build dispatcher | ||
|
||
//let action = Action::new( | ||
// ActionType::Http, | ||
// "Acknowledge", | ||
// Url::parse(&url)?, | ||
//); | ||
|
||
//make message for payload about new container update | ||
let message = format!( | ||
"Update Available: {} From {} to {}", | ||
workload.name, workload.current_version, workload.latest_version | ||
); | ||
|
||
let payload = Payload::new(&topic) | ||
.message(message) // Add optional message | ||
.title(&workload.name) // Add optiona title | ||
.tags(["Update"]) // Add optional tags | ||
.priority(Priority::High) // Edit priority | ||
//.actions([action]) // Add optional actions | ||
//.click(Url::parse("https://example.com")?) // Add optional clickable url | ||
//.attach(Url::parse("https://example.com/file.jpg")?) // Add optional url attachment | ||
//.delay(Local::now() + Duration::minutes(1)) // Add optional delay | ||
.markdown(true); // Use markdown | ||
|
||
match dispatcher.send(&payload).await { | ||
Ok(_) => log::info!("Payload sent successfully."), | ||
Err(e) => log::error!("Failed to send payload: {}", e), | ||
match load_settings() { | ||
Ok(settings) => { | ||
let url = settings.url; | ||
let topic = settings.topic; | ||
let token = settings.token; | ||
|
||
let dispatcher = Dispatcher::builder(&url) | ||
.credentials(Auth::new("", &token)) // Add optional credentials | ||
.build()?; // Build dispatcher | ||
|
||
//let action = Action::new( | ||
// ActionType::Http, | ||
// "Acknowledge", | ||
// Url::parse(&url)?, | ||
//); | ||
|
||
//make message for payload about new container update | ||
let message = format!( | ||
"Update Available: {} From {} to {}", | ||
workload.name, workload.current_version, workload.latest_version | ||
); | ||
|
||
let payload = Payload::new(&topic) | ||
.message(message) // Add optional message | ||
.title(&workload.name) // Add optiona title | ||
.tags(["Update"]) // Add optional tags | ||
.priority(Priority::High) // Edit priority | ||
//.actions([action]) // Add optional actions | ||
//.click(Url::parse("https://example.com")?) // Add optional clickable url | ||
//.attach(Url::parse("https://example.com/file.jpg")?) // Add optional url attachment | ||
//.delay(Local::now() + Duration::minutes(1)) // Add optional delay | ||
.markdown(true); // Use markdown | ||
|
||
match dispatcher.send(&payload).await { | ||
Ok(_) => log::info!("Payload sent successfully."), | ||
Err(e) => log::error!("Failed to send payload: {}", e), | ||
} | ||
log::info!("Notification sent"); | ||
Ok(()) // Proceed with using settings | ||
}, | ||
Err(e) => { | ||
log::info!("Failed to load settings: {}", e); | ||
Ok(()) // Handle the error, e.g., by returning or panicking | ||
// Handle the error, e.g., by returning or panicking | ||
} | ||
} | ||
log::info!("Notification sent"); | ||
Ok(()) | ||
|
||
|
||
} |