From a428d3302427f5a231e470cfe88c82d2331e1225 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 20 May 2024 22:50:13 +0530 Subject: [PATCH] feat(node_manager): pass foundation sk to the auditor --- sn_auditor/src/main.rs | 2 +- sn_node_manager/src/add_services/config.rs | 6 +++++- sn_node_manager/src/add_services/mod.rs | 3 ++- sn_node_manager/src/add_services/tests.rs | 2 ++ sn_node_manager/src/bin/cli/main.rs | 5 +++++ sn_node_manager/src/cmd/auditor.rs | 3 +++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sn_auditor/src/main.rs b/sn_auditor/src/main.rs index 9c19520ab4..8fc4af0469 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -66,7 +66,7 @@ struct Opt { beta_participants: Option, /// Hex string of the Foundation SK. - #[clap(name = "sk")] + #[clap(long, name = "sk")] sk_str: String, } diff --git a/sn_node_manager/src/add_services/config.rs b/sn_node_manager/src/add_services/config.rs index 60f9317f99..68d657667d 100644 --- a/sn_node_manager/src/add_services/config.rs +++ b/sn_node_manager/src/add_services/config.rs @@ -150,9 +150,10 @@ pub struct AddNodeServiceOptions { #[derive(Debug, PartialEq)] pub struct InstallAuditorServiceCtxBuilder { + pub auditor_path: PathBuf, pub bootstrap_peers: Vec, pub env_variables: Option>, - pub auditor_path: PathBuf, + pub foundation_sk_string: String, pub log_dir_path: PathBuf, pub name: String, pub service_user: String, @@ -175,6 +176,8 @@ impl InstallAuditorServiceCtxBuilder { args.push(OsString::from("--peer")); args.push(OsString::from(peers_str)); } + args.push(OsString::from("--sk-str")); + args.push(OsString::from(self.foundation_sk_string)); Ok(ServiceInstallCtx { label: self.name.parse()?, @@ -233,6 +236,7 @@ impl InstallFaucetServiceCtxBuilder { pub struct AddAuditorServiceOptions { pub bootstrap_peers: Vec, + pub foundation_sk_string: String, pub env_variables: Option>, pub auditor_install_bin_path: PathBuf, pub auditor_src_bin_path: PathBuf, diff --git a/sn_node_manager/src/add_services/mod.rs b/sn_node_manager/src/add_services/mod.rs index 500acf902b..1d07241fa7 100644 --- a/sn_node_manager/src/add_services/mod.rs +++ b/sn_node_manager/src/add_services/mod.rs @@ -312,9 +312,10 @@ pub fn add_auditor( )?; let install_ctx = InstallAuditorServiceCtxBuilder { + auditor_path: install_options.auditor_install_bin_path.clone(), bootstrap_peers: install_options.bootstrap_peers.clone(), env_variables: install_options.env_variables.clone(), - auditor_path: install_options.auditor_install_bin_path.clone(), + foundation_sk_string: install_options.foundation_sk_string.clone(), log_dir_path: install_options.service_log_dir_path.clone(), name: "auditor".to_string(), service_user: install_options.user.clone(), diff --git a/sn_node_manager/src/add_services/tests.rs b/sn_node_manager/src/add_services/tests.rs index c00cdae659..89ed9a9e3a 100644 --- a/sn_node_manager/src/add_services/tests.rs +++ b/sn_node_manager/src/add_services/tests.rs @@ -2385,6 +2385,7 @@ async fn add_auditor_should_add_a_auditor_service() -> Result<()> { add_auditor( AddAuditorServiceOptions { bootstrap_peers: vec![], + foundation_sk_string: "test".to_string(), env_variables: Some(vec![("SN_LOG".to_string(), "all".to_string())]), auditor_src_bin_path: auditor_download_path.to_path_buf(), auditor_install_bin_path: auditor_install_path.to_path_buf(), @@ -2455,6 +2456,7 @@ async fn add_auditor_should_return_an_error_if_a_auditor_service_was_already_cre let result = add_auditor( AddAuditorServiceOptions { bootstrap_peers: vec![], + foundation_sk_string: "test".to_string(), env_variables: Some(vec![("SN_LOG".to_string(), "all".to_string())]), auditor_src_bin_path: auditor_download_path.to_path_buf(), auditor_install_bin_path: auditor_install_path.to_path_buf(), diff --git a/sn_node_manager/src/bin/cli/main.rs b/sn_node_manager/src/bin/cli/main.rs index 5dca315970..7f8688c54e 100644 --- a/sn_node_manager/src/bin/cli/main.rs +++ b/sn_node_manager/src/bin/cli/main.rs @@ -388,6 +388,9 @@ pub enum AuditorSubCmd { path: Option, #[command(flatten)] peers: PeersArgs, + /// Hex string of the Foundation SK. + #[clap(long, name = "sk")] + sk_str: String, /// Provide a auditor binary using a URL. /// /// The binary must be inside a zip or gzipped tar archive. @@ -838,6 +841,7 @@ async fn main() -> Result<()> { log_dir_path, path, peers, + sk_str, url, version, }) => { @@ -845,6 +849,7 @@ async fn main() -> Result<()> { env_variables, log_dir_path, peers, + sk_str, path, url, version, diff --git a/sn_node_manager/src/cmd/auditor.rs b/sn_node_manager/src/cmd/auditor.rs index 4a7f93c3e2..d7242591f1 100644 --- a/sn_node_manager/src/cmd/auditor.rs +++ b/sn_node_manager/src/cmd/auditor.rs @@ -25,10 +25,12 @@ use sn_service_management::{ }; use std::path::PathBuf; +#[allow(clippy::too_many_arguments)] pub async fn add( env_variables: Option>, log_dir_path: Option, peers: PeersArgs, + foundation_sk_string: String, src_path: Option, url: Option, version: Option, @@ -74,6 +76,7 @@ pub async fn add( AddAuditorServiceOptions { bootstrap_peers: get_peers_from_args(peers).await?, env_variables, + foundation_sk_string, auditor_src_bin_path, auditor_install_bin_path: PathBuf::from("/usr/local/bin/auditor"), service_log_dir_path,