Skip to content

Commit

Permalink
feat(node_manager): pass foundation sk to the auditor
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed May 21, 2024
1 parent 3f89f68 commit ac4a7de
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sn_auditor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct Opt {
beta_participants: Option<PathBuf>,

/// Hex string of the Foundation SK.
#[clap(name = "sk")]
#[clap(long, name = "sk")]
sk_str: String,
}

Expand Down
6 changes: 5 additions & 1 deletion sn_node_manager/src/add_services/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ pub struct AddNodeServiceOptions {

#[derive(Debug, PartialEq)]
pub struct InstallAuditorServiceCtxBuilder {
pub auditor_path: PathBuf,
pub bootstrap_peers: Vec<Multiaddr>,
pub env_variables: Option<Vec<(String, String)>>,
pub auditor_path: PathBuf,
pub foundation_sk_string: String,
pub log_dir_path: PathBuf,
pub name: String,
pub service_user: String,
Expand All @@ -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()?,
Expand Down Expand Up @@ -233,6 +236,7 @@ impl InstallFaucetServiceCtxBuilder {

pub struct AddAuditorServiceOptions {
pub bootstrap_peers: Vec<Multiaddr>,
pub foundation_sk_string: String,
pub env_variables: Option<Vec<(String, String)>>,
pub auditor_install_bin_path: PathBuf,
pub auditor_src_bin_path: PathBuf,
Expand Down
3 changes: 2 additions & 1 deletion sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions sn_node_manager/src/add_services/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,8 @@ async fn add_auditor_should_add_a_auditor_service() -> Result<()> {
args: vec![
OsString::from("--log-output-dest"),
OsString::from(auditor_logs_dir.to_path_buf().as_os_str()),
OsString::from("--sk-str"),
OsString::from("test"),
],
contents: None,
environment: Some(vec![("SN_LOG".to_string(), "all".to_string())]),
Expand All @@ -2385,6 +2387,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(),
Expand Down Expand Up @@ -2455,6 +2458,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(),
Expand Down
5 changes: 5 additions & 0 deletions sn_node_manager/src/bin/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ pub enum AuditorSubCmd {
path: Option<PathBuf>,
#[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.
Expand Down Expand Up @@ -838,13 +841,15 @@ async fn main() -> Result<()> {
log_dir_path,
path,
peers,
sk_str,
url,
version,
}) => {
cmd::auditor::add(
env_variables,
log_dir_path,
peers,
sk_str,
path,
url,
version,
Expand Down
3 changes: 3 additions & 0 deletions sn_node_manager/src/cmd/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ use sn_service_management::{
};
use std::path::PathBuf;

#[allow(clippy::too_many_arguments)]
pub async fn add(
env_variables: Option<Vec<(String, String)>>,
log_dir_path: Option<PathBuf>,
peers: PeersArgs,
foundation_sk_string: String,
src_path: Option<PathBuf>,
url: Option<String>,
version: Option<String>,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ac4a7de

Please sign in to comment.