Skip to content

Commit 900d862

Browse files
committed
feat(cli): read configure-wifi credentials from environment variables
configure-wifi only prompted interactively, which blocks scripted or headless provisioning. When COUCHLINK_WIFI_SSID and COUCHLINK_WIFI_PASSWORD are both set, use them instead of prompting, with the same length checks. Env vars keep the password out of argv and shell history.
1 parent e8e413d commit 900d862

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

bridge/src/cmd_configure_wifi.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,23 @@ impl Drop for Credentials {
275275
}
276276

277277
fn prompt_credentials() -> Result<Credentials> {
278+
// Non-interactive override for scripted / headless provisioning: when
279+
// both COUCHLINK_WIFI_SSID and COUCHLINK_WIFI_PASSWORD are set, use them
280+
// instead of prompting. Same length limits as the interactive path.
281+
// Env vars keep the password out of argv and shell history.
282+
if let Ok(ssid) = std::env::var("COUCHLINK_WIFI_SSID") {
283+
if !ssid.is_empty() {
284+
let password = std::env::var("COUCHLINK_WIFI_PASSWORD").unwrap_or_default();
285+
if ssid.len() > 32 {
286+
bail!("COUCHLINK_WIFI_SSID can't be longer than 32 bytes");
287+
}
288+
if password.len() > 63 {
289+
bail!("COUCHLINK_WIFI_PASSWORD can't be longer than 63 bytes (WPA2 limit)");
290+
}
291+
println!("Using Wi-Fi credentials from COUCHLINK_WIFI_SSID/PASSWORD.");
292+
return Ok(Credentials { ssid, password });
293+
}
294+
}
278295
let theme = ColorfulTheme::default();
279296
let ssid: String = Input::with_theme(&theme)
280297
.with_prompt("Wi-Fi SSID (2.4 GHz network)")

0 commit comments

Comments
 (0)