Skip to content
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

Add Summary and Applications tabs #2

Merged
merged 11 commits into from
Sep 2, 2024
48 changes: 39 additions & 9 deletions src/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::events::Event;
use crate::model::{Model, MonitorModel};
use crate::model::model::Model;
use crate::model::model::MonitorModel;
use crate::raw_model::RawModel;
use crate::ui::ui::Ui;
use core::fmt::Debug;
Expand Down Expand Up @@ -91,24 +92,55 @@ impl Application {
}
IpcMessage::NetworkStatus(cfg) => {
debug!("Got Network status");
self.raw_model.set_network_status(cfg);
self.model.borrow_mut().update_network_status(cfg);
}
IpcMessage::AppStatus(app) => {
debug!("Got AppStatus");
self.model.borrow_mut().update_app_status(app);
}

IpcMessage::DownloaderStatus(cfg) => {
self.raw_model.set_downloader_status(cfg);
IpcMessage::DownloaderStatus(dnl) => {
debug!("Got DownloaderStatus");
self.model.borrow_mut().update_downloader_status(dnl);
}

// this event is guaranteed to be sent before periodic events
IpcMessage::AppSummary(summary) => {
debug!("Got AppSummary");
self.model.borrow_mut().update_app_summary(summary);
}

// this event is guaranteed to be sent before periodic events
IpcMessage::NodeStatus(node_status) => {
debug!("Got NodeStatus");
self.model.borrow_mut().update_node_status(node_status);
}

IpcMessage::OnboardingStatus(o_status) => {
debug!("Got OnboardingStatus");
self.model.borrow_mut().update_onboarding_status(o_status);
}

IpcMessage::VaultStatus(status) => {
debug!("Got VaultStatus");
self.model.borrow_mut().update_vault_status(status);
}

IpcMessage::LedBlinkCounter(led) => {
// self.raw_model.set_led_blink_counter(led);
debug!("Got LedBlinkCounter");
}

// this event is guaranteed to be sent before periodic events
IpcMessage::AppsList(app_list) => {
debug!("Got AppsList");
self.model.borrow_mut().update_app_list(app_list);
}

_ => {
warn!("Unhandled IPC message: {:?}", msg);
}
}
self.model
.borrow_mut()
.update_from_raw_model(&self.raw_model);
}

