feat: hourly CVE alerting with notification bell and API (#53)
All checks were successful
All checks were successful
This commit was merged in pull request #53.
This commit is contained in:
91
compliance-dashboard/src/infrastructure/notifications.rs
Normal file
91
compliance-dashboard/src/infrastructure/notifications.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
use dioxus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct NotificationListResponse {
|
||||
pub data: Vec<CveNotificationData>,
|
||||
#[serde(default)]
|
||||
pub total: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct CveNotificationData {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: Option<serde_json::Value>,
|
||||
pub cve_id: String,
|
||||
pub repo_name: String,
|
||||
pub package_name: String,
|
||||
pub package_version: String,
|
||||
pub severity: String,
|
||||
pub cvss_score: Option<f64>,
|
||||
pub summary: Option<String>,
|
||||
pub url: Option<String>,
|
||||
pub status: String,
|
||||
#[serde(default)]
|
||||
pub created_at: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct NotificationCountResponse {
|
||||
pub count: u64,
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn fetch_notification_count() -> Result<u64, ServerFnError> {
|
||||
let state: super::server_state::ServerState =
|
||||
dioxus_fullstack::FullstackContext::extract().await?;
|
||||
|
||||
let url = format!("{}/api/v1/notifications/count", state.agent_api_url);
|
||||
let resp = reqwest::get(&url)
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
let body: NotificationCountResponse = resp
|
||||
.json()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(body.count)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn fetch_notifications() -> Result<NotificationListResponse, ServerFnError> {
|
||||
let state: super::server_state::ServerState =
|
||||
dioxus_fullstack::FullstackContext::extract().await?;
|
||||
|
||||
let url = format!("{}/api/v1/notifications?limit=20", state.agent_api_url);
|
||||
let resp = reqwest::get(&url)
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
let body: NotificationListResponse = resp
|
||||
.json()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn mark_all_notifications_read() -> Result<(), ServerFnError> {
|
||||
let state: super::server_state::ServerState =
|
||||
dioxus_fullstack::FullstackContext::extract().await?;
|
||||
|
||||
let url = format!("{}/api/v1/notifications/read-all", state.agent_api_url);
|
||||
reqwest::Client::new()
|
||||
.post(&url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn dismiss_notification(id: String) -> Result<(), ServerFnError> {
|
||||
let state: super::server_state::ServerState =
|
||||
dioxus_fullstack::FullstackContext::extract().await?;
|
||||
|
||||
let url = format!("{}/api/v1/notifications/{id}/dismiss", state.agent_api_url);
|
||||
reqwest::Client::new()
|
||||
.patch(&url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user