()
| 16 | const SECURE_VALUE_REDACTED: &str = "<secureValue>"; |
| 17 | |
| 18 | fn main() { |
| 19 | let args = Args::parse(); |
| 20 | if let Some(input) = args.input { |
| 21 | let mut echo = match serde_json::from_str::<Echo>(&input) { |
| 22 | Ok(echo) => echo, |
| 23 | Err(err) => { |
| 24 | eprintln!("{}: {err}", t!("main.invalidJson")); |
| 25 | std::process::exit(1); |
| 26 | } |
| 27 | }; |
| 28 | if echo.show_secrets != Some(true) { |
| 29 | match echo.output { |
| 30 | Output::SecureString(_) | Output::SecureObject(_) => { |
| 31 | echo.output = Output::String(SECURE_VALUE_REDACTED.to_string()); |
| 32 | }, |
| 33 | Output::Array(ref mut arr) => { |
| 34 | for item in arr.iter_mut() { |
| 35 | if is_secure_value(item) { |
| 36 | *item = Value::String(SECURE_VALUE_REDACTED.to_string()); |
| 37 | } else { |
| 38 | *item = redact(item); |
| 39 | } |
| 40 | } |
| 41 | }, |
| 42 | Output::Object(ref mut obj) => { |
| 43 | obj.clone_from(redact(&Value::Object(obj.clone())) |
| 44 | .as_object() |
| 45 | .expect("Expected redact() to return a Value::Object")); }, |
| 46 | _ => {} |
| 47 | } |
| 48 | } |
| 49 | let json = serde_json::to_string(&echo).unwrap(); |
| 50 | println!("{json}"); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | let schema = schema_for!(Echo); |
| 55 | let json = serde_json::to_string_pretty(&schema).unwrap(); |
| 56 | println!("{json}"); |
| 57 | } |
| 58 | |
| 59 | fn is_secure_value(value: &Value) -> bool { |
| 60 | if let Some(obj) = value.as_object() |
nothing calls this directly
no test coverage detected