Skip to content

Commit

Permalink
debug mode logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneary committed Dec 9, 2024
1 parent 9069e95 commit 9198ea4
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions control-plane/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::process::{Output, Stdio};
use log::info;
use serde_json::Value;
use thiserror::Error;
use tokio::process::Command;
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::Command,
};

use crate::configuration::get_enclave_run_config;

Expand Down Expand Up @@ -54,7 +57,7 @@ impl Orchestration {
info!("No enclaves currently running on this host.");
}

println!("Starting new enclave...");
info!("Starting new enclave...");
let mut run_command = vec![
"nitro-cli",
"run-enclave",
Expand All @@ -69,10 +72,10 @@ impl Orchestration {
];

if run_config.debug_mode == "true" {
println!("Debug mode enabled...");
info!("Debug mode enabled...");
run_command.push("--debug-mode");
} else {
println!("Debug mode disabled...");
info!("Debug mode disabled...");
}

Self::run_command_capture_stdout(&run_command).await?;
Expand All @@ -81,16 +84,27 @@ impl Orchestration {
std::thread::sleep(std::time::Duration::from_secs(10));

if run_config.debug_mode == "true" {
println!("Attaching headless console for running enclaves...");
info!("Attaching headless console for running enclaves...");
let running_enclaves =
Self::run_command_capture_stdout(&["nitro-cli", "describe-enclaves"]).await?;
let enclaves: Value = serde_json::from_str(&running_enclaves)?;
let v = vec![];
let enclaves_array = enclaves.as_array().unwrap_or(&v);
static EMPTY_VEC: Vec<Value> = Vec::new();
let enclaves_array = enclaves.as_array().unwrap_or(&EMPTY_VEC).clone();
for enclave in enclaves_array {
let id = enclave["EnclaveID"].as_str().unwrap();
Self::run_command_capture_stdout(&["nitro-cli", "console", "--enclave-id", id])
.await?;
let id = enclave["EnclaveID"].as_str().unwrap().to_string();

let mut child = Command::new("nitro-cli")
.args(["console", "--enclave-id", &id])
.stdout(Stdio::piped())
.spawn()?;

let stdout = child.stdout.take().unwrap();
tokio::spawn(async move {
let mut lines = BufReader::new(stdout).lines();
while let Ok(Some(line)) = lines.next_line().await {
info!("[ENCLAVE {}]: {}", id, line);
}
});
}
}
Ok(())
Expand Down

0 comments on commit 9198ea4

Please sign in to comment.