use super::{Authority, LysConfig, MachineConfig};
use crate::ServerError;
use std::sync::Arc;
use std::thread::JoinHandle;
pub(super) fn defers(lys: &LysConfig, machine: &MachineConfig) -> bool {
!machine.agent_id.is_empty()
&& machine.carrier_choice.peers.is_none()
&& machine.links.is_empty()
&& machine.carrier_choice.broker_echo.is_none()
&& lys.services.is_none()
&& lys.broker.is_none()
&& !lys.relay.as_ref().is_some_and(|relay| relay.enabled)
}
#[derive(Debug)]
pub struct StartIssue {
authority: Arc<Authority>,
now: u64,
}
impl StartIssue {
pub(super) const fn new(authority: Arc<Authority>, now: u64) -> Self {
Self { authority, now }
}
pub fn begin(self) -> Result<JoinHandle<()>, ServerError> {
std::thread::Builder::new()
.name("liminal-machine-pass".to_owned())
.spawn(move || self.ask())
.map_err(|error| ServerError::ConfigValidation {
message: format!("auth.lys.machine: the pass issue could not start: {error}"),
})
}
fn ask(&self) {
let started = std::time::Instant::now();
match self.authority.refresh(self.now, "boot") {
Ok(()) => tracing::info!("machine pass issued after the bind"),
Err(error) => {
tracing::debug!(reason = %error, "machine pass issue refused after the bind");
}
}
crate::server::boot_steps::finished("machine_pass_issue", started);
}
}
#[cfg(test)]
#[path = "start_issue_tests.rs"]
mod tests;