Skip to content

Commit

Permalink
Make stratis-legacy-pool a command of stratisd-tools
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jan 31, 2025
1 parent 909775e commit 82a7fca
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 77 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -72,9 +69,6 @@ jobs:
- task: make -f Makefile build
toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: make -f Makefile build-test-extras
toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: make -f Makefile build-min
toolchain: 1.84.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
64 changes: 62 additions & 2 deletions src/bin/tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, legacy_pool};

use stratisd::stratis::VERSION;

Expand Down Expand Up @@ -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<String>) -> Result<(), String> {
let matches = StratisLegacyPool::cmd().get_matches_from(command_line_args);
legacy_pool::run(&matches).map_err(|err| format!("{err}"))
}

fn show_in_after_help(&self) -> bool {
false
}
}

pub fn cmds<'a>() -> Vec<Box<dyn ToolCommand<'a>>> {
vec![
Box::new(StratisCheckMetadata),
Box::new(StratisDumpMetadata),
Box::new(StratisLegacyPool),
Box::new(StratisPrintMetadata),
]
}
Expand Down
59 changes: 7 additions & 52 deletions src/bin/stratis-legacy-pool.rs → src/bin/tools/legacy_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -15,65 +15,22 @@ 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<PathBuf>,
Option<KeyDescription>,
Option<(String, Value)>,
)>;

fn parse_args() -> ParseReturn {
let args = env::args().collect::<Vec<_>>();
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::<String>("pool_name")
.expect("required")
.clone();
let blockdevs = matches
.get_many::<String>("blockdevs")
.get_many::<PathBuf>("blockdevs")
.expect("required")
.map(PathBuf::from)
.cloned()
.collect::<Vec<_>>();
let key_desc = match matches.get_one::<String>("key_desc") {
Some(kd) => Some(KeyDescription::try_from(kd)?),
Expand Down Expand Up @@ -107,10 +64,8 @@ fn parse_args() -> ParseReturn {
Ok((pool_name, blockdevs, key_desc, clevis_info))
}

fn main() -> StratisResult<()> {
env_logger::init();

let (name, devices, key_desc, clevis_info) = parse_args()?;
pub fn run(matches: &ArgMatches) -> StratisResult<()> {
let (name, devices, key_desc, clevis_info) = parse_args(matches)?;
let unowned = ProcessedPathInfos::try_from(
devices
.iter()
Expand Down
1 change: 1 addition & 0 deletions src/bin/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
mod check_metadata;
mod cmds;
mod dump_metadata;
mod legacy_pool;

pub use cmds::cmds;

0 comments on commit 82a7fca

Please sign in to comment.