Skip to content

Commit 88d1320

Browse files
authored
Merge pull request #59 from cgwalters/reexec-prep
install: Make install config serializable
2 parents 3179ba5 + 64af002 commit 88d1320

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rust-version = "1.63.0"
1010

1111
[dependencies]
1212
anyhow = "1.0"
13-
camino = "1.0.4"
13+
camino = { version = "1.0.4", features = ["serde1"] }
1414
ostree-ext = "0.10.5"
1515
clap = { version= "3.2", features = ["derive"] }
1616
clap_mangen = { version = "0.1", optional = true }

lib/src/install.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ostree_ext::container as ostree_container;
2222
use ostree_ext::container::SignatureSource;
2323
use ostree_ext::ostree;
2424
use ostree_ext::prelude::Cast;
25-
use serde::Serialize;
25+
use serde::{Deserialize, Serialize};
2626

2727
use crate::containerenv::ContainerExecutionInfo;
2828
use crate::lsm::lsm_label;
@@ -38,7 +38,8 @@ const RUN_BOOTC: &str = "/run/bootc";
3838
/// This is an ext4 special directory we need to ignore.
3939
const LOST_AND_FOUND: &str = "lost+found";
4040

41-
#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq)]
41+
#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
42+
#[serde(rename_all = "kebab-case")]
4243
pub(crate) enum BlockSetup {
4344
Direct,
4445
Tpm2Luks,
@@ -50,7 +51,7 @@ impl Default for BlockSetup {
5051
}
5152
}
5253

53-
#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq)]
54+
#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
5455
pub(crate) enum Filesystem {
5556
Xfs,
5657
Ext4,
@@ -88,12 +89,13 @@ const PREPPN: u32 = 1;
8889
#[cfg(target_arch = "ppc64")]
8990
const RESERVEDPN: u32 = 1;
9091

91-
#[derive(clap::Args, Debug, Clone)]
92+
#[derive(clap::Args, Debug, Clone, Serialize, Deserialize)]
9293
pub(crate) struct InstallTargetOpts {
9394
// TODO: A size specifier which allocates free space for the root in *addition* to the base container image size
9495
// pub(crate) root_additional_size: Option<String>
9596
/// The transport; e.g. oci, oci-archive. Defaults to `registry`.
9697
#[clap(long, default_value = "registry")]
98+
#[serde(default)]
9799
pub(crate) target_transport: String,
98100

99101
/// Specify the image to fetch for subsequent updates
@@ -102,14 +104,15 @@ pub(crate) struct InstallTargetOpts {
102104

103105
/// Explicitly opt-out of requiring any form of signature verification.
104106
#[clap(long)]
107+
#[serde(default)]
105108
pub(crate) target_no_signature_verification: bool,
106109

107110
/// Enable verification via an ostree remote
108111
#[clap(long)]
109112
pub(crate) target_ostree_remote: Option<String>,
110113
}
111114

112-
#[derive(clap::Args, Debug, Clone)]
115+
#[derive(clap::Args, Debug, Clone, Serialize, Deserialize)]
113116
pub(crate) struct InstallConfigOpts {
114117
/// Path to an Ignition config file
115118
#[clap(long, value_parser)]
@@ -127,6 +130,7 @@ pub(crate) struct InstallConfigOpts {
127130
/// This is currently necessary to install *from* a system with SELinux disabled
128131
/// but where the target does have SELinux enabled.
129132
#[clap(long)]
133+
#[serde(default)]
130134
pub(crate) disable_selinux: bool,
131135

132136
// Only occupy at most this much space (if no units are provided, GB is assumed).
@@ -139,24 +143,28 @@ pub(crate) struct InstallConfigOpts {
139143
}
140144

141145
/// Options for installing to a block device
142-
#[derive(Debug, Clone, clap::Args)]
146+
#[derive(Debug, Clone, clap::Args, Serialize, Deserialize)]
147+
#[serde(rename_all = "kebab-case")]
143148
pub(crate) struct InstallBlockDeviceOpts {
144149
/// Target block device for installation. The entire device will be wiped.
145150
pub(crate) device: Utf8PathBuf,
146151

147152
/// Automatically wipe all existing data on device
148153
#[clap(long)]
154+
#[serde(default)]
149155
pub(crate) wipe: bool,
150156

151157
/// Target root block device setup.
152158
///
153159
/// direct: Filesystem written directly to block device
154160
/// tpm2-luks: Bind unlock of filesystem to presence of the default tpm2 device.
155161
#[clap(long, value_enum, default_value_t)]
162+
#[serde(default)]
156163
pub(crate) block_setup: BlockSetup,
157164

158165
/// Target root filesystem type.
159166
#[clap(long, value_enum, default_value_t)]
167+
#[serde(default)]
160168
pub(crate) filesystem: Filesystem,
161169

162170
/// Size of the root partition (default specifier: M). Allowed specifiers: M (mebibytes), G (gibibytes), T (tebibytes).
@@ -167,15 +175,18 @@ pub(crate) struct InstallBlockDeviceOpts {
167175
}
168176

169177
/// Perform an installation to a block device.
170-
#[derive(Debug, Clone, clap::Parser)]
178+
#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize)]
171179
pub(crate) struct InstallOpts {
172180
#[clap(flatten)]
181+
#[serde(flatten)]
173182
pub(crate) block_opts: InstallBlockDeviceOpts,
174183

175184
#[clap(flatten)]
185+
#[serde(flatten)]
176186
pub(crate) target_opts: InstallTargetOpts,
177187

178188
#[clap(flatten)]
189+
#[serde(flatten)]
179190
pub(crate) config_opts: InstallConfigOpts,
180191
}
181192

@@ -1163,3 +1174,12 @@ pub(crate) async fn install_to_filesystem(opts: InstallToFilesystemOpts) -> Resu
11631174

11641175
Ok(())
11651176
}
1177+
1178+
#[test]
1179+
fn install_opts_serializable() {
1180+
let c: InstallOpts = serde_json::from_value(serde_json::json!({
1181+
"device": "/dev/vda"
1182+
}))
1183+
.unwrap();
1184+
assert_eq!(c.block_opts.device, "/dev/vda");
1185+
}

0 commit comments

Comments
 (0)