Lines
0 %
Functions
Branches
100 %
use server::config::{ConfigError, config};
fn get_env_var(var_name: &str) -> String {
std::env::var(var_name).unwrap_or_else(|_| panic!("{var_name} must be set"))
}
/// Public-facing SSH endpoint advertised in the
/// `/account/ssh-key` "key added" snippet. All three values are
/// optional — operators set them via env (`SSH_HOSTNAME`,
/// `SSH_PORT`, `SSH_HOST_FINGERPRINT`) on the deployment ConfigMap.
#[derive(Debug, Clone)]
pub struct SshConnectInfo {
pub hostname: String,
pub port: u16,
pub host_fingerprint: String,
impl SshConnectInfo {
fn from_env() -> Self {
Self {
hostname: std::env::var("SSH_HOSTNAME")
.unwrap_or_else(|_| "ssh.example.invalid".to_string()),
port: std::env::var("SSH_PORT")
.ok()
.and_then(|raw| raw.parse::<u16>().ok())
.unwrap_or(2222),
host_fingerprint: std::env::var("SSH_HOST_FINGERPRINT")
.unwrap_or_else(|_| "(not configured)".to_string()),
pub struct Config {
pub site_url: String,
pub redis_url: String,
pub client_origin: String,
pub access_token_private_key: String,
pub access_token_public_key: String,
pub access_token_expires_in: String,
pub access_token_max_age: i64,
pub refresh_token_private_key: String,
pub refresh_token_public_key: String,
pub refresh_token_expires_in: String,
pub refresh_token_max_age: i64,
pub ssh: SshConnectInfo,
impl Config {
pub async fn init() -> Result<Config, ConfigError> {
let site_url = config("site_url")
.await?
.ok_or(ConfigError::NoConfig("site_url".to_string()))?
.to_string();
let client_origin = config("client_origin")
.ok_or(ConfigError::NoConfig("client_origin".to_string()))?
let redis_url = config("redis_url")
.ok_or(ConfigError::NoConfig("redis_url".to_string()))?
let access_token_private_key = config("access_token_private_key")
.ok_or(ConfigError::NoConfig(
"access_token_private_key".to_string(),
))?
let access_token_public_key = config("access_token_public_key")
.ok_or(ConfigError::NoConfig("access_token_public_key".to_string()))?
let access_token_expires_in = config("access_token_expired_in")
.ok_or(ConfigError::NoConfig("access_token_expired_in".to_string()))?
let access_token_max_age = config("access_token_maxage")
.ok_or(ConfigError::NoConfig("access_token_maxage".to_string()))?
let refresh_token_private_key = config("refresh_token_private_key")
"refresh_token_private_key".to_string(),
let refresh_token_public_key = config("refresh_token_public_key")
"refresh_token_public_key".to_string(),
let refresh_token_expires_in = config("refresh_token_expired_in")
"refresh_token_expired_in".to_string(),
let refresh_token_max_age = config("refresh_token_maxage")
.ok_or(ConfigError::NoConfig("refresh_token_maxage".to_string()))?
Ok(Config {
site_url,
redis_url,
client_origin,
access_token_private_key,
access_token_public_key,
refresh_token_private_key,
refresh_token_public_key,
access_token_expires_in,
refresh_token_expires_in,
access_token_max_age: access_token_max_age.parse::<i64>().unwrap(),
refresh_token_max_age: refresh_token_max_age.parse::<i64>().unwrap(),
ssh: SshConnectInfo::from_env(),
})