Implement sq config inspect policy.

- Fixes #276.
This commit is contained in:
Justus Winter 2024-12-03 16:33:48 +01:00
parent 68522f7bf1
commit 3bde91aeb4
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
5 changed files with 104 additions and 0 deletions

View File

@ -13,6 +13,7 @@ use clap::{
use sequoia_directories::Home;
pub mod get;
pub mod inspect;
pub mod set;
pub mod template;
@ -138,5 +139,6 @@ pub struct Command {
#[non_exhaustive]
pub enum Subcommands {
Get(get::Command),
Inspect(inspect::Command),
Template(template::Command),
}

34
src/cli/config/inspect.rs Normal file
View File

@ -0,0 +1,34 @@
//! Command-line parser for `sq config inspect`.
use clap::{
Parser,
Subcommand,
};
pub mod policy;
#[derive(Debug, Parser)]
#[clap(
name = "inspect",
about = "Inspect effective configuration details",
long_about = "\
Inspect effective configuration details
This subcommand can be used to inspect various aspects of the \
effective configuration, such as various relevant paths, \
the cryptographic policy, the network configuration, etc.
",
subcommand_required = true,
arg_required_else_help = true,
disable_help_subcommand = true,
)]
pub struct Command {
#[clap(subcommand)]
pub subcommand: Subcommands,
}
#[derive(Debug, Subcommand)]
#[non_exhaustive]
pub enum Subcommands {
Policy(policy::Command),
}

View File

@ -0,0 +1,35 @@
//! Command-line parser for `sq config inspect policy`.
use clap::Args;
use crate::cli::examples::*;
#[derive(Debug, Args)]
#[clap(
name = "policy",
about = "Inspect the cryptographic policy",
long_about = "\
Inspect the cryptographic policy
Prints the cryptographic policy in the format that Sequoia uses to \
configure acceptance, rejection, and cutoff times for cryptographic \
algorithms.
See https://docs.rs/sequoia-policy-config/
",
after_help = EXAMPLES,
)]
pub struct Command {
}
const EXAMPLES: Actions = Actions {
actions: &[
Action::example()
.comment("Inspect the cryptographic policy.")
.command(&[
"sq", "config", "inspect", "policy",
])
.build(),
],
};
test_examples!(sq_config_inspect_policy, EXAMPLES);

View File

@ -23,12 +23,15 @@ use crate::{
config::ConfigFile,
};
mod inspect;
pub fn dispatch(sq: Sq, cmd: config::Command)
-> Result<()>
{
match cmd.subcommand {
config::Subcommands::Get(c) => get(sq, c),
config::Subcommands::Template(c) => template(sq, c),
config::Subcommands::Inspect(c) => inspect::dispatch(sq, c),
}
}

View File

@ -0,0 +1,30 @@
//! Dispatches and implements `sq config inspect`.
use anyhow::Result;
use sequoia_policy_config::{
ConfiguredStandardPolicy,
DumpDefault,
};
use crate::{
Sq,
cli::config::inspect,
};
pub fn dispatch(sq: Sq, cmd: inspect::Command)
-> Result<()>
{
match cmd.subcommand {
inspect::Subcommands::Policy(c) => policy(sq, c),
}
}
/// Implements `sq config inspect policy`.
fn policy(sq: Sq, _: inspect::policy::Command) -> Result<()> {
let p = ConfiguredStandardPolicy::from_policy(sq.policy.clone());
p.dump(&mut std::io::stdout(), DumpDefault::Explicit)?;
Ok(())
}