diff --git a/applications/tari_watcher/Cargo.toml b/applications/tari_watcher/Cargo.toml index aac794b1d..4fdb5b2d9 100644 --- a/applications/tari_watcher/Cargo.toml +++ b/applications/tari_watcher/Cargo.toml @@ -9,6 +9,8 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +#tari_common = { workspace = true } + clap = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/applications/tari_watcher/data/watcher/config.toml b/applications/tari_watcher/data/watcher/config.toml deleted file mode 100644 index c674fc0de..000000000 --- a/applications/tari_watcher/data/watcher/config.toml +++ /dev/null @@ -1,36 +0,0 @@ -auto_register = true -base_node_grpc_address = "localhost:18142" -base_wallet_grpc_address = "localhost:18143" -vn_registration_file = "/Users/dkast/go/src/github.com/therealdannzor/tari-dan/applications/tari_watcher/data/watcher/./data/watcher/vn_registration.toml" - -[[instance_config]] -name = "tari_validator_node" -instance_type = "TariValidatorNode" -num_instances = 1 - -[instance_config.settings] - -[[instance_config]] -name = "minotari_wallet" -instance_type = "MinoTariConsoleWallet" -num_instances = 1 - -[instance_config.settings] - -[[executable_config]] -instance_type = "TariValidatorNode" -executable_path = "target/release/minotari_node" -env = [] - -[executable_config.compile] -working_dir = "../tari" -package_name = "minotari_node" - -[[executable_config]] -instance_type = "MinoTariConsoleWallet" -executable_path = "target/release/minotari_wallet" -env = [] - -[executable_config.compile] -working_dir = "../tari" -package_name = "minotari_wallet" diff --git a/applications/tari_watcher/src/cli.rs b/applications/tari_watcher/src/cli.rs index 0df9ea3b2..ae1c1954d 100644 --- a/applications/tari_watcher/src/cli.rs +++ b/applications/tari_watcher/src/cli.rs @@ -5,6 +5,8 @@ use std::path::PathBuf; use clap::Parser; +use crate::config::Config; + #[derive(Clone, Debug, Parser)] pub struct Cli { #[clap(flatten)] @@ -34,15 +36,25 @@ impl Cli { pub struct CommonCli { #[clap(short = 'b', long, parse(from_os_str))] pub base_dir: Option, - #[clap(short, long, parse(from_os_str), default_value = "./data/watcher/config.toml")] + #[clap(short = 'c', long, parse(from_os_str), default_value = "./data/watcher/config.toml")] pub config_path: PathBuf, } #[derive(Clone, Debug, clap::Subcommand)] pub enum Commands { - Init, + Init(InitArgs), Start, } #[derive(Clone, Debug, clap::Args)] -pub struct Overrides {} +pub struct InitArgs { + #[clap(long)] + /// Disable initial and auto registration of the validator node + pub no_auto_register: bool, +} + +impl InitArgs { + pub fn apply(&self, config: &mut Config) { + config.auto_register = !self.no_auto_register; + } +} diff --git a/applications/tari_watcher/src/config.rs b/applications/tari_watcher/src/config.rs index 684bb2c22..ee6c3250b 100644 --- a/applications/tari_watcher/src/config.rs +++ b/applications/tari_watcher/src/config.rs @@ -1,12 +1,16 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause -use crate::Cli; -use std::collections::HashMap; -use std::fmt::{self, Display}; -use std::path::PathBuf; +use std::{ + collections::HashMap, + fmt::{self, Display}, + path::PathBuf, +}; + use tokio::io::{self, AsyncWriteExt}; +use crate::Cli; + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Config { /// Allow watcher to submit a new validator node registration transaction initially and before @@ -31,6 +35,9 @@ pub struct Config { /// The process specific configuration for the executables pub executable_config: Vec, + + /// The channel configuration for alerting and monitoring + pub channel_config: Vec, } impl Config { @@ -53,6 +60,13 @@ impl Display for InstanceType { } } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct ChannelConfig { + pub name: String, + pub enabled: bool, + pub credentials: String, +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ExecutableConfig { pub instance_type: InstanceType, @@ -150,5 +164,17 @@ pub fn get_base_config(cli: &Cli) -> anyhow::Result { vn_registration_file: base_dir.join("vn_registration.toml"), instance_config: instances.to_vec(), executable_config: executables, + channel_config: vec![ + ChannelConfig { + name: "mattermost".to_string(), + enabled: true, + credentials: "".to_string(), + }, + ChannelConfig { + name: "telegram".to_string(), + enabled: true, + credentials: "".to_string(), + }, + ], }) } diff --git a/applications/tari_watcher/src/main.rs b/applications/tari_watcher/src/main.rs index 174493501..cb7c923b9 100644 --- a/applications/tari_watcher/src/main.rs +++ b/applications/tari_watcher/src/main.rs @@ -1,11 +1,13 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause -use crate::cli::{Cli, Commands}; use anyhow::{anyhow, Context}; use tokio::fs; -use crate::config::get_base_config; +use crate::{ + cli::{Cli, Commands}, + config::get_base_config, +}; mod cli; mod config; @@ -16,12 +18,14 @@ async fn main() -> anyhow::Result<()> { let config_path = cli.get_config_path(); match cli.command { - Commands::Init => { + Commands::Init(ref args) => { // set by default in CommonCli let parent = config_path.parent().unwrap(); fs::create_dir_all(parent).await?; - let config = get_base_config(&cli)?; + let mut config = get_base_config(&cli)?; + // optionally disables auto register + args.apply(&mut config); let file = fs::File::create(&config_path) .await @@ -31,6 +35,9 @@ async fn main() -> anyhow::Result<()> { let config_path = config_path .canonicalize() .context("Failed to canonicalize config path")?; + + // TODO: use standardised logging + // if let Err(e) = initialize_logging(..) log::info!("Config file created at {}", config_path.display()); }, Commands::Start => {