Skip to main content

signstar_configure/host/
all_backends.rs

1//! Functionality when support for all backends is compiled in.
2
3use log::info;
4
5use crate::{ConfigurationResult, Error, HostConfiguration};
6
7impl<'config> HostConfiguration<'config> {
8    /// Syncs the Signstar host with its configuration.
9    ///
10    /// # Errors
11    ///
12    /// Returns an error, if
13    ///
14    /// - the syncing of NetHSM backends fails
15    /// - the syncing of YubiHSM2 backends fails
16    pub fn sync(&self) -> Result<ConfigurationResult, Error> {
17        info!("Sync the Signstar host with its configuration.");
18
19        let nethsm_config_result = self.sync_nethsm()?;
20        let yubihsm_config_result = self.sync_yubihsm2()?;
21
22        if matches!(
23            nethsm_config_result,
24            ConfigurationResult::MissingConfigurationForBackend
25        ) && matches!(
26            yubihsm_config_result,
27            ConfigurationResult::MissingConfigurationForBackend
28        ) {
29            return Ok(ConfigurationResult::MissingConfigurationForBackend);
30        }
31
32        if !matches!(
33            nethsm_config_result,
34            ConfigurationResult::SyncSucceeded
35                | ConfigurationResult::MissingConfigurationForBackend
36        ) {
37            return Ok(nethsm_config_result);
38        }
39
40        if !matches!(
41            yubihsm_config_result,
42            ConfigurationResult::SyncSucceeded
43                | ConfigurationResult::MissingConfigurationForBackend
44        ) {
45            return Ok(yubihsm_config_result);
46        }
47
48        Ok(ConfigurationResult::SyncSucceeded)
49    }
50}