diff --git a/server/lib/benches/scaling_10k.rs b/server/lib/benches/scaling_10k.rs index 0742960b1..08122db65 100644 --- a/server/lib/benches/scaling_10k.rs +++ b/server/lib/benches/scaling_10k.rs @@ -30,7 +30,7 @@ pub fn scaling_user_create_single(c: &mut Criterion) { .build() .expect("Failed building the Runtime") .block_on(async { - let (idms, _idms_delayed) = + let (idms, _idms_delayed, _idms_audit) = kanidmd_lib::testkit::setup_idm_test().await; let ct = duration_from_epoch_now(); @@ -97,7 +97,7 @@ pub fn scaling_user_create_batched(c: &mut Criterion) { .build() .expect("Failed building the Runtime") .block_on(async { - let (idms, _idms_delayed) = + let (idms, _idms_delayed, _idms_audit) = kanidmd_lib::testkit::setup_idm_test().await; let ct = duration_from_epoch_now(); diff --git a/server/lib/src/constants/acp.rs b/server/lib/src/constants/acp.rs index 8715a3d14..f5dbed998 100644 --- a/server/lib/src/constants/acp.rs +++ b/server/lib/src/constants/acp.rs @@ -1,7 +1,7 @@ #![allow(clippy::expect_used)] +//! Constant Entries for the IDM use crate::constants::uuids::*; -///! Constant Entries for the IDM use crate::constants::values::*; use crate::entry::{Entry, EntryInit, EntryInitNew, EntryNew}; use crate::value::Value; diff --git a/server/web_ui/src/constants.rs b/server/web_ui/src/constants.rs index d4e156fea..6ac849bae 100644 --- a/server/web_ui/src/constants.rs +++ b/server/web_ui/src/constants.rs @@ -1,4 +1,4 @@ -///! Constants +//! Constants // CSS classes that get applied to full-page forms pub const CSS_CLASSES_BODY_FORM: &[&str] = &["flex-column", "d-flex", "h-100"]; diff --git a/server/web_ui/src/macros.rs b/server/web_ui/src/macros.rs index 3f2d962e2..55eb64053 100644 --- a/server/web_ui/src/macros.rs +++ b/server/web_ui/src/macros.rs @@ -1,4 +1,4 @@ -///! Macros for the web UI +//! Macros for the web UI /// Adds a set of CSS classes to the body element when we're presenting a full-page form #[macro_export] diff --git a/tools/cli/src/cli/group.rs b/tools/cli/src/cli/group.rs index 2f7a2c8d3..6870e8417 100644 --- a/tools/cli/src/cli/group.rs +++ b/tools/cli/src/cli/group.rs @@ -1,5 +1,5 @@ use crate::common::OpType; -use crate::{GroupOpt, GroupPosix}; +use crate::{GroupOpt, GroupPosix, OutputMode}; impl GroupOpt { pub fn debug(&self) -> bool { @@ -25,15 +25,15 @@ impl GroupOpt { GroupOpt::List(copt) => { let client = copt.to_client(OpType::Read).await; match client.idm_group_list().await { - Ok(r) => r.iter().for_each(|ent| match copt.output_mode.as_str() { - "json" => { + Ok(r) => r.iter().for_each(|ent| match copt.output_mode { + OutputMode::Json => { println!( "{}", serde_json::to_string(&ent.attrs) .expect("Failed to serialise json") ); } - _ => println!("{}", ent), + OutputMode::Text => println!("{}", ent), }), Err(e) => error!("Error -> {:?}", e), } @@ -42,14 +42,14 @@ impl GroupOpt { let client = gcopt.copt.to_client(OpType::Read).await; // idm_group_get match client.idm_group_get(gcopt.name.as_str()).await { - Ok(Some(e)) => match gcopt.copt.output_mode.as_str() { - "json" => { + Ok(Some(e)) => match gcopt.copt.output_mode { + OutputMode::Json => { println!( "{}", serde_json::to_string(&e.attrs).expect("Failed to serialise json") ); } - _ => println!("{}", e), + OutputMode::Text => println!("{}", e), }, Ok(None) => warn!("No matching group '{}'", gcopt.name.as_str()), Err(e) => error!("Error -> {:?}", e), diff --git a/tools/cli/src/cli/oauth2.rs b/tools/cli/src/cli/oauth2.rs index e0715d44b..86f340dfd 100644 --- a/tools/cli/src/cli/oauth2.rs +++ b/tools/cli/src/cli/oauth2.rs @@ -1,5 +1,5 @@ use crate::common::OpType; -use crate::Oauth2Opt; +use crate::{Oauth2Opt, OutputMode}; impl Oauth2Opt { pub fn debug(&self) -> bool { @@ -134,7 +134,10 @@ impl Oauth2Opt { .await { Ok(Some(secret)) => { - println!("{secret}"); + match nopt.copt.output_mode { + OutputMode::Text => println!("{}", secret), + OutputMode::Json => println!("{{\"secret\": \"{}\"}}", secret), + } eprintln!("Success"); } Ok(None) => { diff --git a/tools/cli/src/cli/serviceaccount.rs b/tools/cli/src/cli/serviceaccount.rs index fe7830b40..7150e1384 100644 --- a/tools/cli/src/cli/serviceaccount.rs +++ b/tools/cli/src/cli/serviceaccount.rs @@ -3,7 +3,7 @@ use kanidm_proto::messages::{AccountChangeMessage, ConsoleOutputMode, MessageSta use time::OffsetDateTime; use crate::{ - AccountSsh, AccountUserAuthToken, AccountValidity, ServiceAccountApiToken, + AccountSsh, AccountUserAuthToken, AccountValidity, OutputMode, ServiceAccountApiToken, ServiceAccountCredential, ServiceAccountOpt, ServiceAccountPosix, }; use time::format_description::well_known::Rfc3339; @@ -139,8 +139,8 @@ impl ServiceAccountOpt { ) .await { - Ok(new_token) => match copt.output_mode.as_str() { - "json" => { + Ok(new_token) => match copt.output_mode { + OutputMode::Json => { let message = AccountChangeMessage { output_mode: ConsoleOutputMode::JSON, action: "api-token generate".to_string(), @@ -154,7 +154,7 @@ impl ServiceAccountOpt { }; println!("{}", message); } - _ => { + OutputMode::Text => { println!("Success: This token will only be displayed ONCE"); println!("{}", new_token) } diff --git a/tools/cli/src/opt/kanidm.rs b/tools/cli/src/opt/kanidm.rs index 07c63745d..946bcb6dc 100644 --- a/tools/cli/src/opt/kanidm.rs +++ b/tools/cli/src/opt/kanidm.rs @@ -14,6 +14,24 @@ pub struct DebugOpt { pub debug: bool, } +#[derive(Debug, Clone)] +/// The CLI output mode, either text or json, falls back to text if you ask for something other than text/json +pub enum OutputMode { + Text, + Json, +} + +impl std::str::FromStr for OutputMode { + type Err = String; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "text" => Ok(OutputMode::Text), + "json" => Ok(OutputMode::Json), + _ => Ok(OutputMode::Text), + } + } +} + #[derive(Debug, Args, Clone)] pub struct CommonOpt { /// Enable debbuging of the kanidm tool @@ -30,7 +48,7 @@ pub struct CommonOpt { pub ca_path: Option, /// Log format (still in very early development) #[clap(short, long = "output", env = "KANIDM_OUTPUT", default_value = "text")] - output_mode: String, + output_mode: OutputMode, } #[derive(Debug, Args)]