reactive_graph_config_model/
plugins.rs

1use serde::Deserialize;
2use serde::Serialize;
3use std::fs;
4use std::path::PathBuf;
5
6const DEFAULT_HOT_DEPLOY_LOCATION: &str = "./plugins/deploy";
7
8const DEFAULT_INSTALL_LOCATION: &str = "./plugins/installed";
9
10/// Configuration of the plugin system.
11#[derive(Debug, Clone, Deserialize, Serialize)]
12pub struct PluginsConfig {
13    /// If true, the plugin system is disabled.
14    pub disabled: Option<bool>,
15
16    /// The plugins which are disabled.
17    pub disabled_plugins: Option<Vec<String>>,
18
19    /// The plugins which are enabled. If set, disabled_plugins will be ignored.
20    pub enabled_plugins: Option<Vec<String>>,
21
22    /// If true, hot deployment is enabled.
23    pub hot_deploy: Option<bool>,
24
25    /// The folder which is watched for hot deployment.
26    pub hot_deploy_location: Option<String>,
27
28    /// The folder which plugins are installed permanently.
29    pub install_location: Option<String>,
30}
31
32impl PluginsConfig {
33    pub fn is_hot_deploy(&self) -> bool {
34        self.hot_deploy.unwrap_or(true)
35    }
36
37    pub fn get_hot_deploy_location(&self) -> Option<PathBuf> {
38        if !self.is_hot_deploy() {
39            return None;
40        }
41        fs::canonicalize(PathBuf::from(self.hot_deploy_location.clone().unwrap_or(DEFAULT_HOT_DEPLOY_LOCATION.to_string()))).ok()
42    }
43
44    pub fn get_install_location(&self) -> Option<PathBuf> {
45        fs::canonicalize(PathBuf::from(self.install_location.clone().unwrap_or(DEFAULT_INSTALL_LOCATION.to_string()))).ok()
46    }
47}
48
49impl Default for PluginsConfig {
50    fn default() -> Self {
51        PluginsConfig {
52            disabled: Some(false),
53            disabled_plugins: Some(Vec::new()),
54            enabled_plugins: None,
55            hot_deploy: Some(true),
56            hot_deploy_location: Some(DEFAULT_HOT_DEPLOY_LOCATION.to_string()),
57            install_location: Some(DEFAULT_INSTALL_LOCATION.to_string()),
58        }
59    }
60}