use std::time::Duration;
use crate::Context;
use crate::place::ssh::{SshError, Target};
const READ_LIMIT: Duration = Duration::from_secs(30);
const SDN_SOURCE_CHECK: &str = r"grep -Eq '^[[:space:]]*source[[:space:]]+/etc/network/interfaces\.d/(\*|sdn)([[:space:]]|$)' /etc/network/interfaces";
pub async fn sdn_sourced(ctx: &Context, node: &Target) -> Result<bool, SshError> {
sourced(node.exec(ctx, SDN_SOURCE_CHECK, READ_LIMIT).await)
}
fn sourced(checked: Result<String, SshError>) -> Result<bool, SshError> {
match checked {
Ok(_) => Ok(true),
Err(SshError::Failed(why)) if why.trim() == "exited with code 1" => Ok(false),
Err(e) => Err(e),
}
}
pub async fn signs_in(ctx: &Context, node: &Target) -> Result<(), SshError> {
node.exec(ctx, "true", READ_LIMIT).await.map(drop)
}
#[cfg(test)]
mod tests;