From 62c8fa03608db2fe1a80e52651ddbc1646f74994 Mon Sep 17 00:00:00 2001 From: daywalker90 Date: Tue, 27 Feb 2024 14:22:25 +0100 Subject: [PATCH] feat: support important plugins added a new manifest field to mark plugin as important only install as static and important part of #245 --- coffee_core/src/coffee.rs | 21 +++++++++++++++++++-- coffee_lib/src/plugin.rs | 13 +++++++++++++ coffee_lib/src/plugin_conf.rs | 1 + docs/docs-book/src/support-coffee.md | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 1bf247e7..25b3f4d2 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -253,6 +253,12 @@ impl PluginManager for CoffeeManager { if let Some(mut plugin) = repo.get_plugin_by_name(plugin) { log::trace!("{:?}", plugin); + if try_dynamic && plugin.important() { + return Err(error!( + "plugin is important, can't be dynamically installed" + )); + } + // old_root_path is the path where the plugin is cloned and currently stored // eg. ~/.coffee/repositories// let old_root_path = plugin.root_path.clone(); @@ -279,6 +285,12 @@ impl PluginManager for CoffeeManager { ); let old_exec_path = plugin.exec_path.clone(); + let plugin_conf_key = if plugin.important() { + "important-plugin" + } else { + "plugin" + }; + match old_exec_path.strip_prefix(&old_root_path) { Some(relative_path) => { let new_exec_path = format!("{}{}", new_root_path, relative_path); @@ -294,7 +306,7 @@ impl PluginManager for CoffeeManager { self.config.plugins.push(plugin); log::debug!("path coffee conf: {}", self.coffee_cln_config.path); self.coffee_cln_config - .add_conf("plugin", &path.to_owned()) + .add_conf(plugin_conf_key, &path.to_owned()) .map_err(|err| error!("{}", err.cause))?; log::debug!("coffee conf updated: {}", self.coffee_cln_config); self.flush().await?; @@ -328,8 +340,13 @@ impl PluginManager for CoffeeManager { log::debug!("runnable plugin path: {exec_path}"); plugins.remove(index); log::debug!("coffee cln config: {}", self.coffee_cln_config); + let plugin_conf_key = if plugin.important() { + "important-plugin" + } else { + "plugin" + }; self.coffee_cln_config - .rm_conf("plugin", Some(&exec_path.to_owned())) + .rm_conf(plugin_conf_key, Some(&exec_path.to_owned())) .map_err(|err| error!("{}", &err.cause))?; self.flush().await?; self.update_conf().await?; diff --git a/coffee_lib/src/plugin.rs b/coffee_lib/src/plugin.rs index 1123c42e..20e6930d 100644 --- a/coffee_lib/src/plugin.rs +++ b/coffee_lib/src/plugin.rs @@ -165,6 +165,19 @@ impl Plugin { pub fn tipping_info(&self) -> Option { self.conf.as_ref().and_then(|conf| conf.tipping.clone()) } + + pub fn important(&self) -> bool { + let config = if let Some(conf) = &self.conf { + conf + } else { + return false; + }; + if let Some(important) = config.plugin.important { + important + } else { + false + } + } } impl fmt::Display for Plugin { diff --git a/coffee_lib/src/plugin_conf.rs b/coffee_lib/src/plugin_conf.rs index b241c6b8..0df276de 100644 --- a/coffee_lib/src/plugin_conf.rs +++ b/coffee_lib/src/plugin_conf.rs @@ -16,6 +16,7 @@ pub struct Plugin { pub dependencies: Option>, pub install: Option, pub main: String, + pub important: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize)] diff --git a/docs/docs-book/src/support-coffee.md b/docs/docs-book/src/support-coffee.md index 27b92f6e..30c71a28 100644 --- a/docs/docs-book/src/support-coffee.md +++ b/docs/docs-book/src/support-coffee.md @@ -35,6 +35,7 @@ Where it is possible to specify the following options: - `lang`: the language of the plugin, used to try to install a plugin when the `install` script is not specified; - `install`: a custom install script used by Coffee to compile the plugin; - `main`: the binary or runnable file that core lightning needs to run. +- `important`: bool flag for plugins that must be run as important-plugin In the future, the coffee will be also able to install `binary` other than a `plugin`, so coffee will be installed with coffee itself. With some craziness will be also possible to manage core lightning itself.