reactive_graph_config_model/
plugins.rs1use 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#[derive(Debug, Clone, Deserialize, Serialize)]
12pub struct PluginsConfig {
13 pub disabled: Option<bool>,
15
16 pub disabled_plugins: Option<Vec<String>>,
18
19 pub enabled_plugins: Option<Vec<String>>,
21
22 pub hot_deploy: Option<bool>,
24
25 pub hot_deploy_location: Option<String>,
27
28 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}