From 44a07c0de20c22d187682e9189b2d7dbd564f44d Mon Sep 17 00:00:00 2001 From: Zeke Mostov Date: Mon, 9 Oct 2023 11:00:12 -0400 Subject: [PATCH] Do not print json with new line characters --- src/enclave_proc_comm.rs | 15 +++++++++++++-- src/lib.rs | 1 + src/main.rs | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/enclave_proc_comm.rs b/src/enclave_proc_comm.rs index 7fd12e7cd..e8c7e797e 100644 --- a/src/enclave_proc_comm.rs +++ b/src/enclave_proc_comm.rs @@ -303,6 +303,7 @@ pub fn enclave_process_handle_all_replies( prev_failed_conns: usize, print_as_vec: bool, allowed_return_codes: Vec, + pretty_print: bool, ) -> NitroCliResult> where T: Clone + DeserializeOwned + Serialize, @@ -318,18 +319,28 @@ where // Output the received objects either individually or as an array. if print_as_vec { let obj_vec: Vec = objects.iter().map(|v| v.0.clone()).collect(); + let json_result = if pretty_print { + serde_json::to_string_pretty(&obj_vec) + } else { + serde_json::to_string(&obj_vec) + }; println!( "{}", - serde_json::to_string_pretty(&obj_vec).map_err(|e| new_nitro_cli_failure!( + json_result.map_err(|e| new_nitro_cli_failure!( &format!("Failed to print JSON vector: {:?}", e), NitroCliErrorEnum::SerdeError ))? ); } else { for object in objects.iter().map(|v| v.0.clone()) { + let json_result = if pretty_print { + serde_json::to_string_pretty(&object) + } else { + serde_json::to_string(&object) + }; println!( "{}", - serde_json::to_string_pretty(&object).map_err(|e| new_nitro_cli_failure!( + json_result.map_err(|e| new_nitro_cli_failure!( &format!("Failed to print JSON object: {:?}", e), NitroCliErrorEnum::SerdeError ))? diff --git a/src/lib.rs b/src/lib.rs index 169e64b04..29e9dcbdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -440,6 +440,7 @@ pub fn terminate_all_enclaves() -> NitroCliResult<()> { failed_connections.len() + err_socket_files, false, vec![0, libc::EACCES], + true, ) .map_err(|e| e.add_subaction("Failed to handle all enclave processes replies".to_string())) .map(|_| ()) diff --git a/src/main.rs b/src/main.rs index 3c46d6b42..4ab65b28e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,6 +110,7 @@ fn main() { 0, false, vec![0], + true, ) .map_err(|e| { e.add_subaction("Failed to handle all enclave process replies".to_string()) @@ -177,6 +178,7 @@ fn main() { 0, false, vec![0], + true, ) .map_err(|e| { e.add_subaction("Failed to handle all enclave process replies".to_string()) @@ -206,6 +208,7 @@ fn main() { comm_errors, true, vec![0], + true, ) .map_err(|e| { e.add_subaction("Failed to handle all enclave process replies".to_string())