pub fn send_dpc(&self) {
Expand Down Expand Up @@ -316,8 +348,6 @@ impl Application {
}

pub async fn run(&mut self) -> Result<()> {
println!("Running application");

let (ipc_task, ipc_cancellation_token, mut ipc_rx) = self.create_ipc_task();

// TODO: handle suspend/resume for the case when we give away /dev/tty
Expand Down
2 changes: 1 addition & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crossterm::event::KeyEvent;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub enum Event {
Key(KeyEvent),
Tick,
Expand Down
108 changes: 108 additions & 0 deletions src/ipc/eve_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use macaddr::MacAddr8;
use serde::de;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::collections::HashMap;
use std::default;
use std::net::IpAddr;
use strum::Display;
Expand Down Expand Up @@ -963,6 +964,7 @@ pub enum ErrorSeverity {
#[serde(rename_all = "PascalCase")]
pub struct ErrorEntity {
pub entity_type: ErrorEntityType,
#[serde(rename = "EntityID")]
pub entity_id: String,
}

Expand Down Expand Up @@ -1137,6 +1139,11 @@ pub enum SwState {
MaxState = 125,
}

impl SwState {
pub fn to_string(&self) -> String {
format!("{}", self)
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct UUIDandVersion {
Expand Down Expand Up @@ -1269,3 +1276,104 @@ pub struct IoAdapter {} // Replace with actual definition

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)]
pub struct SnapshottingStatus {} // Replace with actual definition

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct EveOnboardingStatus {
#[serde(rename = "DeviceUUID")]
pub device_uuid: Uuid,
pub hardware_model: String, // From controller
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct EveVaultStatus {
pub name: String,
pub status: DataSecAtRestStatus,
#[serde(rename = "PCRStatus")]
pub pcr_status: PCRStatus,
pub conversion_complete: bool,
#[serde(rename = "MissmatchingPCRs")]
pub missmatching_pcrs: Option<Vec<i32>>,
#[serde(flatten)]
pub error_and_time: ErrorAndTime, // Unknown type, skipped
}

#[repr(i32)]
#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Clone)]
pub enum DataSecAtRestStatus {
DataSecAtRestUnknown = 0, // Status is unknown
DataSecAtRestDisabled = 1, // Enabled, but not being used
DataSecAtRestEnabled = 2, // Enabled, and used
DataSecAtRestError = 4, // Enabled, but encountered an error
}

#[repr(i32)]
#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Clone)]
pub enum PCRStatus {
PcrUnknown = 0, // Status is unknown
PcrEnabled = 1, // Enabled PCR
PcrDisabled = 2, // Disabled PCR
}

type AppCount = u8;

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct AppInstanceSummary {
//#[serde(rename = "UUIDandVersion")]
//pub uuid_and_version: UUIDandVersion,
pub total_starting: AppCount, // Total number of apps starting/booting
pub total_running: AppCount, // Total number of apps in running state
pub total_stopping: AppCount, // Total number of apps in halting state
pub total_error: AppCount, // Total number of apps in error state
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct LedBlinkCounter {
pub blink_counter: LedBlinkCount,
}

#[repr(u8)]
#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Clone)]
pub enum LedBlinkCount {
LedBlinkUndefined = 0,
LedBlinkWaitingForIP,
LedBlinkConnectingToController,
LedBlinkConnectedToController,
LedBlinkOnboarded,
LedBlinkRadioSilence,
LedBlinkOnboardingFailure = 10,
LedBlinkRespWithoutTLS = 12,
LedBlinkRespWithoutOSCP,
LedBlinkInvalidControllerCert,
LedBlinkInvalidAuthContainer,
LedBlinkInvalidBootstrapConfig,
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct EveNodeStatus {
pub server: Option<String>,
#[serde(deserialize_with = "zero_uuid_as_none")]
pub node_uuid: Option<Uuid>,
pub onboarded: bool,
pub app_instance_summary: Option<AppInstanceSummary>,
}

fn zero_uuid_as_none<'de, D>(deserializer: D) -> Result<Option<Uuid>, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s == "00000000-0000-0000-0000-000000000000" {
Ok(None)
} else {
Ok(Some(Uuid::parse_str(&s).map_err(serde::de::Error::custom)?))
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AppsList {
pub apps: Vec<AppInstanceStatus>,
}
13 changes: 13 additions & 0 deletions src/ipc/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ use bytes::BytesMut;
use log::error;
use serde::Deserialize;
use serde::Serialize;
use uuid::Uuid;

use super::eve_types::AppInstanceStatus;
use super::eve_types::AppInstanceSummary;
use super::eve_types::AppsList;
use super::eve_types::DeviceNetworkStatus;
use super::eve_types::DevicePortConfig;
use super::eve_types::DevicePortConfigList;
use super::eve_types::DownloaderStatus;
use super::eve_types::EveNodeStatus;
use super::eve_types::EveOnboardingStatus;
use super::eve_types::EveVaultStatus;
use super::eve_types::LedBlinkCounter;
use super::eve_types::PhysicalIOAdapterList;

/// WindowId is a unique identifier for a window that is incremented sequentially.
Expand Down Expand Up @@ -45,6 +52,12 @@ pub enum IpcMessage {
DownloaderStatus(DownloaderStatus),
IOAdapters(PhysicalIOAdapterList),
AppStatus(AppInstanceStatus),
AppSummary(AppInstanceSummary),
VaultStatus(EveVaultStatus),
OnboardingStatus(EveOnboardingStatus),
LedBlinkCounter(LedBlinkCounter),
NodeStatus(EveNodeStatus),
AppsList(AppsList),
Response {
#[serde(flatten)]
result: core::result::Result<String, String>,
Expand Down
Loading