-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #895 from DefGuard/updates-ui
* core update notification ui (modal) * feat: version update notification as custom toast * cleanup * update check backend * core updates frontend * cleanup * update lockfile --------- Co-authored-by: Filip Ślęzak <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,178 additions
and
220 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use axum::http::StatusCode; | ||
use serde_json::json; | ||
|
||
use super::{ApiResponse, ApiResult}; | ||
use crate::{ | ||
auth::{AdminRole, SessionInfo}, | ||
updates::get_update, | ||
}; | ||
|
||
pub async fn check_new_version(_admin: AdminRole, session: SessionInfo) -> ApiResult { | ||
debug!( | ||
"User {} is checking if there is a new version available", | ||
session.user.username | ||
); | ||
let update = get_update(); | ||
if let Some(update) = update.as_ref() { | ||
debug!("A new version is available, returning the update information"); | ||
Ok(ApiResponse { | ||
json: json!(update), | ||
status: StatusCode::OK, | ||
}) | ||
} else { | ||
debug!("No new version available"); | ||
Ok(ApiResponse { | ||
json: serde_json::json!({ "message": "No updates available" }), | ||
status: StatusCode::NO_CONTENT, | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::{ | ||
env, | ||
sync::{RwLock, RwLockReadGuard}, | ||
}; | ||
|
||
use chrono::NaiveDate; | ||
use semver::Version; | ||
|
||
const PRODUCT_NAME: &str = "Defguard"; | ||
const UPDATES_URL: &str = "https://update-service-dev.defguard.net/api/update/check"; | ||
const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
#[derive(Deserialize, Debug, Serialize)] | ||
pub struct Update { | ||
version: String, | ||
release_date: NaiveDate, | ||
release_notes_url: String, | ||
update_url: String, | ||
critical: bool, | ||
notes: String, | ||
} | ||
|
||
static NEW_UPDATE: RwLock<Option<Update>> = RwLock::new(None); | ||
|
||
fn set_update(update: Update) { | ||
*NEW_UPDATE | ||
.write() | ||
.expect("Failed to acquire lock on the update.") = Some(update); | ||
} | ||
|
||
pub fn get_update() -> RwLockReadGuard<'static, Option<Update>> { | ||
NEW_UPDATE | ||
.read() | ||
.expect("Failed to acquire lock on the update.") | ||
} | ||
|
||
async fn fetch_update() -> Result<Update, anyhow::Error> { | ||
let body = serde_json::json!({ | ||
"product": PRODUCT_NAME, | ||
"client_version": VERSION, | ||
"operating_system": env::consts::OS, | ||
}); | ||
let response = reqwest::Client::new() | ||
.post(UPDATES_URL) | ||
.json(&body) | ||
.send() | ||
.await?; | ||
Ok(response.json::<Update>().await?) | ||
} | ||
|
||
pub(crate) async fn do_new_version_check() -> Result<(), anyhow::Error> { | ||
debug!("Checking for new version of Defguard ..."); | ||
let update = fetch_update().await?; | ||
let current_version = Version::parse(VERSION)?; | ||
let new_version = Version::parse(&update.version)?; | ||
if new_version > current_version { | ||
if update.critical { | ||
warn!("There is a new critical Defguard update available: {} (Released on {}). It's recommended to update as soon as possible.", | ||
update.version, update.release_date); | ||
} else { | ||
info!( | ||
"There is a new Defguard version available: {} (Released on {})", | ||
update.version, update.release_date | ||
); | ||
} | ||
set_update(update); | ||
} else { | ||
debug!("New version check done. You are using the latest version of Defguard."); | ||
} | ||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
PROXY_TARGET=https://defguard-dev.teonite.net |
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
Oops, something went wrong.