terrazzo-terminal 0.2.8

A simple web-based terminal emulator built on Terrazzo.
use std::ops::Deref;
use std::sync::Arc;

use serde::Deserialize;
use serde::Serialize;
use trz_gateway_common::dynamic_config::DynamicConfig;
use trz_gateway_common::dynamic_config::has_diff::DiffArc;

use super::types::ConfigTypes;
use super::types::Password;
use super::types::RuntimeTypes;

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ServerConfig<T: ConfigTypes = RuntimeTypes> {
    /// The TCP host to listen to.
    pub host: T::String,

    /// The TCP ports to listen to.
    pub ports: T::Ports,

    /// The shell command to run for new terminals.
    #[serde(rename = "terminal-shell", alias = "terminal_shell")]
    pub terminal_shell: Option<String>,

    /// The folder where deleted text-editor files are moved.
    pub trash: T::Path,

    /// The folder, relative to a Git repository root, where deleted Git files are moved.
    #[serde(rename = "git-trash", alias = "git_trash")]
    pub git_trash: T::MaybePath,

    pub set_current_endpoint: T::MaybePath,

    /// The file to store the pid of the daemon while it is running,
    pub pidfile: T::Path,

    /// The file to the store private Root CA.
    pub private_root_ca: T::Path,

    /// The password to login to the UI.
    pub password: Option<Password>,
    pub token_lifetime: T::Duration,
    pub token_refresh: T::Duration,

    /// Whether to watch the config file for live updates.
    pub config_file_watcher: T::MaybeBool,

    /// Polling strategy for the config file
    pub config_file_poll_strategy: T::MaybeRetryStrategy,

    /// Certificates renewal strategy
    pub certificate_renewal_threshold: T::Duration,
}

#[derive(Clone)]
pub struct DynamicServerConfig(pub(super) Arc<DynamicConfig<DiffArc<ServerConfig>>>);

impl Deref for DynamicServerConfig {
    type Target = Arc<DynamicConfig<DiffArc<ServerConfig>>>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl From<Arc<DynamicConfig<DiffArc<ServerConfig>>>> for DynamicServerConfig {
    fn from(value: Arc<DynamicConfig<DiffArc<ServerConfig>>>) -> Self {
        Self(value)
    }
}