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

Give config info at session start #2447

Merged
merged 5 commits into from
May 17, 2024
Merged
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
1 change: 1 addition & 0 deletions changelog.d/2367.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added config info printout at session start.
2 changes: 1 addition & 1 deletion mirrord/cli/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mirrord_progress::{JsonProgress, Progress, ProgressTracker};

use crate::{config::ExtensionExecArgs, error::CliError, execution::MirrordExecution, Result};

/// Actualy facilitate execution after all preperatations were complete
/// Actually facilitate execution after all preparations were complete
async fn mirrord_exec<P>(
#[cfg(target_os = "macos")] executable: Option<&str>,
env: HashMap<String, String>,
Expand Down
109 changes: 109 additions & 0 deletions mirrord/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use miette::JSONReportHandler;
use mirrord_analytics::{AnalyticsError, AnalyticsReporter, CollectAnalytics, Reporter};
use mirrord_config::{
config::{ConfigContext, MirrordConfig},
feature::{fs::FsModeConfig, network::incoming::IncomingMode},
target::TargetDisplay,
LayerConfig, LayerFileConfig,
};
Expand Down Expand Up @@ -102,6 +103,17 @@ where
// Put original executable in argv[0] even if actually running patched version.
binary_args.insert(0, args.binary.clone());

// Print config details for the user
let mut sub_progress_config = progress.subtask("config summary");
print_config(
&sub_progress_config,
Some(&binary),
Some(&args.binary_args),
&config,
false,
);
sub_progress_config.success(None);

sub_progress.success(Some("ready to launch process"));
// The execve hook is not yet active and does not hijack this call.
let err = execvp(binary.clone(), binary_args.clone());
Expand All @@ -119,6 +131,103 @@ where
Err(CliError::BinaryExecuteFailed(binary, binary_args))
}

fn print_config<P>(
progress_subtask: &P,
binary: Option<&String>,
binary_args: Option<&Vec<String>>,
config: &LayerConfig,
single_msg: bool,
) where
P: Progress + Send + Sync,
{
let mut messages = vec![];
if let Some(b) = binary
&& let Some(a) = binary_args
{
messages.push(format!("Running binary \"{}\" with arguments: {:?}.", b, a));
}

let target_info = if let Some(target) = &config.target.path {
&format!("mirrord will target: {}", target)[..]
} else {
"mirrord will run without a target"
};
let config_info = if let Ok(path) = std::env::var("MIRRORD_CONFIG_FILE") {
&format!("a configuration file was loaded from: {} ", path)[..]
} else {
"no configuration file was loaded"
};
messages.push(format!("{}, {}", target_info, config_info));

let operator_info = match config.operator {
Some(true) => "be used",
Some(false) => "not be used",
None => "be used if possible",
};
messages.push(format!("operator: the operator will {}", operator_info));

let exclude = config.feature.env.exclude.as_ref();
let include = config.feature.env.include.as_ref();
let env_info = if let Some(excluded) = exclude {
if excluded.clone().to_vec().contains(&String::from("*")) {
"no"
} else {
"not all"
}
} else if include.is_some() {
"not all"
} else {
"all"
};
messages.push(format!(
"env: {} environment variables will be fetched",
env_info
));

let fs_info = match config.feature.fs.mode {
FsModeConfig::Read => "read only from the remote",
FsModeConfig::Write => "read and write from the remote",
_ => "read and write locally",
};
messages.push(format!("fs: file operations will default to {}", fs_info));

let incoming_info = match config.feature.network.incoming.mode {
IncomingMode::Mirror => "mirrored",
IncomingMode::Steal => "stolen",
IncomingMode::Off => "ignored",
};
messages.push(format!(
"incoming: incoming traffic will be {}",
incoming_info
));

let outgoing_info = match (
config.feature.network.outgoing.tcp,
config.feature.network.outgoing.udp,
) {
(true, true) => "enabled on TCP and UDP",
(true, false) => "enabled on TCP",
(false, true) => "enabled on UDP",
(false, false) => "disabled on TCP and UDP",
};
messages.push(format!("outgoing: forwarding is {}", outgoing_info));

let dns_info = match config.feature.network.dns {
true => "remotely",
false => "locally",
};
messages.push(format!("dns: DNS will be resolved {}", dns_info));

if single_msg {
let long_message = messages.join(". \n");
progress_subtask.info(&long_message);
} else {
for m in messages {
progress_subtask.info(&m[..]);
}
}
}

async fn exec(args: &ExecArgs, watch: drain::Watch) -> Result<()> {
let progress = ProgressTracker::from_env("mirrord exec");
if !args.disable_version_check {
Expand Down
Loading