Skip to content
59 changes: 59 additions & 0 deletions src/app/config_dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2025 Lablup Inc. and Jeongkyu Shin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

//! Side-effect-free resolved SSH configuration output.

use std::io::Write as _;

use anyhow::{Context, Result};
use bssh::cli::SshDumpInvocation;
use bssh::ssh::ssh_config::{SshConfig, render_resolved_config};

/// Resolve and print ssh_config without initializing any connection services.
pub async fn handle_config_dump(invocation: &SshDumpInvocation) -> Result<()> {
let mut config = match invocation.config_file.as_deref() {
Some(path) if path.as_os_str() == "none" => SshConfig::new(),
Some(path) => SshConfig::load_explicit_for_config_dump_with_options(
path,
&invocation.destination,
&invocation.overrides,
)
.await
.with_context(|| format!("Failed to load SSH config from {path:?}"))?,
None => {
SshConfig::load_default_for_config_dump_with_options(
&invocation.destination,
&invocation.overrides,
)
.await?
}
};
if invocation
.config_file
.as_deref()
.is_some_and(|path| path.as_os_str() == "none")
{
config
.apply_cli_options(&invocation.overrides)
.context("Failed to apply command-line SSH options")?;
}
if let Some(keyword) = config
.hosts
.iter()
.flat_map(|host| host.unknown_options.keys())
.next()
{
anyhow::bail!("Unknown SSH config option '{keyword}'");
}
let mut resolved = config.find_host_config(&invocation.destination);
if invocation.stdio_forward {
resolved.clear_all_forwardings.get_or_insert(true);
resolved.exit_on_forward_failure.get_or_insert(true);
}
let rendered = render_resolved_config(&invocation.destination, &resolved)?;
std::io::stdout()
.write_all(rendered.as_bytes())
.context("Failed to write resolved SSH configuration")
}
1 change: 1 addition & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! initialization, and utility functions for the bssh CLI.

pub mod cache;
pub mod config_dump;
pub mod dispatcher;
pub mod initialization;
pub mod nodes;
Expand Down
16 changes: 16 additions & 0 deletions src/app/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@

use bssh::diagnosticln as eprintln;

pub fn is_supported_query(query: &str) -> bool {
matches!(
query,
"cipher"
| "cipher-auth"
| "mac"
| "kex"
| "key"
| "key-plain"
| "key-cert"
| "key-sig"
| "protocol-version"
| "help"
)
}

/// Handle SSH query options (-Q)
pub fn handle_query(query: &str) {
match query {
Expand Down
2 changes: 2 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@

mod bssh;
pub mod pdsh;
mod ssh_args;

#[cfg(test)]
mod mode_detection_tests;

// Re-export main CLI types from bssh module
pub use bssh::{Cli, Commands};
pub use ssh_args::SshDumpInvocation;

// Re-export pdsh compatibility utilities
pub use pdsh::{
Expand Down
Loading
Loading