gitdataai/libs/config/ssh.rs
2026-04-15 09:08:09 +08:00

39 lines
1.2 KiB
Rust

use crate::AppConfig;
impl AppConfig {
pub fn ssh_domain(&self) -> anyhow::Result<String> {
if let Some(ssh_domain) = self.env.get("APP_SSH_DOMAIN") {
return Ok(ssh_domain.to_string());
}
let main_domain = self.main_domain()?;
if let Some(stripped) = main_domain.strip_prefix("https://") {
Ok(stripped.to_string())
} else if let Some(stripped) = main_domain.strip_prefix("http://") {
Ok(stripped.to_string())
} else {
Ok(main_domain)
}
}
pub fn ssh_port(&self) -> anyhow::Result<u16> {
if let Some(ssh_port) = self.env.get("APP_SSH_PORT") {
return Ok(ssh_port.parse::<u16>()?);
}
Ok(8022)
}
pub fn ssh_server_private_key(&self) -> anyhow::Result<String> {
if let Some(private_key) = self.env.get("APP_SSH_SERVER_PRIVATE_KEY") {
return Ok(private_key.to_string());
}
Ok("".to_string())
}
pub fn ssh_server_public_key(&self) -> anyhow::Result<String> {
if let Some(public_key) = self.env.get("APP_SSH_SERVER_PUBLIC_KEY") {
return Ok(public_key.to_string());
}
Ok("".to_string())
}
}