Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86338062a5 | ||
|
|
c4c85d5b3d |
@@ -30,7 +30,8 @@ ui=false; backend=false
|
||||
while IFS= read -r f; do
|
||||
[ -z "$f" ] && continue
|
||||
case "$f" in
|
||||
crates/alkane-gui/src/ui.rs|crates/alkane-gui/src/fixtures.rs|thirdparty/wx-rs/*)
|
||||
crates/alkane-gui/src/ui.rs|crates/alkane-gui/src/fixtures.rs|thirdparty/wx-rs/*|\
|
||||
crates/alkane-gui/src/bin/*)
|
||||
ui=true ;;
|
||||
crates/alkane-core/*|crates/alkane-discovery/*|crates/alkane-access/*|\
|
||||
crates/alkane-flash/*|crates/alkane-artifacts/*|crates/alkane-cli/*|\
|
||||
|
||||
@@ -348,6 +348,94 @@ async fn lifecycle(ip_s: &str, verb: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read (no tz arg) or set the miner's timezone (round 16 / G10). Capability-gated.
|
||||
async fn timezone(ip_s: &str, tz: Option<&str>) {
|
||||
use asic_rs::core::config::timezone::{Tz, TimezoneConfig};
|
||||
let Ok(ip) = ip_s.parse::<std::net::IpAddr>() else {
|
||||
eprintln!("bad ip {ip_s}");
|
||||
return;
|
||||
};
|
||||
match factory().scan_miner(ip).await {
|
||||
Ok(Some(m)) => {
|
||||
if !m.supports_timezone_config() {
|
||||
eprintln!("{ip}: timezone config not supported");
|
||||
return;
|
||||
}
|
||||
if let Some(tz_s) = tz {
|
||||
let Ok(zone) = tz_s.parse::<Tz>() else {
|
||||
eprintln!("bad IANA timezone '{tz_s}' (e.g. America/Edmonton)");
|
||||
return;
|
||||
};
|
||||
let cfg = TimezoneConfig {
|
||||
timezone: Some(zone),
|
||||
available: Vec::new(),
|
||||
};
|
||||
match m.set_timezone_config(cfg).await {
|
||||
Ok(v) => println!("{ip} set timezone {zone} -> Ok({v})"),
|
||||
Err(e) => println!("{ip} set timezone -> Err: {e:#}"),
|
||||
}
|
||||
}
|
||||
match m.get_timezone_config().await {
|
||||
Ok(c) => println!(
|
||||
"{ip} timezone now: {:?} ({} available)",
|
||||
c.timezone.map(|t| t.to_string()),
|
||||
c.available.len()
|
||||
),
|
||||
Err(e) => println!("{ip} read timezone -> Err: {e:#}"),
|
||||
}
|
||||
}
|
||||
Ok(None) => eprintln!("no miner at {ip}"),
|
||||
Err(e) => eprintln!("scan_miner {ip}: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Change the miner's web/API password (round 16 / G11). Capability-gated.
|
||||
/// DANGEROUS: a failed change can lock the toolkit out -- use a dedicated unit.
|
||||
async fn passwd(ip_s: &str, newpass: &str) {
|
||||
let Ok(ip) = ip_s.parse::<std::net::IpAddr>() else {
|
||||
eprintln!("bad ip {ip_s}");
|
||||
return;
|
||||
};
|
||||
match factory().scan_miner(ip).await {
|
||||
Ok(Some(mut m)) => {
|
||||
if !m.supports_change_password() {
|
||||
eprintln!("{ip}: change password not supported");
|
||||
return;
|
||||
}
|
||||
match m.change_password(newpass).await {
|
||||
Ok(v) => println!("{ip} change_password -> Ok({v})"),
|
||||
Err(e) => println!("{ip} change_password -> Err: {e:#}"),
|
||||
}
|
||||
}
|
||||
Ok(None) => eprintln!("no miner at {ip}"),
|
||||
Err(e) => eprintln!("scan_miner {ip}: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Factory-reset the miner (round 16 / G12). Capability-gated. DESTRUCTIVE:
|
||||
/// wipes config and may reset the network (unit can drop off its IP) -- only run
|
||||
/// on a sacrificial/console-attached unit.
|
||||
async fn factoryreset(ip_s: &str) {
|
||||
let Ok(ip) = ip_s.parse::<std::net::IpAddr>() else {
|
||||
eprintln!("bad ip {ip_s}");
|
||||
return;
|
||||
};
|
||||
match factory().scan_miner(ip).await {
|
||||
Ok(Some(m)) => {
|
||||
if !m.supports_factory_reset() {
|
||||
eprintln!("{ip}: factory reset not supported");
|
||||
return;
|
||||
}
|
||||
match m.factory_reset().await {
|
||||
Ok(v) => println!("{ip} factory_reset -> Ok({v})"),
|
||||
Err(e) => println!("{ip} factory_reset -> Err: {e:#}"),
|
||||
}
|
||||
}
|
||||
Ok(None) => eprintln!("no miner at {ip}"),
|
||||
Err(e) => eprintln!("scan_miner {ip}: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let rt = match tokio::runtime::Builder::new_current_thread().enable_all().build() {
|
||||
@@ -379,6 +467,10 @@ fn main() {
|
||||
rt.block_on(setpools(&args[2], &args[3], &args[4], &args[5]))
|
||||
}
|
||||
Some("msgs") if args.len() == 3 => rt.block_on(msgs(&args[2])),
|
||||
Some("timezone") if args.len() == 3 => rt.block_on(timezone(&args[2], None)),
|
||||
Some("timezone") if args.len() == 4 => rt.block_on(timezone(&args[2], Some(&args[3]))),
|
||||
Some("passwd") if args.len() == 4 => rt.block_on(passwd(&args[2], &args[3])),
|
||||
Some("factoryreset") if args.len() == 3 => rt.block_on(factoryreset(&args[2])),
|
||||
_ => {
|
||||
eprintln!(
|
||||
"miner_probe -- asic-rs config + scan CLI for the alkane-toolkit fleet\n\
|
||||
@@ -396,6 +488,9 @@ fn main() {
|
||||
\x20 restart <ip> restart/reboot\n\
|
||||
\x20 setpl <ip> <watts> set power limit\n\
|
||||
\x20 setpools <ip> <url> <user> <pass> set the default pool group\n\
|
||||
\x20 timezone <ip> [<IANA>] read (no arg) or set the timezone\n\
|
||||
\x20 passwd <ip> <newpass> change the web/API password (DANGEROUS)\n\
|
||||
\x20 factoryreset <ip> factory reset (DESTRUCTIVE; sacrificial units only)\n\
|
||||
\n\
|
||||
Each write verb is capability-gated (skips miners that do not support it).\n\
|
||||
Credentials: ALKANE_PROBE_USER/PASS or ~/.config/alkane-toolkit/scan-credentials.txt."
|
||||
|
||||
@@ -159,6 +159,9 @@ impl Board {
|
||||
tuning: self.mining,
|
||||
firmware_flash,
|
||||
pools: true,
|
||||
timezone: self.mining,
|
||||
change_password: true,
|
||||
factory_reset: true,
|
||||
},
|
||||
// Demo values for the round-8/9 columns (synthetic, so the columns
|
||||
// show variety offline). control_board is derived above via naming.
|
||||
|
||||
@@ -219,6 +219,11 @@ pub struct MinerCaps {
|
||||
/// Whether this miner's driver supports writing pool configuration (probed
|
||||
/// via `supports_pools_config()` at scan time; round 14 #7).
|
||||
pub pools: bool,
|
||||
/// Round 17 B: supports setting the timezone / changing the web password /
|
||||
/// factory reset (probed via the matching `supports_*()` at scan time).
|
||||
pub timezone: bool,
|
||||
pub change_password: bool,
|
||||
pub factory_reset: bool,
|
||||
}
|
||||
|
||||
impl MinerCaps {
|
||||
@@ -233,6 +238,9 @@ impl MinerCaps {
|
||||
tuning: self.tuning && other.tuning,
|
||||
firmware_flash: self.firmware_flash && other.firmware_flash,
|
||||
pools: self.pools && other.pools,
|
||||
timezone: self.timezone && other.timezone,
|
||||
change_password: self.change_password && other.change_password,
|
||||
factory_reset: self.factory_reset && other.factory_reset,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +270,9 @@ impl MinerCaps {
|
||||
|| self.tuning
|
||||
|| self.firmware_flash
|
||||
|| self.pools
|
||||
|| self.timezone
|
||||
|| self.change_password
|
||||
|| self.factory_reset
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2244,6 +2255,9 @@ mod tests {
|
||||
tuning: true,
|
||||
firmware_flash: true,
|
||||
pools: true,
|
||||
timezone: true,
|
||||
change_password: true,
|
||||
factory_reset: true,
|
||||
};
|
||||
let idle = MinerCaps { fault_light: true, restart: true, ..Default::default() };
|
||||
// Two full miners keep every action.
|
||||
|
||||
@@ -651,6 +651,9 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
tuning: miner.supports_set_tuning_percent(),
|
||||
firmware_flash: miner.supports_upgrade_firmware(),
|
||||
pools: miner.supports_pools_config(),
|
||||
timezone: miner.supports_timezone_config(),
|
||||
change_password: miner.supports_change_password(),
|
||||
factory_reset: miner.supports_factory_reset(),
|
||||
};
|
||||
// PIC vs noPIC (round 14 #2 rework). No firmware exposes a PIC flag over the
|
||||
// network -- it's a fixed hardware property of the hashboard type -- so infer
|
||||
@@ -770,6 +773,9 @@ pub enum ConfigAction {
|
||||
Resume,
|
||||
PowerLimit(f64), // watts
|
||||
TuningPercent(u8),
|
||||
Timezone(String), // IANA zone, e.g. "America/Edmonton" (round 17 B / G10)
|
||||
ChangePassword(String), // new web/API password (round 17 B / G11)
|
||||
FactoryReset, // round 17 B / G12
|
||||
}
|
||||
|
||||
impl ConfigAction {
|
||||
@@ -783,6 +789,9 @@ impl ConfigAction {
|
||||
ConfigAction::Resume => "resume".into(),
|
||||
ConfigAction::PowerLimit(w) => format!("power limit {w:.0} W"),
|
||||
ConfigAction::TuningPercent(p) => format!("tuning {p}%"),
|
||||
ConfigAction::Timezone(tz) => format!("timezone {tz}"),
|
||||
ConfigAction::ChangePassword(_) => "change password".into(),
|
||||
ConfigAction::FactoryReset => "factory reset".into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,6 +806,9 @@ impl ConfigAction {
|
||||
ConfigAction::Resume => "resuming…".into(),
|
||||
ConfigAction::PowerLimit(_) => "setting power…".into(),
|
||||
ConfigAction::TuningPercent(_) => "tuning…".into(),
|
||||
ConfigAction::Timezone(_) => "setting timezone…".into(),
|
||||
ConfigAction::ChangePassword(_) => "changing password…".into(),
|
||||
ConfigAction::FactoryReset => "factory resetting…".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -828,6 +840,25 @@ async fn apply_action(miner: &dyn Miner, action: &ConfigAction) -> Result<bool,
|
||||
ConfigAction::Resume => miner.resume(None).await,
|
||||
ConfigAction::PowerLimit(w) => miner.set_power_limit(Power::from_watts(*w)).await,
|
||||
ConfigAction::TuningPercent(p) => miner.set_tuning_percent(*p).await,
|
||||
ConfigAction::Timezone(tz) => {
|
||||
use asic_rs::core::config::timezone::{Tz, TimezoneConfig};
|
||||
match tz.parse::<Tz>() {
|
||||
Ok(zone) => {
|
||||
miner
|
||||
.set_timezone_config(TimezoneConfig {
|
||||
timezone: Some(zone),
|
||||
available: Vec::new(),
|
||||
})
|
||||
.await
|
||||
}
|
||||
Err(_) => return Err(format!("invalid IANA timezone '{tz}'")),
|
||||
}
|
||||
}
|
||||
ConfigAction::FactoryReset => miner.factory_reset().await,
|
||||
// ChangePassword takes &mut self; handled in the run loop, not here.
|
||||
ConfigAction::ChangePassword(_) => {
|
||||
return Err("internal: change-password handled separately".to_string());
|
||||
}
|
||||
};
|
||||
result.map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -883,11 +914,21 @@ pub fn start_config_action(ips: Vec<String>, action: ConfigAction) -> ActionHand
|
||||
let (success, detail) = match ip_s.parse::<std::net::IpAddr>() {
|
||||
Err(_) => (false, "bad IP".to_string()),
|
||||
Ok(ip) => match factory.scan_miner(ip).await {
|
||||
Ok(Some(miner)) => match apply_action(&*miner, &action).await {
|
||||
Ok(true) => (true, "ok".to_string()),
|
||||
Ok(false) => (false, "refused".to_string()),
|
||||
Err(e) => (false, format!("{e}")),
|
||||
},
|
||||
Ok(Some(mut miner)) => {
|
||||
// change_password takes &mut self, so it can't go through
|
||||
// apply_action(&dyn Miner); run it on the owned miner here.
|
||||
let outcome = match &action {
|
||||
ConfigAction::ChangePassword(p) => {
|
||||
miner.change_password(p).await.map_err(|e| e.to_string())
|
||||
}
|
||||
other => apply_action(&*miner, other).await,
|
||||
};
|
||||
match outcome {
|
||||
Ok(true) => (true, "ok".to_string()),
|
||||
Ok(false) => (false, "refused".to_string()),
|
||||
Err(e) => (false, format!("{e}")),
|
||||
}
|
||||
}
|
||||
Ok(None) => (false, "no miner at IP".to_string()),
|
||||
Err(e) => (false, format!("{e}")),
|
||||
},
|
||||
|
||||
+81
-22
@@ -67,6 +67,10 @@ const ID_CTX_RESUME: i32 = 726;
|
||||
const ID_CTX_TUNING: i32 = 727;
|
||||
const ID_CTX_POWER: i32 = 728;
|
||||
const ID_CTX_RESTART: i32 = 729;
|
||||
// Round 17 B: timezone / change-password / factory-reset config actions.
|
||||
const ID_CTX_TIMEZONE: i32 = 737;
|
||||
const ID_CTX_PASSWORD: i32 = 738;
|
||||
const ID_CTX_FACTORY_RESET: i32 = 739;
|
||||
const ID_CTX_ACCESS_PROBE: i32 = 731;
|
||||
// View a miner's log fetched over its firmware API (round 12 #12).
|
||||
const ID_CTX_VIEW_LOG: i32 = 734;
|
||||
@@ -85,9 +89,18 @@ const ID_POOL_PLUS_BASE: i32 = 800;
|
||||
const ID_POOL_MENU_ADD: i32 = 819; // "add new" (adds current box value to the dropdown)
|
||||
const ID_POOL_MENU_BASE: i32 = 820; // one id per dropdown entry (820 + index)
|
||||
const ID_POOL_MENU_REMOVE_BASE: i32 = 1000; // one id per removable saved entry (round 16 #5)
|
||||
// Value-prompt dialog for power-limit / tuning-percent actions.
|
||||
// Value-prompt dialog for power-limit / tuning-percent / timezone / password.
|
||||
const ID_ACTION_OK: i32 = 740;
|
||||
const ID_ACTION_CANCEL: i32 = 741;
|
||||
|
||||
/// Which value the shared text/number prompt is collecting (round 17 B).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum PromptKind {
|
||||
Power,
|
||||
Tuning,
|
||||
Timezone,
|
||||
Password,
|
||||
}
|
||||
// Confirmation dialog for disruptive actions (restart / pause / resume).
|
||||
const ID_CONFIRM_OK: i32 = 742;
|
||||
const ID_CONFIRM_CANCEL: i32 = 743;
|
||||
@@ -659,7 +672,7 @@ pub struct App {
|
||||
action_ips: Vec<String>,
|
||||
action_prompt: Widget,
|
||||
action_input: Widget,
|
||||
action_is_power: bool,
|
||||
action_kind: PromptKind,
|
||||
action_total: usize,
|
||||
action_done: usize,
|
||||
// IPs the current config action targets, re-probed after it completes so the
|
||||
@@ -984,7 +997,7 @@ pub fn build(frame: Widget) -> App {
|
||||
action_ips: Vec::new(),
|
||||
action_prompt: frame,
|
||||
action_input: frame,
|
||||
action_is_power: false,
|
||||
action_kind: PromptKind::Power,
|
||||
action_total: 0,
|
||||
action_done: 0,
|
||||
action_targets: Vec::new(),
|
||||
@@ -1469,6 +1482,19 @@ impl App {
|
||||
if caps.pools {
|
||||
menu.menu_append(ID_CTX_POOLS, &format!("Configure pools...{sfx}"));
|
||||
}
|
||||
if caps.timezone {
|
||||
menu.menu_append(ID_CTX_TIMEZONE, &format!("Set timezone...{sfx}"));
|
||||
}
|
||||
// Destructive / credential-changing actions, set apart (round 17 B).
|
||||
if caps.change_password || caps.factory_reset {
|
||||
menu.menu_append_separator();
|
||||
if caps.change_password {
|
||||
menu.menu_append(ID_CTX_PASSWORD, &format!("Change password...{sfx}"));
|
||||
}
|
||||
if caps.factory_reset {
|
||||
menu.menu_append(ID_CTX_FACTORY_RESET, &format!("Factory reset...{sfx}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Firmware flash is intentionally not offered for now (round 16 #6): the
|
||||
// in-app flash path is disabled while it is reworked. Restore-to-stock +
|
||||
@@ -2079,8 +2105,13 @@ impl App {
|
||||
ID_CTX_RESUME => return Some(self.build_confirm_dialog(scan::ConfigAction::Resume)),
|
||||
ID_CTX_RESTART => return Some(self.build_confirm_dialog(scan::ConfigAction::Restart)),
|
||||
// Value entry is itself the confirmation.
|
||||
ID_CTX_POWER => return Some(self.build_action_prompt(true)),
|
||||
ID_CTX_TUNING => return Some(self.build_action_prompt(false)),
|
||||
ID_CTX_POWER => return Some(self.build_action_prompt(PromptKind::Power)),
|
||||
ID_CTX_TUNING => return Some(self.build_action_prompt(PromptKind::Tuning)),
|
||||
ID_CTX_TIMEZONE => return Some(self.build_action_prompt(PromptKind::Timezone)),
|
||||
ID_CTX_PASSWORD => return Some(self.build_action_prompt(PromptKind::Password)),
|
||||
ID_CTX_FACTORY_RESET => {
|
||||
return Some(self.build_confirm_dialog(scan::ConfigAction::FactoryReset))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
None
|
||||
@@ -2095,9 +2126,17 @@ impl App {
|
||||
scan::ConfigAction::Restart => ("Restart", "Restart"),
|
||||
scan::ConfigAction::Pause => ("Pause mining on", "Pause"),
|
||||
scan::ConfigAction::Resume => ("Resume mining on", "Resume"),
|
||||
scan::ConfigAction::FactoryReset => ("Factory reset", "Factory reset"),
|
||||
_ => ("Apply to", "Confirm"),
|
||||
};
|
||||
let msg = format!("{verb} {n} selected miner(s)? This affects running hardware.");
|
||||
let msg = if matches!(action, scan::ConfigAction::FactoryReset) {
|
||||
format!(
|
||||
"Factory reset {n} selected miner(s)? This WIPES their configuration (pools, \
|
||||
tuning, network) and reboots -- a miner may return on DHCP and change IP."
|
||||
)
|
||||
} else {
|
||||
format!("{verb} {n} selected miner(s)? This affects running hardware.")
|
||||
};
|
||||
self.pending_confirm = Some((ips, action));
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Confirm action");
|
||||
@@ -2117,17 +2156,24 @@ impl App {
|
||||
|
||||
/// A small modal to enter a power limit (watts) or tuning percent for the
|
||||
/// selection. Built here, shown modally by `dispatch` outside the App borrow.
|
||||
fn build_action_prompt(&mut self, is_power: bool) -> Widget {
|
||||
fn build_action_prompt(&mut self, kind: PromptKind) -> Widget {
|
||||
self.action_ips = self.selected_ip_list();
|
||||
self.action_is_power = is_power;
|
||||
self.action_kind = kind;
|
||||
let n = self.action_ips.len();
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, if is_power { "Set power limit" } else { "Set tuning percent" });
|
||||
let title = match kind {
|
||||
PromptKind::Power => "Set power limit",
|
||||
PromptKind::Tuning => "Set tuning percent",
|
||||
PromptKind::Timezone => "Set timezone",
|
||||
PromptKind::Password => "Change password",
|
||||
};
|
||||
let dlg = Widget::dialog(frame, title);
|
||||
let root = Widget::box_sizer(true);
|
||||
let lbl = if is_power {
|
||||
format!("Power limit in watts for {n} miner(s):")
|
||||
} else {
|
||||
format!("Tuning percent (0-100) for {n} miner(s):")
|
||||
let lbl = match kind {
|
||||
PromptKind::Power => format!("Power limit in watts for {n} miner(s):"),
|
||||
PromptKind::Tuning => format!("Tuning percent (0-100) for {n} miner(s):"),
|
||||
PromptKind::Timezone => format!("IANA timezone (e.g. America/Edmonton) for {n} miner(s):"),
|
||||
PromptKind::Password => format!("New web/API password for {n} miner(s):"),
|
||||
};
|
||||
root.add(Widget::static_text(dlg, &lbl), 0, sf::BORDER_ALL, 8);
|
||||
let input = Widget::text_ctrl(dlg, false);
|
||||
@@ -2151,15 +2197,27 @@ impl App {
|
||||
/// captured selection) so the operator can correct it.
|
||||
fn apply_action_prompt(&mut self) {
|
||||
let val = self.action_input.get_value();
|
||||
let action = if self.action_is_power {
|
||||
match val.trim().parse::<f64>() {
|
||||
let action = match self.action_kind {
|
||||
PromptKind::Power => match val.trim().parse::<f64>() {
|
||||
Ok(w) if w > 0.0 && w.is_finite() => Some(scan::ConfigAction::PowerLimit(w)),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
match val.trim().parse::<u8>() {
|
||||
},
|
||||
PromptKind::Tuning => match val.trim().parse::<u8>() {
|
||||
Ok(p) if p <= 100 => Some(scan::ConfigAction::TuningPercent(p)),
|
||||
_ => None,
|
||||
},
|
||||
PromptKind::Timezone => {
|
||||
let tz = val.trim();
|
||||
// Validate as an IANA zone before firing so a typo doesn't hit the fleet.
|
||||
if !tz.is_empty() && tz.parse::<asic_rs::core::config::timezone::Tz>().is_ok() {
|
||||
Some(scan::ConfigAction::Timezone(tz.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
PromptKind::Password => {
|
||||
let p = val.trim();
|
||||
(!p.is_empty()).then(|| scan::ConfigAction::ChangePassword(p.to_string()))
|
||||
}
|
||||
};
|
||||
match action {
|
||||
@@ -2169,10 +2227,11 @@ impl App {
|
||||
self.start_action(ips, a);
|
||||
}
|
||||
None => {
|
||||
let hint = if self.action_is_power {
|
||||
"enter a positive number of watts"
|
||||
} else {
|
||||
"enter a percent from 0 to 100"
|
||||
let hint = match self.action_kind {
|
||||
PromptKind::Power => "enter a positive number of watts",
|
||||
PromptKind::Tuning => "enter a percent from 0 to 100",
|
||||
PromptKind::Timezone => "enter a valid IANA zone, e.g. America/Edmonton",
|
||||
PromptKind::Password => "enter a non-empty password",
|
||||
};
|
||||
wx_rs::set_status_text(&format!("invalid value - {hint}"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
Subject: [PATCH 0015] braiins v26_04: treat an empty 2xx body as success (not a parse error)
|
||||
|
||||
Found live verifying change-password (round 17 B / G11). The BOS REST setters like
|
||||
PUT auth/password answer 2xx with an empty body; send_command tried
|
||||
response.json() on it, which fails, so change_password (which does `.is_ok()`)
|
||||
reported Ok(false) even though the password DID change. Read the body as text
|
||||
first: an empty body on a success status is Null (success), a non-empty body must
|
||||
still parse. Verified live on 10.4.1.27: change root->bftest2 now returns Ok(true),
|
||||
the new password authenticates, and restore -> root returns Ok(true).
|
||||
diff --git a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||
index 624eca4c..3e06b682 100644
|
||||
--- a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||
+++ b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||
@@ -57,11 +57,20 @@ impl WebAPIClient for BraiinsWebAPI {
|
||||
|
||||
let status = response.status();
|
||||
if status.is_success() {
|
||||
- let json_data = response
|
||||
- .json()
|
||||
+ // Some setters (e.g. PUT auth/password) answer 2xx with an empty or
|
||||
+ // non-JSON body. An empty body is success, not a parse error -- treat
|
||||
+ // it as Null so callers using `.is_ok()` don't read a real success as
|
||||
+ // failure. A non-empty body must still parse.
|
||||
+ let body = response
|
||||
+ .text()
|
||||
.await
|
||||
.map_err(|e| BraiinsError::ParseError(e.to_string()))?;
|
||||
- Ok(json_data)
|
||||
+ if body.trim().is_empty() {
|
||||
+ Ok(Value::Null)
|
||||
+ } else {
|
||||
+ Ok(serde_json::from_str(&body)
|
||||
+ .map_err(|e| BraiinsError::ParseError(e.to_string()))?)
|
||||
+ }
|
||||
} else {
|
||||
// The API reports why it rejected a request in the body.
|
||||
let status = status.as_u16();
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+12
-3
@@ -57,11 +57,20 @@ impl WebAPIClient for BraiinsWebAPI {
|
||||
|
||||
let status = response.status();
|
||||
if status.is_success() {
|
||||
let json_data = response
|
||||
.json()
|
||||
// Some setters (e.g. PUT auth/password) answer 2xx with an empty or
|
||||
// non-JSON body. An empty body is success, not a parse error -- treat
|
||||
// it as Null so callers using `.is_ok()` don't read a real success as
|
||||
// failure. A non-empty body must still parse.
|
||||
let body = response
|
||||
.text()
|
||||
.await
|
||||
.map_err(|e| BraiinsError::ParseError(e.to_string()))?;
|
||||
Ok(json_data)
|
||||
if body.trim().is_empty() {
|
||||
Ok(Value::Null)
|
||||
} else {
|
||||
Ok(serde_json::from_str(&body)
|
||||
.map_err(|e| BraiinsError::ParseError(e.to_string()))?)
|
||||
}
|
||||
} else {
|
||||
// The API reports why it rejected a request in the body.
|
||||
let status = status.as_u16();
|
||||
|
||||
Reference in New Issue
Block a user