diff --git a/.github/workflows/fedora.yml b/.github/workflows/fedora.yml index cc9a94688f..a64c170233 100644 --- a/.github/workflows/fedora.yml +++ b/.github/workflows/fedora.yml @@ -45,9 +45,6 @@ jobs: - task: PROFILEDIR=debug make -f Makefile build toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN components: cargo - - task: PROFILEDIR=debug make -f Makefile build-test-extras - toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN - components: cargo - task: PROFILEDIR=debug make -f Makefile build-min toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN components: cargo diff --git a/Cargo.toml b/Cargo.toml index 1edd4ef048..bad3b71498 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,10 +71,6 @@ required-features = ["udev_scripts"] name = "stratis-utils" required-features = ["engine"] -[[bin]] -name = "stratis-legacy-pool" -required-features = ["test_extras"] - [dependencies.async-trait] version = "0.1.51" optional = true diff --git a/Makefile b/Makefile index 425ec7a6cd..9b7401e7c0 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,7 @@ endif MIN_FEATURES = --no-default-features --features engine,min NO_IPC_FEATURES = --no-default-features --features engine SYSTEMD_FEATURES = --no-default-features --features engine,min,systemd_compat -EXTRAS_FEATURES = --no-default-features --features engine,extras,min -TEST_EXTRAS_FEATURES = --no-default-features --features test_extras +EXTRAS_FEATURES = --no-default-features --features engine,extras,min,test_extras UDEV_FEATURES = --no-default-features --features udev_scripts UTILS_FEATURES = --no-default-features --features engine,systemd_compat @@ -193,12 +192,6 @@ stratisd-tools: cargo ${BUILD} ${RELEASE_FLAG} \ --bin=stratisd-tools ${EXTRAS_FEATURES} ${TARGET_ARGS} -## Build the test extras -build-test-extras: - PKG_CONFIG_ALLOW_CROSS=1 \ - cargo build ${RELEASE_FLAG} \ - --bin=stratis-legacy-pool ${TEST_EXTRAS_FEATURES} ${TARGET_ARGS} - ## Build the stratis-dumpmetadata program ## Build stratis-min for early userspace stratis-min: @@ -421,12 +414,8 @@ clippy-utils: clippy-no-ipc: cargo clippy ${CLIPPY_OPTS} ${NO_IPC_FEATURES} -## Run clippy on no-ipc-build -clippy-test-extras: - cargo clippy ${CLIPPY_OPTS} ${TEST_EXTRAS_FEATURES} - ## Run clippy on the current source tree -clippy: clippy-macros clippy-min clippy-udev-utils clippy-no-ipc clippy-utils clippy-test-extras +clippy: clippy-macros clippy-min clippy-udev-utils clippy-no-ipc clippy-utils cargo clippy ${CLIPPY_OPTS} ## Lint Python parts of the source code diff --git a/src/bin/tools/cmds.rs b/src/bin/tools/cmds.rs index 9fe84b43e4..20ce67a685 100644 --- a/src/bin/tools/cmds.rs +++ b/src/bin/tools/cmds.rs @@ -4,9 +4,9 @@ use std::path::PathBuf; -use clap::{Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, ArgGroup, Command}; -use crate::tools::{check_metadata, dump_metadata}; +use crate::tools::{check_metadata, dump_metadata, stratis_legacy_pool}; use stratisd::stratis::VERSION; @@ -147,10 +147,70 @@ impl<'a> ToolCommand<'a> for StratisPrintMetadata { } } +struct StratisLegacyPool; + +impl StratisLegacyPool { + fn cmd() -> Command { + Command::new("stratis-legacy-pool") + .arg(Arg::new("pool_name").num_args(1).required(true)) + .arg( + Arg::new("blockdevs") + .action(ArgAction::Append) + .value_parser(clap::value_parser!(PathBuf)) + .required(true), + ) + .arg( + Arg::new("key_desc") + .long("key-desc") + .num_args(1) + .required(false), + ) + .arg( + Arg::new("clevis") + .long("clevis") + .num_args(1) + .required(false) + .value_parser(["nbde", "tang", "tpm2"]) + .requires_if("nbde", "tang_args") + .requires_if("tang", "tang_args"), + ) + .arg( + Arg::new("tang_url") + .long("tang-url") + .num_args(1) + .required_if_eq("clevis", "nbde") + .required_if_eq("clevis", "tang"), + ) + .arg(Arg::new("thumbprint").long("thumbprint").num_args(1)) + .arg(Arg::new("trust_url").long("trust-url").num_args(0)) + .group( + ArgGroup::new("tang_args") + .arg("thumbprint") + .arg("trust_url"), + ) + } +} + +impl<'a> ToolCommand<'a> for StratisLegacyPool { + fn name(&self) -> &'a str { + "stratis-legacy-pool" + } + + fn run(&self, command_line_args: Vec) -> Result<(), String> { + let matches = StratisLegacyPool::cmd().get_matches_from(command_line_args); + stratis_legacy_pool::run(&matches).map_err(|err| format!("{err}")) + } + + fn show_in_after_help(&self) -> bool { + false + } +} + pub fn cmds<'a>() -> Vec>> { vec![ Box::new(StratisCheckMetadata), Box::new(StratisDumpMetadata), + Box::new(StratisLegacyPool), Box::new(StratisPrintMetadata), ] } diff --git a/src/bin/tools/mod.rs b/src/bin/tools/mod.rs index a7d3a25f57..3b4ad61e6e 100644 --- a/src/bin/tools/mod.rs +++ b/src/bin/tools/mod.rs @@ -5,5 +5,6 @@ mod check_metadata; mod cmds; mod dump_metadata; +mod stratis_legacy_pool; pub use cmds::cmds; diff --git a/src/bin/stratis-legacy-pool.rs b/src/bin/tools/stratis_legacy_pool.rs similarity index 62% rename from src/bin/stratis-legacy-pool.rs rename to src/bin/tools/stratis_legacy_pool.rs index fb5dbaeea0..b41d501fc9 100644 --- a/src/bin/stratis-legacy-pool.rs +++ b/src/bin/tools/stratis_legacy_pool.rs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::{env, path::PathBuf}; +use std::path::PathBuf; -use clap::{Arg, ArgAction, ArgGroup, Command}; +use clap::ArgMatches; use serde_json::{json, Map, Value}; use stratisd::{ @@ -15,45 +15,6 @@ use stratisd::{ stratis::StratisResult, }; -fn stratis_legacy_pool_args() -> Command { - Command::new("stratis-legacy-pool") - .arg(Arg::new("pool_name").num_args(1).required(true)) - .arg( - Arg::new("blockdevs") - .action(ArgAction::Append) - .required(true), - ) - .arg( - Arg::new("key_desc") - .long("key-desc") - .num_args(1) - .required(false), - ) - .arg( - Arg::new("clevis") - .long("clevis") - .num_args(1) - .required(false) - .value_parser(["nbde", "tang", "tpm2"]) - .requires_if("nbde", "tang_args") - .requires_if("tang", "tang_args"), - ) - .arg( - Arg::new("tang_url") - .long("tang-url") - .num_args(1) - .required_if_eq("clevis", "nbde") - .required_if_eq("clevis", "tang"), - ) - .arg(Arg::new("thumbprint").long("thumbprint").num_args(1)) - .arg(Arg::new("trust_url").long("trust-url").num_args(0)) - .group( - ArgGroup::new("tang_args") - .arg("thumbprint") - .arg("trust_url"), - ) -} - type ParseReturn = StratisResult<( String, Vec, @@ -61,11 +22,7 @@ type ParseReturn = StratisResult<( Option<(String, Value)>, )>; -fn parse_args() -> ParseReturn { - let args = env::args().collect::>(); - let parser = stratis_legacy_pool_args(); - let matches = parser.get_matches_from(args); - +fn parse_args(matches: &ArgMatches) -> ParseReturn { let pool_name = matches .get_one::("pool_name") .expect("required") @@ -107,10 +64,10 @@ fn parse_args() -> ParseReturn { Ok((pool_name, blockdevs, key_desc, clevis_info)) } -fn main() -> StratisResult<()> { +pub fn run(matches: &ArgMatches) -> StratisResult<()> { env_logger::init(); - let (name, devices, key_desc, clevis_info) = parse_args()?; + let (name, devices, key_desc, clevis_info) = parse_args(matches)?; let unowned = ProcessedPathInfos::try_from( devices .iter()