mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
Fixes #2363 * Rename `relay` package to `firezone-relay` so that binaries outputted match the `firezone-*` cli naming scheme * Rename `firezone-headless-client` package to `firezone-linux-client` for consistency * Add READMEs for user-facing CLI components (there will also be docs later)
62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
use anyhow::Result;
|
|
use clap::Parser;
|
|
use connlib_client_shared::{file_logger, get_device_id, Callbacks, Error, Session};
|
|
use firezone_cli_utils::{block_on_ctrl_c, setup_global_subscriber, CommonArgs};
|
|
use secrecy::SecretString;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() -> Result<()> {
|
|
let cli = Cli::parse();
|
|
|
|
let (layer, handle) = cli.log_dir.as_deref().map(file_logger::layer).unzip();
|
|
setup_global_subscriber(layer);
|
|
|
|
let device_id = get_device_id();
|
|
|
|
let mut session = Session::connect(
|
|
cli.common.portal_url,
|
|
SecretString::from(cli.common.portal_token),
|
|
device_id,
|
|
CallbackHandler { handle },
|
|
)
|
|
.unwrap();
|
|
tracing::info!("new_session");
|
|
|
|
block_on_ctrl_c();
|
|
|
|
session.disconnect(None);
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct CallbackHandler {
|
|
handle: Option<file_logger::Handle>,
|
|
}
|
|
|
|
impl Callbacks for CallbackHandler {
|
|
type Error = std::convert::Infallible;
|
|
|
|
fn roll_log_file(&self) -> Option<PathBuf> {
|
|
self.handle
|
|
.as_ref()?
|
|
.roll_to_new_file()
|
|
.unwrap_or_else(|e| {
|
|
tracing::debug!("Failed to roll over to new file: {e}");
|
|
let _ = self.on_error(&Error::LogFileRollError(e));
|
|
|
|
None
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(Parser)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct Cli {
|
|
#[command(flatten)]
|
|
common: CommonArgs,
|
|
|
|
/// File logging directory.
|
|
#[arg(short, long, env = "FZ_LOG_DIR")]
|
|
log_dir: Option<PathBuf>,
|
|
}
|