wip(windows): impl get_host_name (#3089)

Resolves #3082 
I can remove the debug subcommand before merging. I just wanted to
confirm it gets my laptop's hostname.

connlib already has an indirect dependency on `hostname` via Hickory, so
I just used that.


![image](https://github.com/firezone/firezone/assets/13400041/e1adada4-f3e9-47be-828e-3e1d1cb69e83)
This commit is contained in:
Reactor Scram
2024-01-02 15:49:57 -06:00
committed by GitHub
parent cf31112e82
commit ed3e76894a
7 changed files with 18 additions and 2 deletions

2
rust/Cargo.lock generated
View File

@@ -1198,6 +1198,7 @@ dependencies = [
"futures",
"futures-util",
"hickory-resolver",
"hostname",
"ip_network",
"libc",
"log",
@@ -2078,6 +2079,7 @@ dependencies = [
"connlib-client-shared",
"connlib-shared",
"firezone-cli-utils",
"hostname",
"ipconfig",
"keyring",
"ring 0.17.7",

View File

@@ -15,6 +15,8 @@ boringtun = { workspace = true }
chrono = { workspace = true }
futures = { version = "0.3", default-features = false, features = ["std", "async-await", "executor"] }
futures-util = { version = "0.3", default-features = false, features = ["std", "async-await", "async-await-macro"] }
# Hickory already depends on `hostname` so this isn't new
hostname = "0.3.1"
ip_network = { version = "0.4", default-features = false, features = ["serde"] }
os_info = { version = "3", default-features = false }
parking_lot = "0.12"

View File

@@ -153,10 +153,10 @@ fn get_host_name() -> Option<String> {
String::from_utf8(buf.split(|c| *c == 0).next()?.to_vec()).ok()
}
/// Returns the hostname, or `None` if it's not valid UTF-8
#[cfg(target_os = "windows")]
fn get_host_name() -> Option<String> {
// FIXME: windows
None
hostname::get().ok().and_then(|x| x.into_string().ok())
}
fn set_ws_scheme(url: &mut Url) -> Result<()> {

View File

@@ -18,6 +18,8 @@ clap = { version = "4.4", features = ["derive", "env"] }
connlib-client-shared = { workspace = true }
connlib-shared = { workspace = true }
firezone-cli-utils = { workspace = true }
# Same crate Hickory uses
hostname = "0.3.1"
# This is the same crate hickory uses to get system resolvers
ipconfig = "0.3.2"
keyring = "2.0.5"

View File

@@ -66,6 +66,7 @@ pub(crate) fn run() -> Result<()> {
println!("debug");
Ok(())
}
Some(Cmd::DebugHostname) => debug_commands::hostname(),
Some(Cmd::DebugPipeServer) => debug_commands::pipe_server(),
Some(Cmd::DebugWintun) => debug_commands::wintun(cli),
// If we already tried to elevate ourselves, don't try again

View File

@@ -12,6 +12,7 @@ pub struct Cli {
#[derive(clap::Subcommand)]
pub enum CliCommands {
Debug,
DebugHostname,
DebugPipeServer,
DebugWintun,
Elevated,

View File

@@ -8,6 +8,14 @@ use tokio::runtime::Runtime;
// TODO: In tauri-plugin-deep-link, this is the identifier in tauri.conf.json
const PIPE_NAME: &str = "dev.firezone.client";
pub fn hostname() -> Result<()> {
println!(
"{:?}",
hostname::get().ok().and_then(|x| x.into_string().ok())
);
Ok(())
}
pub fn open_deep_link(path: &url::Url) -> Result<()> {
tracing_subscriber::fmt::init();