Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opt out of json pretty print in enclave_process_handle_all_replies #544

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/enclave_proc_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ pub fn enclave_process_handle_all_replies<T>(
prev_failed_conns: usize,
print_as_vec: bool,
allowed_return_codes: Vec<i32>,
pretty_print: bool,
) -> NitroCliResult<Vec<T>>
where
T: Clone + DeserializeOwned + Serialize,
Expand All @@ -318,18 +319,28 @@ where
// Output the received objects either individually or as an array.
if print_as_vec {
let obj_vec: Vec<T> = 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
))?
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| ())
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down