mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
OAuth2 secret JSON (#1758)
* clippyisms * adding JSON support for oauth2 show-basic-token, slight refactor on OutputMode
This commit is contained in:
parent
a9547d7150
commit
41d8fece68
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"];
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<OutputMode, std::string::String> {
|
||||
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<PathBuf>,
|
||||
/// 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)]
|
||||
|
|
Loading…
Reference in a new issue