Commit 82257726 authored by Éloïs's avatar Éloïs

[enh] add plugins cli injection

parent 5f5c380c
......@@ -132,7 +132,6 @@ dependencies = [
"textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -228,7 +227,6 @@ dependencies = [
name = "duniter-core"
version = "0.1.0-a0.1"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"duniter-blockchain 0.1.0-a0.1",
"duniter-conf 0.1.0-a0.1",
......@@ -236,17 +234,13 @@ dependencies = [
"duniter-message 0.1.0-a0.1",
"duniter-module 0.1.0-a0.1",
"duniter-network 0.1.0-a0.1",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"simplelog 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sqlite 0.23.9 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -322,6 +316,7 @@ dependencies = [
"serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -358,6 +353,7 @@ dependencies = [
"serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -380,6 +376,7 @@ dependencies = [
"duniter-tui 0.1.0-a0.1",
"durs-ws2p 0.1.0-a0.1",
"durs-ws2p-v1-legacy 0.1.0-a0.1",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -395,6 +392,7 @@ dependencies = [
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -437,6 +435,7 @@ dependencies = [
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"sqlite 0.23.9 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"ws 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -958,6 +957,25 @@ name = "strsim"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "structopt"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "structopt-derive"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.11.11"
......@@ -1177,11 +1195,6 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "yaml-rust"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
......@@ -1272,6 +1285,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum sqlite3-src 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "46e0bc115b563b1ee6c665ef895b56bf488522f57d1c6571887547c57c8f5a88"
"checksum sqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71fec807a1534bd13eeaaec396175d67c79bdc68df55e18a452726ec62a8fb08"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e9ad6a11096cbecdcca0cc6aa403fdfdbaeda2fb3323a39c98e6a166a1e45a"
"checksum structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4cbce8ccdc62166bd594c14396a3242bf94c337a51dbfa9be1076dd74b3db2af"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c67da57e61ebc7b7b6fff56bb34440ca3a83db037320b0507af4c10368deda7d"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
......@@ -1301,4 +1316,3 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum ws 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ccf752fee5350ca505fdb0b34d503b17d1528bd867561b7aa91d6ea750d5e972"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"
......@@ -7,14 +7,16 @@ license = "AGPL-3.0"
[dependencies]
duniter-core = { path = "./core" }
duniter-tui = { path = "./tui", optional = true }
durs-ws2p = { path = "./ws2p" }
durs-ws2p-v1-legacy = { path = "./ws2p-v1-legacy" }
structopt= "0.2.*"
[target.'cfg(unix)'.dependencies]
duniter-tui = { path = "./tui" }
[features]
default = ["tui","ssl"]
default = ["ssl"]
ssl = ["durs-ws2p-v1-legacy/ssl"]
tui = ["duniter-tui"]
# Treat warnings as a build error.
strict = []
......
......@@ -172,6 +172,25 @@ impl DuniterConf for DuRsConf {
_ => panic!("Fail to load duniter conf : conf version not supported !"),
}
}
fn set_module_conf(&mut self, module_id: String, new_module_conf: serde_json::Value) {
match *self {
DuRsConf::V1(ref mut conf_v1) => {
if conf_v1.modules.is_null() {
let mut new_modules_conf = serde_json::Map::with_capacity(1);
new_modules_conf.insert(module_id, new_module_conf);
conf_v1.modules = serde_json::value::to_value(new_modules_conf)
.expect("Fail to create map of new modules conf !");
} else {
conf_v1
.modules
.as_object_mut()
.expect("Conf file currupted !")
.insert(module_id, new_module_conf);
}
}
_ => panic!("Fail to set duniter conf : conf version not supported !"),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
......
......@@ -9,7 +9,6 @@ license = "AGPL-3.0"
path = "lib.rs"
[dependencies]
clap = {version = "2.31.2", features = ["yaml"]}
dirs = "1.0.2"
duniter-blockchain = { path = "../blockchain" }
duniter-conf = { path = "../conf" }
......@@ -17,17 +16,13 @@ duniter-crypto = { path = "../crypto" }
duniter-message = { path = "../message" }
duniter-module = { path = "../module" }
duniter-network = { path = "../network" }
lazy_static = "1.0.*"
log = "0.4.*"
log-panics = "2.0.*"
rand = "0.4.*"
regex = "1.0.*"
rust-crypto = "0.2.*"
serde = "1.0.*"
serde_derive = "1.0.*"
serde_json = "1.0.*"
simplelog = "0.5.*"
sqlite = "0.23.*"
structopt= "0.2.*"
threadpool = "1.7.*"
[features]
......
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Durs-core cli : dbex subcommands.
extern crate structopt;
#[derive(StructOpt, Debug, Clone)]
#[structopt(
name = "dbex",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// durs databases explorer
pub struct DbExOpt {
#[structopt(short = "c", long = "csv")]
/// csv output
pub csv: bool,
#[structopt(subcommand)]
/// DbExSubCommand
pub subcommand: DbExSubCommand,
}
#[derive(StructOpt, Debug, Clone)]
/// dbex subcommands
pub enum DbExSubCommand {
#[structopt(
name = "distance",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// durs databases explorer (distances datas)
DistanceOpt(DistanceOpt),
#[structopt(
name = "members",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// durs databases explorer (members datas)
MembersOpt(MembersOpt),
#[structopt(
name = "member",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// durs databases explorer (member datas)
MemberOpt(MemberOpt),
#[structopt(
name = "balance",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// durs databases explorer (balances datas)
BalanceOpt(BalanceOpt),
}
#[derive(StructOpt, Debug, Copy, Clone)]
/// DistanceOpt
pub struct DistanceOpt {
#[structopt(short = "r", long = "reverse")]
/// reverse order
pub reverse: bool,
}
#[derive(StructOpt, Debug, Copy, Clone)]
/// MembersOpt
pub struct MembersOpt {
#[structopt(short = "r", long = "reverse")]
/// reverse order
pub reverse: bool,
#[structopt(short = "e", long = "expire")]
/// show members expire date
pub expire: bool,
}
#[derive(StructOpt, Debug, Clone)]
/// MemberOpt
pub struct MemberOpt {
/// choose member uid
pub uid: String,
}
#[derive(StructOpt, Debug, Clone)]
/// BalanceOpt
pub struct BalanceOpt {
/// public key or uid
pub address: String,
}
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Define durs-core cli subcommands options.
extern crate structopt;
pub mod dbex;
pub mod modules;
pub mod reset;
pub mod start;
pub mod sync;
pub use dbex::*;
use log::Level;
pub use modules::*;
pub use reset::*;
pub use start::*;
pub use sync::*;
/*/// Inject core subcommands
pub fn inject_core_subcommands<'a, 'b>(
core_cli_conf_without_subcommands: App<'a, 'b>,
) -> App<'a, 'b> {
core_cli_conf_without_subcommands.subcommands(vec![
EnableOpt::clap(),
DisableOpt::clap(),
ListModulesOpt::clap(),
StartOpt::clap(),
SyncOpt::clap(),
SyncTsOpt::clap(),
])
}*/
#[derive(StructOpt, Debug)]
#[structopt(
name = "durs",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// Rust implementation of Duniter
pub struct DursOpt {
#[structopt(short = "p", long = "profile")]
/// Set a custom user datas folder
profile_name: Option<String>,
#[structopt(short = "l", long = "logs", raw(next_line_help = "true"))]
/// Set the level of logs verbosity. (Default is INFO).
/// Possible values : [OFF, ERROR, WARN, INFO, DEBUG, TRACE]
logs_level: Option<Level>,
#[structopt(subcommand)]
/// CoreSubCommand
cmd: CoreSubCommand,
}
#[derive(StructOpt, Debug)]
/// Core cli subcommands
pub enum CoreSubCommand {
#[structopt(name = "enable")]
/// Enable some module
EnableOpt(EnableOpt),
#[structopt(name = "disable")]
/// Disable some module
DisableOpt(DisableOpt),
#[structopt(name = "modules")]
/// list modules
ListModulesOpt(ListModulesOpt),
#[structopt(name = "start")]
/// start durs server
StartOpt(StartOpt),
#[structopt(name = "sync")]
/// synchronization from network
SyncOpt(SyncOpt),
#[structopt(name = "sync_ts")]
/// synchronization via a duniter-ts database
SyncTsOpt(SyncTsOpt),
/// reset data or conf or all
#[structopt(
name = "reset",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
ResetOpt(ResetOpt),
/// durs databases explorer
#[structopt(
name = "dbex",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
DbExOpt(DbExOpt),
}
/// InvalidInput
#[derive(Debug, Copy, Clone)]
pub struct InvalidInput(&'static str);
impl ToString for InvalidInput {
fn to_string(&self) -> String {
String::from(self.0)
}
}
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Durs-core cli : modules manager subcommands.
extern crate structopt;
use duniter_module::*;
use std::collections::HashSet;
#[derive(StructOpt, Debug)]
#[structopt(
name = "enable",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// Enable some module
pub struct EnableOpt {
#[structopt(parse(from_str))]
/// The module name to enable
pub module_name: ModuleId,
}
#[derive(StructOpt, Debug)]
#[structopt(
name = "disable",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// Disable some module
pub struct DisableOpt {
#[structopt(parse(from_str))]
/// The module name to disable
pub module_name: ModuleId,
}
#[derive(StructOpt, Debug, Copy, Clone)]
#[structopt(
name = "modules",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// list module
pub struct ListModulesOpt {
#[structopt(short = "d")]
/// list only disabled modules
pub disabled: bool,
#[structopt(short = "e")]
/// list only enabled modules
pub enabled: bool,
#[structopt(short = "n")]
/// list only network modules
pub network: bool,
#[structopt(short = "s")]
/// list only modules having access to the secret member key
pub secret: bool,
}
impl ListModulesOpt {
/// Extract modules filters from cli options
pub fn get_filters(self) -> HashSet<ModulesFilter> {
let mut filters = HashSet::with_capacity(4);
if self.disabled {
filters.insert(ModulesFilter::Enabled(false));
}
if self.enabled {
filters.insert(ModulesFilter::Enabled(true));
}
if self.network {
filters.insert(ModulesFilter::Network());
}
if self.secret {
filters.insert(ModulesFilter::RequireMemberPrivKey());
}
filters
}
}
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Durs-core cli : reset subcommand.
extern crate structopt;
use cli::InvalidInput;
use std::str::FromStr;
#[derive(StructOpt, Debug, Copy, Clone)]
/// start durs server
pub struct ResetOpt {
/// choose type datas to reset
pub reset_type: ResetType,
}
#[derive(Debug, Copy, Clone)]
/// Reset type
pub enum ResetType {
/// Reset datas
Datas,
/// Reset configuration
Conf,
/// Reset all
All,
}
impl FromStr for ResetType {
type Err = InvalidInput;
fn from_str(source: &str) -> Result<Self, Self::Err> {
match source {
"data" => Ok(ResetType::Datas),
"conf" => Ok(ResetType::Conf),
"all" => Ok(ResetType::All),
_ => Err(InvalidInput("Values accepted are : data, conf, all.")),
}
}
}
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Durs-core cli : start subcommands.
extern crate structopt;
#[derive(StructOpt, Debug, Copy, Clone)]
#[structopt(
name = "start",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// start durs server
pub struct StartOpt {}
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Durs-core cli : sync subcommands.
extern crate structopt;
#[derive(StructOpt, Debug, Clone)]
#[structopt(
name = "sync",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// synchronization from network
pub struct SyncOpt {
/// The domain name or ip address of the node from which to synchronize.
pub host: String,
/// The port number of the node from which to synchronize.
pub port: u16,
/// The endpoint path of the node from which to synchronize.
pub path: Option<String>,
#[structopt(short = "c", long = "cautious")]
/// cautious mode (check all protocol rules, very slow)
pub cautious_mode: bool,
#[structopt(short = "u", long = "unsafe")]
/// unsafe mode (not check blocks inner hashs, very dangerous)
pub unsafe_mode: bool,
}
#[derive(StructOpt, Debug, Clone)]
#[structopt(
name = "sync",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
/// synchronization via a duniter-ts database
pub struct SyncTsOpt {
/// Set the ts profile to use
pub ts_profile: Option<String>,
#[structopt(short = "c", long = "cautious")]
/// cautious mode (check all protocol rules, very slow)
pub cautious_mode: bool,
#[structopt(short = "u", long = "unsafe")]
/// unsafe mode (not check blocks inner hashs, very dangerous)
pub unsafe_mode: bool,
}
This diff is collapsed.
......@@ -90,7 +90,6 @@ pub trait BinSignable<'de>: Serialize + Deserialize<'de> {
} else {
self.compute_hash()?
};
println!("DEBUG: verified hash={:?}", hash.0);
if pubkey.verify(&hash.0, &sig) {
Ok(())
} else {
......
......@@ -14,6 +14,7 @@ duniter-documents = { path = "../documents" }
serde = "1.0.*"