mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
* help ios downlaod .crt and add begin add masked for addresses * only require and show CA for public domain if addSsl * fix type and revert i18n const * feat: add address masking and adjust design (#3088) * feat: add address masking and adjust design * update lockfile * chore: move eye button to actions * chore: refresh notifications and handle action error * static width for health check name --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> * hide certificate authorities tab * alpha.17 * add waiting health check status * remove "on" from waiting message * reject on abort in `.watch` * id migration: nostr -> nostr-rs-relay * health check waiting state * use interface type for launch button * better wording for masked * cleaner * sdk improvements * fix type error * fix notification badge issue --------- Co-authored-by: Alex Inkin <alexander@inkin.ru> Co-authored-by: Aiden McClelland <me@drbonez.dev>
110 lines
4.0 KiB
Rust
110 lines
4.0 KiB
Rust
use std::str::FromStr;
|
|
|
|
use clap::builder::ValueParserFactory;
|
|
use serde::{Deserialize, Serialize};
|
|
use ts_rs::TS;
|
|
|
|
pub use crate::HealthCheckId;
|
|
use crate::util::FromStrParser;
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct NamedHealthCheckResult {
|
|
pub name: String,
|
|
#[serde(flatten)]
|
|
pub kind: NamedHealthCheckResultKind,
|
|
}
|
|
// healthCheckName:kind:message OR healthCheckName:kind
|
|
impl FromStr for NamedHealthCheckResult {
|
|
type Err = color_eyre::eyre::Report;
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
let from_parts = |name: &str, kind: &str, message: Option<&str>| {
|
|
let message = message.map(|x| x.to_string());
|
|
let kind = match kind {
|
|
"success" => NamedHealthCheckResultKind::Success { message },
|
|
"disabled" => NamedHealthCheckResultKind::Disabled { message },
|
|
"starting" => NamedHealthCheckResultKind::Starting { message },
|
|
"waiting" => NamedHealthCheckResultKind::Waiting { message },
|
|
"loading" => NamedHealthCheckResultKind::Loading {
|
|
message: message.unwrap_or_default(),
|
|
},
|
|
"failure" => NamedHealthCheckResultKind::Failure {
|
|
message: message.unwrap_or_default(),
|
|
},
|
|
_ => return Err(color_eyre::eyre::eyre!("Invalid health check kind")),
|
|
};
|
|
Ok(Self {
|
|
name: name.to_string(),
|
|
kind,
|
|
})
|
|
};
|
|
let parts = s.split(':').collect::<Vec<_>>();
|
|
match &*parts {
|
|
[name, kind, message] => from_parts(name, kind, Some(message)),
|
|
[name, kind] => from_parts(name, kind, None),
|
|
_ => Err(color_eyre::eyre::eyre!(
|
|
"Could not match the shape of the result ${parts:?}"
|
|
)),
|
|
}
|
|
}
|
|
}
|
|
impl ValueParserFactory for NamedHealthCheckResult {
|
|
type Parser = FromStrParser<Self>;
|
|
fn value_parser() -> Self::Parser {
|
|
FromStrParser::new()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[serde(tag = "result")]
|
|
pub enum NamedHealthCheckResultKind {
|
|
Success { message: Option<String> },
|
|
Disabled { message: Option<String> },
|
|
Starting { message: Option<String> },
|
|
Waiting { message: Option<String> },
|
|
Loading { message: String },
|
|
Failure { message: String },
|
|
}
|
|
impl std::fmt::Display for NamedHealthCheckResult {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
let name = &self.name;
|
|
match &self.kind {
|
|
NamedHealthCheckResultKind::Success { message } => {
|
|
if let Some(message) = message {
|
|
write!(f, "{name}: Succeeded ({message})")
|
|
} else {
|
|
write!(f, "{name}: Succeeded")
|
|
}
|
|
}
|
|
NamedHealthCheckResultKind::Disabled { message } => {
|
|
if let Some(message) = message {
|
|
write!(f, "{name}: Disabled ({message})")
|
|
} else {
|
|
write!(f, "{name}: Disabled")
|
|
}
|
|
}
|
|
NamedHealthCheckResultKind::Starting { message } => {
|
|
if let Some(message) = message {
|
|
write!(f, "{name}: Starting ({message})")
|
|
} else {
|
|
write!(f, "{name}: Starting")
|
|
}
|
|
}
|
|
NamedHealthCheckResultKind::Waiting { message } => {
|
|
if let Some(message) = message {
|
|
write!(f, "{name}: Waiting ({message})")
|
|
} else {
|
|
write!(f, "{name}: Waiting")
|
|
}
|
|
}
|
|
NamedHealthCheckResultKind::Loading { message } => {
|
|
write!(f, "{name}: Loading ({message})")
|
|
}
|
|
NamedHealthCheckResultKind::Failure { message } => {
|
|
write!(f, "{name}: Failed ({message})")
|
|
}
|
|
}
|
|
}
|
|
}
|