Restructure the example into two clear phases: Phase 1 (--boot): creates KVM network + VM, waits for web UI, prints instructions for enabling SSH via the OPNsense GUI. Phase 2 (default run): checks SSH is reachable, creates API key, installs HAProxy, runs LoadBalancerScore, verifies via API. The config.xml injection sets vtnet0=LAN (192.168.1.1) and vtnet1=WAN (DHCP). SSH must be enabled manually in the web UI because OPNsense has no REST API for SSH management and the config.xml injection doesn't reliably enable sshd. Future: use a pre-customized OPNsense image on S3 for CI. Also add show_ssh_config example to opnsense-api crate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
//! Example: show SSH configuration from OPNsense.
|
|
//!
|
|
//! ```text
|
|
//! cargo run --example show_ssh_config
|
|
//! ```
|
|
|
|
mod common;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let client = common::client_from_env();
|
|
|
|
let resp: serde_json::Value = client
|
|
.get_typed("core", "system", "get")
|
|
.await
|
|
.expect("API call failed");
|
|
|
|
// Find and display SSH-related configuration
|
|
fn find_keys(obj: &serde_json::Value, path: &str, needle: &str) {
|
|
match obj {
|
|
serde_json::Value::Object(map) => {
|
|
for (k, v) in map {
|
|
let full = if path.is_empty() {
|
|
k.clone()
|
|
} else {
|
|
format!("{path}.{k}")
|
|
};
|
|
if k.to_lowercase().contains(needle) {
|
|
println!("{full}: {}", serde_json::to_string_pretty(v).unwrap());
|
|
}
|
|
find_keys(v, &full, needle);
|
|
}
|
|
}
|
|
serde_json::Value::Array(arr) => {
|
|
for (i, v) in arr.iter().enumerate() {
|
|
find_keys(v, &format!("{path}[{i}]"), needle);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
println!("SSH-related configuration:");
|
|
println!("==========================");
|
|
find_keys(&resp, "", "ssh");
|
|
}
|