refactor: move hostname plugins to system module and remove basic.rs
Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use gethostname::gethostname;
|
||||
use local_ip_address::local_ip;
|
||||
use dns_lookup::lookup_addr;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::env;
|
||||
@@ -279,3 +282,89 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct HostnameMetaPlugin {
|
||||
meta_name: String,
|
||||
}
|
||||
|
||||
impl HostnameMetaPlugin {
|
||||
pub fn new() -> HostnameMetaPlugin {
|
||||
HostnameMetaPlugin {
|
||||
meta_name: "hostname".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaPlugin for HostnameMetaPlugin {
|
||||
fn create(&self) -> Result<Box<dyn Write>> {
|
||||
Ok(Box::new(io::sink()))
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> io::Result<String> {
|
||||
match gethostname().into_string() {
|
||||
Ok(hostname) => Ok(hostname),
|
||||
Err(_) => Ok("unknown".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
// No update needed for hostname
|
||||
}
|
||||
|
||||
fn meta_name(&mut self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct FullHostnameMetaPlugin {
|
||||
meta_name: String,
|
||||
}
|
||||
|
||||
impl FullHostnameMetaPlugin {
|
||||
pub fn new() -> FullHostnameMetaPlugin {
|
||||
FullHostnameMetaPlugin {
|
||||
meta_name: "full_hostname".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaPlugin for FullHostnameMetaPlugin {
|
||||
fn create(&self) -> Result<Box<dyn Write>> {
|
||||
Ok(Box::new(io::sink()))
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> io::Result<String> {
|
||||
// Try to get the FQDN through reverse DNS lookup
|
||||
match local_ip() {
|
||||
Ok(my_local_ip) => {
|
||||
match lookup_addr(&my_local_ip) {
|
||||
Ok(hostname) => Ok(hostname),
|
||||
Err(_) => {
|
||||
// Fall back to regular hostname if reverse DNS fails
|
||||
match gethostname().into_string() {
|
||||
Ok(hostname) => Ok(hostname),
|
||||
Err(_) => Ok("unknown".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// Fall back to regular hostname if we can't get local IP
|
||||
match gethostname().into_string() {
|
||||
Ok(hostname) => Ok(hostname),
|
||||
Err(_) => Ok("unknown".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
// No update needed for full hostname
|
||||
}
|
||||
|
||||
fn meta_name(&mut self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user