ant_node_manager/cmd/
auditor.rs

1// Copyright (C) 2024 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
4// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
5// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
6// KIND, either express or implied. Please review the Licences for the specific language governing
7// permissions and limitations relating to use of the SAFE Network Software.
8
9use crate::{
10    config::{self, is_running_as_root},
11    print_banner, ServiceManager, VerbosityLevel,
12};
13use ant_bootstrap::InitialPeersConfig;
14use ant_service_management::{auditor::AuditorService, control::ServiceController, NodeRegistry};
15use color_eyre::{eyre::eyre, Result};
16use std::path::PathBuf;
17
18#[expect(clippy::too_many_arguments)]
19pub async fn add(
20    _beta_encryption_key: Option<String>,
21    _env_variables: Option<Vec<(String, String)>>,
22    _log_dir_path: Option<PathBuf>,
23    _peers_args: InitialPeersConfig,
24    _src_path: Option<PathBuf>,
25    _url: Option<String>,
26    _version: Option<String>,
27    _verbosity: VerbosityLevel,
28) -> Result<()> {
29    // TODO: The whole subcommand for the auditor should be removed when we have some time.
30    panic!("The auditor service is no longer supported");
31}
32
33pub async fn start(verbosity: VerbosityLevel) -> Result<()> {
34    if !is_running_as_root() {
35        return Err(eyre!("The start command must run as the root user"));
36    }
37    info!("Starting the auditor service");
38
39    let mut node_registry = NodeRegistry::load(&config::get_node_registry_path()?)?;
40    if let Some(auditor) = &mut node_registry.auditor {
41        if verbosity != VerbosityLevel::Minimal {
42            print_banner("Start Auditor Service");
43        }
44        info!("Starting the auditor service");
45
46        let service = AuditorService::new(auditor, Box::new(ServiceController {}));
47        let mut service_manager = ServiceManager::new(
48            service,
49            Box::new(ServiceController {}),
50            VerbosityLevel::Normal,
51        );
52        service_manager.start().await?;
53
54        node_registry.save()?;
55        return Ok(());
56    }
57    error!("The auditor service has not been added yet");
58    Err(eyre!("The auditor service has not been added yet"))
59}
60
61pub async fn stop(verbosity: VerbosityLevel) -> Result<()> {
62    if !is_running_as_root() {
63        return Err(eyre!("The stop command must run as the root user"));
64    }
65
66    let mut node_registry = NodeRegistry::load(&config::get_node_registry_path()?)?;
67    if let Some(auditor) = &mut node_registry.auditor {
68        if verbosity != VerbosityLevel::Minimal {
69            print_banner("Stop Auditor Service");
70        }
71        info!("Stopping the auditor service");
72
73        let service = AuditorService::new(auditor, Box::new(ServiceController {}));
74        let mut service_manager =
75            ServiceManager::new(service, Box::new(ServiceController {}), verbosity);
76        service_manager.stop().await?;
77
78        node_registry.save()?;
79
80        return Ok(());
81    }
82
83    error!("The auditor service has not been added yet");
84    Err(eyre!("The auditor service has not been added yet"))
85}
86
87pub async fn upgrade(
88    _do_not_start: bool,
89    _force: bool,
90    _provided_env_variables: Option<Vec<(String, String)>>,
91    _url: Option<String>,
92    _version: Option<String>,
93    _verbosity: VerbosityLevel,
94) -> Result<()> {
95    // TODO: The whole subcommand for the auditor should be removed when we have some time.
96    panic!("The auditor service is no longer supported");
97}