-
Notifications
You must be signed in to change notification settings - Fork 6
chore: added ods version compatibility check #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5fc7a00
5d5aa99
1ad8ff7
8801416
e336899
150380a
c2a7c85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| use crate::common::VERSION_CHECK; | ||
| use crate::common::{config_path, validate_password, validate_token_and_claims}; | ||
| use crate::middleware::TOKEN_EXPIRE_HOURS; | ||
| use crate::socket_client::*; | ||
|
|
@@ -113,7 +114,19 @@ impl Api { | |
|
|
||
| pub async fn healthcheck() -> impl Responder { | ||
| debug!("healthcheck() called"); | ||
| HttpResponse::Ok().finish() | ||
|
|
||
| let info = VERSION_CHECK.lock().unwrap().clone(); | ||
|
|
||
| match info { | ||
| Some(result) => { | ||
| if result.is_below_min { | ||
| HttpResponse::InternalServerError().json(result) | ||
ronny-standtke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| HttpResponse::Ok().json(result) | ||
| } | ||
| } | ||
| None => HttpResponse::Ok().body("No version check performed yet"), | ||
| } | ||
|
Comment on lines
117
to
129
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. healthcheck must be called in another PR during startup and handle the result
JanZachmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| pub async fn factory_reset( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,28 @@ | ||
| use crate::MIN_ODS_VERSION; | ||
| use actix_web::body::MessageBody; | ||
| use anyhow::{anyhow, bail, Context, Result}; | ||
| use argon2::{Argon2, PasswordHash, PasswordVerifier}; | ||
| use base64::{prelude::BASE64_STANDARD, Engine}; | ||
| use jwt_simple::prelude::{RS256PublicKey, RSAPublicKeyLike}; | ||
| use reqwest::blocking::get; | ||
| use semver::Version; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::{fs, io::Write, path::Path}; | ||
| use std::{ | ||
| fs, | ||
| io::Write, | ||
| path::Path, | ||
| sync::{LazyLock, Mutex}, | ||
| }; | ||
|
|
||
| #[derive(Clone, Debug, Serialize)] | ||
| pub struct VersionCheckResult { | ||
| pub min_version: String, | ||
| pub current_version: String, | ||
| pub is_below_min: bool, | ||
| } | ||
|
|
||
| pub static VERSION_CHECK: LazyLock<Mutex<Option<VersionCheckResult>>> = | ||
| LazyLock::new(|| Mutex::new(None)); | ||
|
|
||
| #[derive(Deserialize)] | ||
| pub struct RealmInfo { | ||
|
|
@@ -30,6 +47,7 @@ pub struct StatusResponse { | |
| #[derive(Deserialize)] | ||
| pub struct SystemInfo { | ||
| pub fleet_id: Option<String>, | ||
| pub omnect_device_service_version: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Deserialize)] | ||
|
|
@@ -199,3 +217,32 @@ pub fn create_frontend_config_file(keycloak_url: &str) -> Result<()> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn check_and_store_ods_version(ods_socket_path: &str) -> Result<()> { | ||
| let status_response = get_status(ods_socket_path) | ||
| .await | ||
| .context("Failed to get status from socket client")?; | ||
ronny-standtke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let Some(omnect_device_service_version) = | ||
| &status_response.system_info.omnect_device_service_version | ||
| else { | ||
| bail!("failed to get omnect_device_service_version from status response") | ||
| }; | ||
|
||
|
|
||
| let ods_version = omnect_device_service_version.clone(); | ||
JanZachmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // compare to MIN_ODS_VERSION | ||
| let min_version = Version::parse(MIN_ODS_VERSION).expect("parse MIN_ODS_VERSION"); | ||
| let current_version = Version::parse(&ods_version).expect("parse ods_version"); | ||
| let is_below_min = current_version < min_version; | ||
| { | ||
| let mut version_check = VERSION_CHECK.lock().unwrap(); | ||
| *version_check = Some(VersionCheckResult { | ||
| min_version: MIN_ODS_VERSION.to_string(), | ||
| current_version: ods_version.clone(), | ||
| is_below_min, | ||
| }); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,8 @@ use tokio::{ | |
| }; | ||
| use uuid::Uuid; | ||
|
|
||
| pub const MIN_ODS_VERSION: &str = "0.39.0"; | ||
|
|
||
|
||
| const UPLOAD_LIMIT_BYTES: usize = 250 * 1024 * 1024; | ||
| const MEMORY_LIMIT_BYTES: usize = 10 * 1024 * 1024; | ||
|
|
||
|
|
@@ -120,11 +122,16 @@ async fn main() { | |
| .parse::<u64>() | ||
| .expect("UI_PORT format"); | ||
|
|
||
| let ods_socket_path = std::env::var("SOCKET_PATH").expect("env SOCKET_PATH is missing"); | ||
ronny-standtke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| common::check_and_store_ods_version(&ods_socket_path) | ||
| .await | ||
| .expect("failed to check and store ods version"); | ||
|
|
||
| CryptoProvider::install_default(default_provider()).expect("failed to install crypto provider"); | ||
|
|
||
| certificate::create_module_certificate(&cert_path!(), &key_path!()) | ||
| .await | ||
| .expect("Failed to create module certificate"); | ||
| .expect("failed to create module certificate"); | ||
|
|
||
| let mut tls_certs = | ||
| std::io::BufReader::new(std::fs::File::open(cert_path!()).expect("read certs_file")); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.