Repository: bottlerocket-os/bottlerocket
File: sources/api/thar-be-updates/src/status.rs (Rust)

Code before:
use crate::error;
use crate::error::Result;
use bottlerocket_release::BottlerocketRelease;
use chrono::{DateTime, Utc};
use modeled_types::{FriendlyVersion, Url};
use serde::{Deserialize, Serialize};
use signpost::State;
use snafu::{OptionExt, ResultExt};
use std::convert::TryInto;
use std::fs;
use std::fs::File;
use std::os::unix::process::ExitStatusExt;
use std::path::Path;
use std::process::Output;

pub const UPDATE_LOCKFILE: &str = "/run/lock/thar-be-updates.lock";
pub const UPDATE_STATUS_FILE: &str = "/run/cache/thar-be-updates/status.json";

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
struct UpdatesSettings {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    metadata_base_url: Option<Url>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    targets_base_url: Option<Url>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    seed: Option<u32>,
    // Version to update to when updating via the API.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    version_lock: Option<FriendlyVersion>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    ignore_waves: Option<bool>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum UpdateState {
    Idle,
    Available,
    Staged,
    Ready,
}

/// UpdateImage represents a Bottlerocket update image
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UpdateImage {
    arch: String,
    version: semver::Version,
    variant: String,
}


Review comment (bug):
Per other note you can specialize this struct to just the settings needed:
```suggestion
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct UpdatesSettings {
    version_lock: Option<FriendlyVersion>,
}
```

Code after:
use crate::error;
use crate::error::Result;
use bottlerocket_release::BottlerocketRelease;
use chrono::{DateTime, Utc};
use modeled_types::FriendlyVersion;
use serde::{Deserialize, Serialize};
use signpost::State;
use snafu::{OptionExt, ResultExt};
use std::convert::TryInto;
use std::fs;
use std::fs::File;
use std::os::unix::process::ExitStatusExt;
use std::path::Path;
use std::process::Output;

pub const UPDATE_LOCKFILE: &str = "/run/lock/thar-be-updates.lock";
pub const UPDATE_STATUS_FILE: &str = "/run/cache/thar-be-updates/status.json";

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
struct UpdatesSettings {
    // Version to update to when updating via the API.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    version_lock: Option<FriendlyVersion>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum UpdateState {
    Idle,
    Available,
    Staged,
    Ready,
}

/// UpdateImage represents a Bottlerocket update image
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UpdateImage {
    arch: String,
    version: semver::Version,
    variant: String,
}

impl UpdateImage {
    pub fn version(&self) -> &semver::Version {
        &self.version
    }
}

/// StagedImage represents a Bottlerocket image that is written to a partition set
#[derive(Debug, Clone, Deserialize, Serialize)]