Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support important plugins #252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Coffee mod implementation
use std::collections::HashMap;
use std::fmt::Debug;
use std::vec::Vec;

Check warning on line 4 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `Vec` is imported redundantly

Check warning on line 4 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `Vec` is imported redundantly
use tokio::fs;

use async_trait::async_trait;
use clightningrpc_common::client::Client;
use clightningrpc_common::json_utils;
use clightningrpc_conf::{CLNConf, SyncCLNConf};
use log;

Check warning on line 11 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly

Check warning on line 11 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -271,6 +271,12 @@
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/<repo_name>/<plugin_name>
let old_root_path = plugin.root_path.clone();
Expand All @@ -297,6 +303,12 @@
);
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);
Expand All @@ -312,7 +324,7 @@
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?;
Expand Down Expand Up @@ -348,9 +360,14 @@
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"
};
let remove_config = self
.coffee_cln_config
.rm_conf("plugin", Some(&exec_path.to_owned()));
.rm_conf(plugin_conf_key, Some(&exec_path.to_owned()));
if let Err(err) = remove_config {
// if this is true, we are probably a dynamic plugin:
if err.cause.contains("field with `plugin` not present") {
Expand Down
12 changes: 12 additions & 0 deletions coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! from a plugin manager point of view.
use std::fmt::{self, Display};

use log;

Check warning on line 5 in coffee_lib/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly

Check warning on line 5 in coffee_lib/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly
use serde::{Deserialize, Serialize};
use tokio::process::Command;

Expand Down Expand Up @@ -165,6 +165,18 @@
pub fn tipping_info(&self) -> Option<Tipping> {
self.conf.as_ref().and_then(|conf| conf.tipping.clone())
}

pub fn important(&self) -> bool {
if let Some(config) = &self.conf {
if let Some(important) = config.plugin.important {
important
} else {
false
}
} else {
false
}
}
}

impl fmt::Display for Plugin {
Expand Down
1 change: 1 addition & 0 deletions coffee_lib/src/plugin_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Plugin {
pub dependencies: Option<Vec<String>>,
pub install: Option<String>,
pub main: String,
pub important: Option<bool>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions docs/docs-book/src/support-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading