use std::collections::HashMap;
use serde::{Deserialize, Deserializer, Serialize};
use zbus::as_variant;
use zbus::{DeserializeDict, OwnedVariant, SerializeDict, Signature, Type};
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusInfo {
pub name: String,
pub description: Option<String>,
pub path: String,
#[zbus(rename = "type")]
pub r#type: String,
pub parent_class: Option<String>,
pub artifacts: Vec<ArtifactStatusArtifactInfo>,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusArtifactInfo {
pub name: String,
pub instances: Vec<ArtifactStatusInstanceInfo>,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct ArtifactStatusInstanceInfo {
pub checksum: String,
pub references: Vec<String>,
}
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotState {
Booted,
Active,
Inactive,
}
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotBootStatus {
Good,
Bad,
Unknown,
}
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum SlotInstallationStatus {
Ok,
Failed,
Pending,
}
pub type SlotName = String;
#[derive(Type, Debug, Clone, PartialEq, Eq, Hash)]
#[zbus(signature = "s")]
pub enum SlotIdentifier {
Booted,
Other,
Named(SlotName),
}
impl SlotIdentifier {
pub fn as_str(&self) -> &str {
match self {
Self::Booted => "booted",
Self::Other => "other",
Self::Named(name) => name,
}
}
}
impl Serialize for SlotIdentifier {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct GetSlotStatusInfo {
pub class: String,
pub device: String,
#[zbus(rename = "type")]
pub r#type: String,
pub bootname: Option<String>,
pub state: Option<SlotState>,
pub parent: Option<String>,
pub mountpoint: Option<String>,
pub boot_status: Option<SlotBootStatus>,
pub status: Option<SlotInstallationStatus>,
pub sha256: Option<String>,
pub size: Option<u64>,
#[zbus(rename = "installed.timestamp")]
pub installed_timestamp: Option<String>,
#[zbus(rename = "installed.count")]
pub installed_count: Option<u32>,
#[zbus(rename = "installed.transaction")]
pub installed_transaction: Option<String>,
#[zbus(rename = "activated.timestamp")]
pub activated_timestamp: Option<String>,
#[zbus(rename = "activated.count")]
pub activated_count: Option<u32>,
#[zbus(rename = "bundle.compatible")]
pub bundle_compatible: Option<String>,
#[zbus(rename = "bundle.version")]
pub bundle_version: Option<String>,
#[zbus(rename = "bundle.description")]
pub bundle_description: Option<String>,
#[zbus(rename = "bundle.build")]
pub bundle_build: Option<String>,
#[zbus(rename = "bundle.hash")]
pub bundle_hash: Option<String>,
}
#[derive(SerializeDict, DeserializeDict, Type, Debug, Clone, PartialEq, Eq, Default)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleArgs {
pub tls_cert: Option<String>,
pub tls_key: Option<String>,
pub tls_ca: Option<String>,
pub http_headers: Option<Vec<String>>,
pub tls_no_verify: Option<bool>,
}
#[derive(Deserialize, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}")]
#[serde(rename_all = "kebab-case")]
pub struct InspectBundleInfo {
#[serde(with = "as_variant")]
pub manifest_hash: String,
#[serde(deserialize_with = "decode_variant_layers")]
pub update: InspectBundleUpdateInfo,
#[serde(deserialize_with = "decode_variant_layers")]
pub bundle: InspectBundleBundleInfo,
#[serde(default, deserialize_with = "decode_optional_variant_layers")]
pub hooks: Option<InspectBundleHooksInfo>,
#[serde(default, deserialize_with = "decode_optional_variant_layers")]
pub handler: Option<InspectBundleHandlerInfo>,
#[serde(deserialize_with = "decode_variant_layers")]
pub images: Vec<InspectBundleImageInfo>,
#[serde(deserialize_with = "decode_variant_layers")]
pub meta: HashMap<String, HashMap<String, String>>,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleUpdateInfo {
pub compatible: String,
pub version: Option<String>,
pub description: Option<String>,
pub build: Option<String>,
}
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum BundleFormat {
Plain,
Verity,
Crypt,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleBundleInfo {
pub format: BundleFormat,
pub verity_size: Option<u64>,
pub verity_salt: Option<String>,
pub verity_hash: Option<String>,
}
#[derive(Deserialize, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}")]
#[serde(rename_all = "kebab-case")]
pub struct InspectBundleHooksInfo {
#[serde(with = "as_variant")]
pub filename: String,
#[serde(deserialize_with = "decode_variant_layers")]
pub hooks: Vec<String>,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleHandlerInfo {
pub filename: String,
pub args: Option<String>,
}
#[derive(DeserializeDict, Type, Debug, Clone, PartialEq, Eq)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InspectBundleImageInfo {
pub slot_class: String,
pub variant: Option<String>,
pub filename: Option<String>,
#[zbus(rename = "type")]
pub r#type: Option<String>,
pub checksum: Option<String>,
pub size: Option<u64>,
pub hooks: Vec<String>,
pub adaptive: Option<Vec<String>>,
}
#[derive(SerializeDict, DeserializeDict, Type, Debug, Clone, PartialEq, Eq, Default)]
#[zbus(signature = "a{sv}", rename_all = "kebab-case")]
pub struct InstallBundleArgs {
pub ignore_compatible: Option<bool>,
pub ignore_version_limit: Option<bool>,
pub transaction_id: Option<String>,
pub require_manifest_hash: Option<String>,
pub tls_cert: Option<String>,
pub tls_key: Option<String>,
pub tls_ca: Option<String>,
pub http_headers: Option<Vec<String>>,
pub tls_no_verify: Option<bool>,
}
#[derive(Serialize, Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
#[zbus(signature = "s")]
pub enum MarkState {
Good,
Bad,
Active,
}
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MarkInfo {
pub slot_name: String,
pub message: String,
}
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[zbus(signature = "s", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum Operation {
Idle,
Installing,
}
#[derive(Deserialize, Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(from = "i32")]
#[zbus(signature = "i")]
pub enum InstallationResult {
Success,
Failure(i32),
}
impl From<i32> for InstallationResult {
fn from(code: i32) -> Self {
match code {
0 => Self::Success,
code => Self::Failure(code),
}
}
}
#[derive(OwnedVariant, Type, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Progress {
pub percentage: i32,
pub message: String,
pub nesting_depth: i32,
}
#[derive(Deserialize)]
struct Variant<T> {
#[allow(dead_code)]
signature: Signature,
value: T,
}
fn decode_variant_layers<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Type + 'de,
{
let wrapped = Variant::<as_variant::Deserialize<'de, T>>::deserialize(deserializer)?;
Ok(wrapped.value.0)
}
fn decode_optional_variant_layers<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Type + 'de,
{
decode_variant_layers(deserializer).map(Some)
}